fpc/rtl/os2/sysdir.inc
Jonas Maebe d66d15aad3 + added mkdir/chdir/rmdir(rawbytestring) and (unicodestring) to the system unit
* 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 -
2013-07-04 22:28:37 +00:00

140 lines
3.6 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
*****************************************************************************}
Procedure do_MkDir(s: rawbytestring);
var
Rc : word;
begin
DoDirSeparators(s);
Rc := DosCreateDir(pchar(s),nil);
if Rc <> 0 then
begin
InOutRes := Rc;
Errno2Inoutres;
end;
end;
Procedure do_RmDir(s: rawbytestring);
var
Rc : word;
begin
if s = '.' then
begin
InOutRes := 16;
exit;
end;
DoDirSeparators(s);
Rc := DosDeleteDir(pchar(s));
if Rc <> 0 then
begin
InOutRes := Rc;
Errno2Inoutres;
end;
end;
{$ASMMODE INTEL}
Procedure do_ChDir(s: rawbytestring);
var RC: cardinal;
Len: Longint;
begin
Len := Length (s);
if (Len >= 2) and (S[2] = ':') then
begin
RC := DosSetDefaultDisk ((Ord (S [1]) and not ($20)) - $40);
if RC <> 0 then
InOutRes := RC
else
if Len > 2 then
begin
DoDirSeparators (s);
RC := DosSetCurrentDir (pchar (s));
if RC <> 0 then
begin
InOutRes := RC;
Errno2InOutRes;
end;
end;
end else begin
DoDirSeparators (s);
RC := DosSetCurrentDir (pchar (s));
if RC <> 0 then
begin
InOutRes:= RC;
Errno2InOutRes;
end;
end;
end;
{$ASMMODE ATT}
procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
{Written by Michael Van Canneyt.}
var sof: Pchar;
i:byte;
l,l2:cardinal;
begin
setlength(Dir,255);
Dir [4] := #0;
{ Used in case the specified drive isn't available }
sof:=pchar(@dir[4]);
{ dir[1..3] will contain '[drivenr]:\', but is not }
{ supplied by DOS, so we let dos string start at }
{ dir[4] }
{ Get dir from drivenr : 0=default, 1=A etc... }
{ TODO: if max path length is > 255, increase the setlength parameter above and
the 255 below }
l:=255-3;
InOutRes:=longint (DosQueryCurrentDir(DriveNr, sof^, l));
{$WARNING Result code should be translated in some cases!}
{ Now Dir should be filled with directory in ASCIIZ, }
{ starting from dir[4] }
dir[2]:=':';
dir[3]:='\';
i:=4;
{Conversion to Pascal string }
while (dir[i]<>#0) do
begin
{ convert path name to DOS }
if dir[i] in AllowDirectorySeparators then
dir[i]:=DirectorySeparator;
inc(i);
end;
setlength(dir,i-1);
{ upcase the string (FPC function) }
if drivenr<>0 then { Drive was supplied. We know it }
dir[1]:=chr(64+drivenr)
else
begin
{ We need to get the current drive from DOS function 19H }
{ because the drive was the default, which can be unknown }
DosQueryCurrentDisk(l, l2);
dir[1]:=chr(64+l);
end;
SetCodePage(dir,DefaultFileSystemCodePage,false);
if not (FileNameCasePreserving) then dir:=upcase(dir);
end;