123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- {
- 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;
- procedure dirfn(afunc : TDirFnType;const s:string);
- var
- buffer : array[0..255] of char;
- begin
- move(s[1],buffer,length(s));
- buffer[length(s)]:=#0;
- AllowSlash(pchar(@buffer));
- if not aFunc(@buffer) then
- begin
- errno:=GetLastError;
- Errno2InoutRes;
- end;
- end;
- function CreateDirectoryTrunc(name:pointer):longbool;stdcall;
- begin
- CreateDirectoryTrunc:=CreateDirectory(name,nil);
- end;
- procedure mkdir(const s:string);[IOCHECK];
- begin
- If (s='') or (InOutRes <> 0) then
- exit;
- dirfn(TDirFnType(@CreateDirectoryTrunc),s);
- end;
- procedure rmdir(const s:string);[IOCHECK];
- begin
- if (s ='.') then
- InOutRes := 16;
- {$ifdef WINCE}
- if (s ='..') then
- InOutRes := 5;
- {$endif WINCE}
- If (s='') or (InOutRes <> 0) then
- exit;
- dirfn(TDirFnType(@RemoveDirectory),s);
- {$ifdef WINCE}
- if (Inoutres=3) and (Pos(DirectorySeparator, s)<2) then
- Inoutres:=2;
- {$endif WINCE}
- end;
- procedure chdir(const s:string);[IOCHECK];
- begin
- {$ifndef WINCE}
- If (s='') or (InOutRes <> 0) then
- exit;
- dirfn(TDirFnType(@SetCurrentDirectory),s);
- if Inoutres=2 then
- Inoutres:=3;
- {$else WINCE}
- InOutRes:=3;
- {$endif WINCE}
- end;
- procedure GetDir (DriveNr: byte; var Dir: ShortString);
- {$ifndef WINCE}
- const
- Drive:array[0..3]of char=(#0,':',#0,#0);
- var
- defaultdrive:boolean;
- DirBuf,SaveBuf:array[0..259] of Char;
- {$endif WINCE}
- begin
- {$ifndef WINCE}
- defaultdrive:=drivenr=0;
- if not defaultdrive then
- begin
- byte(Drive[0]):=Drivenr+64;
- GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
- if not SetCurrentDirectory(@Drive) then
- begin
- errno := word (GetLastError);
- Errno2InoutRes;
- Dir := char (DriveNr + 64) + ':\';
- SetCurrentDirectory(@SaveBuf);
- Exit;
- end;
- end;
- GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
- if not defaultdrive then
- SetCurrentDirectory(@SaveBuf);
- dir:=strpas(DirBuf);
- if not FileNameCaseSensitive then
- dir:=upcase(dir);
- {$else WINCE}
- Dir:='\';
- {$endif WINCE}
- end;
|