mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 11:39:24 +02:00

* renamed platform-specific pchar versions of those rouines to do_*() and changed them to either rawbytestring or unicodestring depending on the FPCRTL_FILESYSTEM_SINGLE_BYTE_API/FPCRTL_FILESYSTEM_TWO_BYTE_API setting * implemented generic shortstring versions of those routines on top of either rawbytestring or unicodestring depending on the API-kind (in case of the embedded target, if ansistring are not supported they will map directly to shortstring routines instead) * all platform-specific *dir() routines with rawbytestring parameters now receive their parameters in DefaultFileSystemCodePage - removed no longer required ansistring variants from the objpas unit - removed no longer required FPC_SYS_MKDIR etc aliases * factored out empty string and inoutres<>0 checks from platform-specific *dir() routines to generic ones o platform-specific notes: o amiga/morphos: check new pathconv(rawbytestring) function o macos TODO: convert PathArgToFSSpec (and the routines it calls) to rawbytestring o nativent: added SysUnicodeStringToNtStr() function o wii: convert dirio callbacks to use rawbytestring to avoid conversion + test for unicode mk/ch/rm/getdir() git-svn-id: branches/cpstrrtl@25048 -
116 lines
2.9 KiB
PHP
116 lines
2.9 KiB
PHP
{
|
|
This file is part of the Free Pascal run time library.
|
|
Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
|
|
member of the Free Pascal development team.
|
|
|
|
FPC Pascal system unit for the Win32 API.
|
|
|
|
See the file COPYING.FPC, included in this distribution,
|
|
for details about the copyright.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
**********************************************************************}
|
|
|
|
{*****************************************************************************
|
|
Directory Handling
|
|
*****************************************************************************}
|
|
type
|
|
TDirFnType=function(name:pointer):longbool;stdcall;
|
|
|
|
function CreateDirectoryTrunc(name:pointer):longbool;stdcall;
|
|
begin
|
|
CreateDirectoryTrunc:=CreateDirectoryW(name,nil);
|
|
end;
|
|
|
|
procedure dirfn(afunc : TDirFnType;s:unicodestring);
|
|
begin
|
|
DoDirSeparators(s);
|
|
if not aFunc(punicodechar(s)) then
|
|
begin
|
|
errno:=GetLastError;
|
|
Errno2InoutRes;
|
|
end;
|
|
end;
|
|
Procedure do_MkDir(const s: UnicodeString);
|
|
begin
|
|
dirfn(TDirFnType(@CreateDirectoryTrunc),s);
|
|
end;
|
|
|
|
Procedure do_RmDir(const s: UnicodeString);
|
|
begin
|
|
if (s ='.') then
|
|
begin
|
|
InOutRes := 16;
|
|
exit;
|
|
end;
|
|
{$ifdef WINCE}
|
|
if (s='..') then
|
|
begin
|
|
InOutRes := 5;
|
|
exit;
|
|
end;
|
|
{$endif WINCE}
|
|
dirfn(TDirFnType(@RemoveDirectoryW),s);
|
|
{$ifdef WINCE}
|
|
if (Inoutres=3) and (Pos(DirectorySeparator, s)<2) then
|
|
Inoutres:=2;
|
|
{$endif WINCE}
|
|
end;
|
|
|
|
Procedure do_ChDir(const s: UnicodeString);
|
|
begin
|
|
{$ifndef WINCE}
|
|
dirfn(TDirFnType(@SetCurrentDirectoryW),s);
|
|
if Inoutres=2 then
|
|
Inoutres:=3;
|
|
{$else WINCE}
|
|
InOutRes:=3;
|
|
{$endif WINCE}
|
|
end;
|
|
|
|
procedure do_GetDir (DriveNr: byte; var Dir: Unicodestring);
|
|
{$ifndef WINCE}
|
|
var
|
|
Drive:array[0..3]of char;
|
|
defaultdrive:boolean;
|
|
savebuf: UnicodeString;
|
|
len : integer;
|
|
{$endif WINCE}
|
|
begin
|
|
{$ifndef WINCE}
|
|
defaultdrive:=drivenr=0;
|
|
if not defaultdrive then
|
|
begin
|
|
Drive[0]:=widechar(Drivenr+64);
|
|
Drive[1]:=':';
|
|
Drive[2]:=#0;
|
|
Drive[3]:=#0;
|
|
len:=GetCurrentDirectoryW(0,nil); // in TChar
|
|
setlength(savebuf,len-1); // -1 because len is #0 inclusive
|
|
|
|
GetCurrentDirectoryW(len,punicodechar(SaveBuf)); // in TChar
|
|
if not SetCurrentDirectoryW(@Drive) then
|
|
begin
|
|
errno := word (GetLastError);
|
|
Errno2InoutRes;
|
|
Dir := widechar (DriveNr + 64) + ':\';
|
|
SetCurrentDirectoryW(@SaveBuf);
|
|
Exit;
|
|
end;
|
|
end;
|
|
|
|
len:=GetCurrentDirectoryW(0,nil);
|
|
setlength(dir,len-1); // -1 because len is #0 inclusive
|
|
GetCurrentDirectoryW(len,punicodechar(dir));
|
|
if not defaultdrive then
|
|
SetCurrentDirectoryW(@SaveBuf);
|
|
if not FileNameCasePreserving then
|
|
dir:=upcase(dir);
|
|
{$else WINCE}
|
|
Dir:='\';
|
|
{$endif WINCE}
|
|
end;
|