|
@@ -20,14 +20,6 @@ interface
|
|
|
{ include system-independent routine headers }
|
|
|
{$I systemh.inc}
|
|
|
|
|
|
-{Platform specific information}
|
|
|
-type
|
|
|
-{$ifdef CPU64}
|
|
|
- THandle = Int64;
|
|
|
-{$else CPU64}
|
|
|
- THandle = Longint;
|
|
|
-{$endif CPU64}
|
|
|
-
|
|
|
const
|
|
|
LineEnding = #13;
|
|
|
LFNSupport = true;
|
|
@@ -38,9 +30,6 @@ const
|
|
|
|
|
|
maxExitCode = 65535;
|
|
|
|
|
|
-{ include heap support headers }
|
|
|
-{$I heaph.inc}
|
|
|
-
|
|
|
const
|
|
|
{ Default filehandles }
|
|
|
UnusedHandle : Longint = -1;
|
|
@@ -187,171 +176,6 @@ Perhaps handle readonly filesystems, as in sysunix.inc
|
|
|
{$I system.inc}
|
|
|
|
|
|
|
|
|
-{*********************** MacOS API *********************}
|
|
|
-
|
|
|
-{This implementation uses StdCLib: }
|
|
|
-{$define MACOS_USE_STDCLIB}
|
|
|
-
|
|
|
-{Some MacOS API routines and StdCLib included for internal use:}
|
|
|
-{$I macostp.inc}
|
|
|
-
|
|
|
-{Note, because the System unit is the most low level, it should not
|
|
|
-depend on any other units, and thus the macos api must be accessed
|
|
|
-as an include file and not a unit.}
|
|
|
-
|
|
|
-{The reason StdCLib is used is that it can easily be connected
|
|
|
-to either SIOW or, in case of MPWTOOL, to MPW }
|
|
|
-
|
|
|
-{If the Apples Universal Interfaces are used, the qd variable is required
|
|
|
-to be allocated somewhere, so we do it here for the convenience to the user.}
|
|
|
-
|
|
|
-var
|
|
|
- qd: QDGlobals; cvar;
|
|
|
-
|
|
|
-
|
|
|
-{$ifdef MACOS_USE_STDCLIB}
|
|
|
-
|
|
|
-{************** API to StdCLib in MacOS ***************}
|
|
|
-{The reason StdCLib is used is that it can easily be connected
|
|
|
-to either SIOW or, in case of MPWTOOL, to MPW }
|
|
|
-
|
|
|
-{$endif}
|
|
|
-
|
|
|
-
|
|
|
-{*********************** Macutils *********************}
|
|
|
-
|
|
|
-{And also include the same utilities as in the macutils.pp unit.}
|
|
|
-
|
|
|
-var
|
|
|
- {emulated working directory}
|
|
|
- workingDirectorySpec: FSSpec; cvar;
|
|
|
- {Also declared in macutils.pp as external. Declared here to be available
|
|
|
- to macutils.inc and below in this file.}
|
|
|
-
|
|
|
-{$I macutils.inc}
|
|
|
-
|
|
|
-{******************************************************}
|
|
|
-
|
|
|
-function GetAppFileLocation (var spec: FSSpec): Boolean;
|
|
|
-{Requires >= System 7}
|
|
|
-
|
|
|
- var
|
|
|
- PSN: ProcessSerialNumber;
|
|
|
- info: ProcessInfoRec;
|
|
|
- appFileRefNum: Integer;
|
|
|
- appName: Str255;
|
|
|
- dummy: Mac_Handle;
|
|
|
-
|
|
|
-begin
|
|
|
- begin
|
|
|
- PSN.highLongOfPSN := 0;
|
|
|
- PSN.lowLongOfPSN := kCurrentProcess;
|
|
|
- info.processInfoLength := SizeOf(info);
|
|
|
- info.processName := nil;
|
|
|
- info.processAppSpec := @spec;
|
|
|
- if GetProcessInformation(PSN, info) = noErr then
|
|
|
- begin
|
|
|
- spec.name := '';
|
|
|
- GetAppFileLocation := true;
|
|
|
- end
|
|
|
- else
|
|
|
- GetAppFileLocation := false;
|
|
|
- end
|
|
|
-end;
|
|
|
-
|
|
|
-Procedure Errno2InOutRes;
|
|
|
-{
|
|
|
- Convert ErrNo error to the correct InOutRes value.
|
|
|
- It seems that some of the errno is, in macos,
|
|
|
- used for other purposes than its original definition.
|
|
|
-}
|
|
|
-
|
|
|
-begin
|
|
|
- if errno = 0 then { Else it will go through all the cases }
|
|
|
- exit;
|
|
|
- case Errno of
|
|
|
- Sys_ENFILE,
|
|
|
- Sys_EMFILE : Inoutres:=4;
|
|
|
- Sys_ENOENT : Inoutres:=2;
|
|
|
- Sys_EBADF : Inoutres:=6;
|
|
|
- Sys_ENOMEM,
|
|
|
- Sys_EFAULT : Inoutres:=217; //TODO Exchange to something better
|
|
|
- Sys_EINVAL : Inoutres:=218; //TODO RTE 218 doesn't exist
|
|
|
- Sys_EAGAIN,
|
|
|
- Sys_ENOSPC : Inoutres:=101;
|
|
|
- Sys_ENOTDIR : Inoutres:=3;
|
|
|
- Sys_EPERM,
|
|
|
- Sys_EROFS,
|
|
|
- Sys_EEXIST,
|
|
|
- Sys_EISDIR,
|
|
|
- Sys_EINTR, //Happens when attempt to rename a file fails
|
|
|
- Sys_EBUSY, //Happens when attempt to remove a locked file
|
|
|
- Sys_EACCES,
|
|
|
- Sys_EMLINK : Inoutres:=5; //Happens when attempt to remove open file
|
|
|
- Sys_ENXIO : InOutRes:=152;
|
|
|
- Sys_ESPIPE : InOutRes:=156; //Illegal seek
|
|
|
- else
|
|
|
- InOutRes := Integer(errno);//TODO Exchange to something better
|
|
|
- end;
|
|
|
- errno:=0;
|
|
|
-end;
|
|
|
-
|
|
|
-Procedure OSErr2InOutRes(err: OSErr);
|
|
|
-begin
|
|
|
- InOutRes:= MacOSErr2RTEerr(err);
|
|
|
-end;
|
|
|
-
|
|
|
-function FSpLocationFromFullPath(fullPathLength: Integer;
|
|
|
- fullPath: Mac_Ptr; var spec: FSSpec ):OSErr;
|
|
|
-
|
|
|
-var
|
|
|
- alias: AliasHandle;
|
|
|
- res: OSErr;
|
|
|
- wasChanged: Boolean;
|
|
|
- nullString: Str32;
|
|
|
-
|
|
|
-begin
|
|
|
- nullString:= '';
|
|
|
- res:= NewAliasMinimalFromFullPath(fullPathLength,
|
|
|
- fullPath, nullString, nullString, alias);
|
|
|
- if res = noErr then
|
|
|
- begin
|
|
|
- res:= ResolveAlias(nil, alias, spec, wasChanged);
|
|
|
- DisposeHandle(Mac_Handle(alias));
|
|
|
- end;
|
|
|
- FSpLocationFromFullPath:= res;
|
|
|
-end;
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- MacOS specific functions
|
|
|
-*****************************************************************************}
|
|
|
-var
|
|
|
- defaultCreator: OSType = $4D505320; {'MPS ' MPW Shell}
|
|
|
- //defaultCreator: OSType = $74747874; {'ttxt' Simple Text}
|
|
|
- defaultFileType: OSType = $54455854; {'TEXT'}
|
|
|
-
|
|
|
-procedure Yield;
|
|
|
-
|
|
|
-begin
|
|
|
- if StandAlone = 0 then
|
|
|
- SpinCursor(1);
|
|
|
-end;
|
|
|
-
|
|
|
-procedure SetDefaultMacOSFiletype(ftype: ShortString);
|
|
|
-
|
|
|
-begin
|
|
|
- if Length(ftype) = 4 then
|
|
|
- defaultFileType:= PLongWord(@ftype[1])^;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure SetDefaultMacOSCreator(creator: ShortString);
|
|
|
-
|
|
|
-begin
|
|
|
- if Length(creator) = 4 then
|
|
|
- defaultCreator:= PLongWord(@creator[1])^;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
{*****************************************************************************
|
|
|
ParamStr/Randomize
|
|
|
*****************************************************************************}
|
|
@@ -379,486 +203,6 @@ begin
|
|
|
end;
|
|
|
|
|
|
|
|
|
-{*****************************************************************************
|
|
|
- OS Memory allocation / deallocation
|
|
|
- ****************************************************************************}
|
|
|
-
|
|
|
-{ function to allocate size bytes more for the program }
|
|
|
-{ must return the first address of new data space or nil if failed }
|
|
|
-function SysOSAlloc(size: ptrint): pointer;
|
|
|
-begin
|
|
|
- result := NewPtr(size);
|
|
|
-end;
|
|
|
-
|
|
|
-{$define HAS_SYSOSFREE}
|
|
|
-
|
|
|
-procedure SysOSFree(p: pointer; size: ptrint);
|
|
|
-begin
|
|
|
- DisposePtr(p);
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
-{ include standard heap management }
|
|
|
-{$I heap.inc}
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- Low Level File Routines
|
|
|
- ****************************************************************************}
|
|
|
-
|
|
|
-function do_isdevice(handle:longint):boolean;
|
|
|
-begin
|
|
|
- do_isdevice:=false;
|
|
|
-end;
|
|
|
-
|
|
|
-{ close a file from the handle value }
|
|
|
-procedure do_close(h : longint);
|
|
|
-var
|
|
|
- err: OSErr;
|
|
|
-{No error handling, according to the other targets, which seems reasonable,
|
|
|
-because close might be used to clean up after an error.}
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- c_close(h);
|
|
|
- // Errno2InOutRes;
|
|
|
- {$else}
|
|
|
- err:= FSClose(h);
|
|
|
- // OSErr2InOutRes(err);
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-procedure do_erase(p : pchar);
|
|
|
-
|
|
|
-var
|
|
|
- spec: FSSpec;
|
|
|
- err: OSErr;
|
|
|
- res: Integer;
|
|
|
-
|
|
|
-begin
|
|
|
- res:= PathArgToFSSpec(p, spec);
|
|
|
- if (res = 0) then
|
|
|
- begin
|
|
|
- if not IsDirectory(spec) then
|
|
|
- begin
|
|
|
- err:= FSpDelete(spec);
|
|
|
- OSErr2InOutRes(err);
|
|
|
- end
|
|
|
- else
|
|
|
- InOutRes:= 2;
|
|
|
- end
|
|
|
- else
|
|
|
- InOutRes:=res;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure do_rename(p1,p2 : pchar);
|
|
|
-var
|
|
|
- s1,s2: AnsiString;
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- InOutRes:= PathArgToFullPath(p1, s1);
|
|
|
- if InOutRes <> 0 then
|
|
|
- exit;
|
|
|
- InOutRes:= PathArgToFullPath(p2, s2);
|
|
|
- if InOutRes <> 0 then
|
|
|
- exit;
|
|
|
- c_rename(PChar(s1),PChar(s2));
|
|
|
- Errno2InoutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-function do_write(h:longint;addr:pointer;len : longint) : longint;
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- do_write:= c_write(h, addr, len);
|
|
|
- Errno2InoutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- if FSWrite(h, len, Mac_Ptr(addr)) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- do_write:= len;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-function do_read(h:longint;addr:pointer;len : longint) : longint;
|
|
|
-
|
|
|
-var
|
|
|
- i: Longint;
|
|
|
-
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- len:= c_read(h, addr, len);
|
|
|
- Errno2InoutRes;
|
|
|
-
|
|
|
- do_read:= len;
|
|
|
-
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- if FSread(h, len, Mac_Ptr(addr)) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- do_read:= len;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-function do_filepos(handle : longint) : longint;
|
|
|
-
|
|
|
-var
|
|
|
- pos: Longint;
|
|
|
-
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- {This returns the filepos without moving it.}
|
|
|
- do_filepos := lseek(handle, 0, SEEK_CUR);
|
|
|
- Errno2InoutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- if GetFPos(handle, pos) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- do_filepos:= pos;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-procedure do_seek(handle,pos : longint);
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- lseek(handle, pos, SEEK_SET);
|
|
|
- Errno2InoutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- if SetFPos(handle, fsFromStart, pos) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-function do_seekend(handle:longint):longint;
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- do_seekend:= lseek(handle, 0, SEEK_END);
|
|
|
- Errno2InoutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- if SetFPos(handle, fsFromLEOF, 0) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- {TODO Resulting file position is to be returned.}
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-function do_filesize(handle : longint) : longint;
|
|
|
-
|
|
|
-var
|
|
|
- aktfilepos: Longint;
|
|
|
-
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- aktfilepos:= lseek(handle, 0, SEEK_CUR);
|
|
|
- if errno = 0 then
|
|
|
- begin
|
|
|
- do_filesize := lseek(handle, 0, SEEK_END);
|
|
|
- Errno2InOutRes; {Report the error from this operation.}
|
|
|
- lseek(handle, aktfilepos, SEEK_SET); {Always try to move back,
|
|
|
- even in presence of error.}
|
|
|
- end
|
|
|
- else
|
|
|
- Errno2InOutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- if GetEOF(handle, pos) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- do_filesize:= pos;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-{ truncate at a given position }
|
|
|
-procedure do_truncate (handle,pos:longint);
|
|
|
-begin
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
- ioctl(handle, FIOSETEOF, pointer(pos));
|
|
|
- Errno2InoutRes;
|
|
|
- {$else}
|
|
|
- InOutRes:=1;
|
|
|
- do_seek(handle,pos); //TODO: Is this needed (Does the user anticipate the filemarker is at the end?)
|
|
|
- if SetEOF(handle, pos) = noErr then
|
|
|
- InOutRes:=0;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-procedure do_open(var f;p:pchar;flags:longint);
|
|
|
-{
|
|
|
- filerec and textrec have both handle and mode as the first items so
|
|
|
- they could use the same routine for opening/creating.
|
|
|
- when (flags and $100) the file will be append
|
|
|
- when (flags and $1000) the file will be truncate/rewritten
|
|
|
- when (flags and $10000) there is no check for close (needed for textfiles)
|
|
|
-}
|
|
|
-
|
|
|
-var
|
|
|
- scriptTag: ScriptCode;
|
|
|
- refNum: Integer;
|
|
|
-
|
|
|
- err: OSErr;
|
|
|
- res: Integer;
|
|
|
- spec: FSSpec;
|
|
|
-
|
|
|
- fh: Longint;
|
|
|
-
|
|
|
- oflags : longint;
|
|
|
- fullPath: AnsiString;
|
|
|
-
|
|
|
- finderInfo: FInfo;
|
|
|
-
|
|
|
-begin
|
|
|
- // AllowSlash(p);
|
|
|
-
|
|
|
-{ close first if opened }
|
|
|
- if ((flags and $10000)=0) then
|
|
|
- begin
|
|
|
- case filerec(f).mode of
|
|
|
- fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
|
|
|
- fmclosed : ;
|
|
|
- else
|
|
|
- begin
|
|
|
- {not assigned}
|
|
|
- inoutres:=102;
|
|
|
- exit;
|
|
|
- end;
|
|
|
- end;
|
|
|
- end;
|
|
|
-
|
|
|
-{ reset file handle }
|
|
|
- filerec(f).handle:=UnusedHandle;
|
|
|
-
|
|
|
- {$ifdef MACOS_USE_STDCLIB}
|
|
|
-
|
|
|
-{ We do the conversion of filemodes here, concentrated on 1 place }
|
|
|
- case (flags and 3) of
|
|
|
- 0 : begin
|
|
|
- oflags :=O_RDONLY;
|
|
|
- filerec(f).mode:=fminput;
|
|
|
- end;
|
|
|
- 1 : begin
|
|
|
- oflags :=O_WRONLY;
|
|
|
- filerec(f).mode:=fmoutput;
|
|
|
- end;
|
|
|
- 2 : begin
|
|
|
- oflags :=O_RDWR;
|
|
|
- filerec(f).mode:=fminout;
|
|
|
- end;
|
|
|
- end;
|
|
|
-
|
|
|
- if (flags and $1000)=$1000 then
|
|
|
- oflags:=oflags or (O_CREAT or O_TRUNC)
|
|
|
- else if (flags and $100)=$100 then
|
|
|
- oflags:=oflags or (O_APPEND);
|
|
|
-
|
|
|
-{ empty name is special }
|
|
|
- if p[0]=#0 then
|
|
|
- begin
|
|
|
- case FileRec(f).mode of
|
|
|
- fminput :
|
|
|
- FileRec(f).Handle:=StdInputHandle;
|
|
|
- fminout, { this is set by rewrite }
|
|
|
- fmoutput :
|
|
|
- FileRec(f).Handle:=StdOutputHandle;
|
|
|
- fmappend :
|
|
|
- begin
|
|
|
- FileRec(f).Handle:=StdOutputHandle;
|
|
|
- FileRec(f).mode:=fmoutput; {fool fmappend}
|
|
|
- end;
|
|
|
- end;
|
|
|
- exit;
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- InOutRes:= PathArgToFSSpec(p, spec);
|
|
|
- if (InOutRes = 0) or (InOutRes = 2) then
|
|
|
- begin
|
|
|
- err:= FSpGetFullPath(spec, fullPath, false);
|
|
|
- InOutRes:= MacOSErr2RTEerr(err);
|
|
|
- end;
|
|
|
-
|
|
|
- if InOutRes <> 0 then
|
|
|
- exit;
|
|
|
-
|
|
|
- p:= PChar(fullPath);
|
|
|
- end;
|
|
|
-
|
|
|
-
|
|
|
- fh:= c_open(p, oflags);
|
|
|
- if (fh = -1) and (errno = Sys_EROFS) and ((oflags and O_RDWR)<>0) then
|
|
|
- begin
|
|
|
- oflags:=oflags and not(O_RDWR);
|
|
|
- fh:= c_open(p, oflags);
|
|
|
- end;
|
|
|
- Errno2InOutRes;
|
|
|
- if fh <> -1 then
|
|
|
- begin
|
|
|
- if FileRec(f).mode in [fmoutput, fminout, fmappend] then
|
|
|
- begin
|
|
|
- {Change of filetype and creator is always done when a file is opened
|
|
|
- for some kind of writing. This ensures overwritten Darwin files will
|
|
|
- get apropriate filetype. It must be done after file is opened,
|
|
|
- in the case the file did not previously exist.}
|
|
|
-
|
|
|
- FSpGetFInfo(spec, finderInfo);
|
|
|
- finderInfo.fdType:= defaultFileType;
|
|
|
- finderInfo.fdCreator:= defaultCreator;
|
|
|
- FSpSetFInfo(spec, finderInfo);
|
|
|
- end;
|
|
|
- filerec(f).handle:= fh;
|
|
|
- end
|
|
|
- else
|
|
|
- filerec(f).handle:= UnusedHandle;
|
|
|
-
|
|
|
- {$else}
|
|
|
-
|
|
|
- InOutRes:=1;
|
|
|
-
|
|
|
- { reset file handle }
|
|
|
- filerec(f).handle:=UnusedHandle;
|
|
|
-
|
|
|
- res:= FSpLocationFromFullPath(StrLen(p), p, spec);
|
|
|
- if (res = noErr) or (res = fnfErr) then
|
|
|
- begin
|
|
|
- if FSpCreate(spec, defaultCreator, defaultFileType, smSystemScript) = noErr then
|
|
|
- ;
|
|
|
-
|
|
|
- if FSpOpenDF(spec, fsCurPerm, refNum) = noErr then
|
|
|
- begin
|
|
|
- filerec(f).handle:= refNum;
|
|
|
- InOutRes:=0;
|
|
|
- end;
|
|
|
- end;
|
|
|
-
|
|
|
- if (filerec(f).handle=UnusedHandle) then
|
|
|
- begin
|
|
|
- //errno:=GetLastError;
|
|
|
- //Errno2InoutRes;
|
|
|
- end;
|
|
|
- {$endif}
|
|
|
-end;
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- UnTyped File Handling
|
|
|
-*****************************************************************************}
|
|
|
-
|
|
|
-{$i file.inc}
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- Typed File Handling
|
|
|
-*****************************************************************************}
|
|
|
-
|
|
|
-{$i typefile.inc}
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- Text File Handling
|
|
|
-*****************************************************************************}
|
|
|
-
|
|
|
-{ #26 is not end of a file in MacOS ! }
|
|
|
-
|
|
|
-{$i text.inc}
|
|
|
-
|
|
|
-{*****************************************************************************
|
|
|
- Directory Handling
|
|
|
-*****************************************************************************}
|
|
|
-
|
|
|
-procedure mkdir(const s:string);[IOCheck];
|
|
|
-var
|
|
|
- spec: FSSpec;
|
|
|
- createdDirID: Longint;
|
|
|
- err: OSErr;
|
|
|
- res: Integer;
|
|
|
-begin
|
|
|
- If (s='') or (InOutRes <> 0) then
|
|
|
- exit;
|
|
|
-
|
|
|
- res:= PathArgToFSSpec(s, spec);
|
|
|
- if (res = 0) or (res = 2) then
|
|
|
- begin
|
|
|
- err:= FSpDirCreate(spec, smSystemScript, createdDirID);
|
|
|
- OSErr2InOutRes(err);
|
|
|
- end
|
|
|
- else
|
|
|
- InOutRes:=res;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure rmdir(const s:string);[IOCheck];
|
|
|
-
|
|
|
-var
|
|
|
- spec: FSSpec;
|
|
|
- err: OSErr;
|
|
|
- res: Integer;
|
|
|
-
|
|
|
-begin
|
|
|
- If (s='') or (InOutRes <> 0) then
|
|
|
- exit;
|
|
|
-
|
|
|
- res:= PathArgToFSSpec(s, spec);
|
|
|
-
|
|
|
- if (res = 0) then
|
|
|
- begin
|
|
|
- if IsDirectory(spec) then
|
|
|
- begin
|
|
|
- err:= FSpDelete(spec);
|
|
|
- OSErr2InOutRes(err);
|
|
|
- end
|
|
|
- else
|
|
|
- InOutRes:= 20;
|
|
|
- end
|
|
|
- else
|
|
|
- InOutRes:=res;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure chdir(const s:string);[IOCheck];
|
|
|
-var
|
|
|
- spec, newDirSpec: FSSpec;
|
|
|
- err: OSErr;
|
|
|
- res: Integer;
|
|
|
-begin
|
|
|
- if (s='') or (InOutRes <> 0) then
|
|
|
- exit;
|
|
|
-
|
|
|
- res:= PathArgToFSSpec(s, spec);
|
|
|
- if (res = 0) or (res = 2) then
|
|
|
- begin
|
|
|
- { The fictive file x is appended to the directory name to make
|
|
|
- FSMakeFSSpec return a FSSpec to a file in the directory.
|
|
|
- Then by clearing the name, the FSSpec then
|
|
|
- points to the directory. It doesn't matter whether x exists or not.}
|
|
|
- err:= FSMakeFSSpec (spec.vRefNum, spec.parID, ':'+spec.name+':x', newDirSpec);
|
|
|
- if (err = noErr) or (err = fnfErr) then
|
|
|
- begin
|
|
|
- workingDirectorySpec:= newDirSpec;
|
|
|
- workingDirectorySpec.name:='';
|
|
|
- InOutRes:= 0;
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- {E g if the directory doesn't exist.}
|
|
|
- OSErr2InOutRes(err);
|
|
|
- end;
|
|
|
- end
|
|
|
- else
|
|
|
- InOutRes:=res;
|
|
|
-end;
|
|
|
-
|
|
|
-procedure getDir (DriveNr: byte; var Dir: ShortString);
|
|
|
-
|
|
|
-var
|
|
|
- fullPath: AnsiString;
|
|
|
- pathHandleSize: Longint;
|
|
|
-
|
|
|
-begin
|
|
|
- if FSpGetFullPath(workingDirectorySpec, fullPath, false) <> noErr then
|
|
|
- Halt(3); {exit code 3 according to MPW}
|
|
|
-
|
|
|
- if Length(fullPath) <= 255 then {because dir is ShortString}
|
|
|
- InOutRes := 0
|
|
|
- else
|
|
|
- InOutRes := 1; //TODO Exchange to something better
|
|
|
-
|
|
|
- dir:= fullPath;
|
|
|
-end;
|
|
|
-
|
|
|
{*****************************************************************************
|
|
|
SystemUnit Initialization
|
|
|
*****************************************************************************}
|
|
@@ -1191,9 +535,7 @@ begin
|
|
|
{ Reset IO Error }
|
|
|
InOutRes:=0;
|
|
|
errno:=0;
|
|
|
-(* This should be changed to a real value during *)
|
|
|
-(* thread driver initialization if appropriate. *)
|
|
|
- ThreadID := 1;
|
|
|
+ InitSystemThreads;
|
|
|
{$ifdef HASVARIANT}
|
|
|
initvariantmanager;
|
|
|
{$endif HASVARIANT}
|
|
@@ -1212,7 +554,10 @@ end.
|
|
|
|
|
|
{
|
|
|
$Log$
|
|
|
- Revision 1.28 2005-02-01 20:22:49 florian
|
|
|
+ Revision 1.29 2005-02-07 21:30:12 peter
|
|
|
+ * system unit updated
|
|
|
+
|
|
|
+ Revision 1.28 2005/02/01 20:22:49 florian
|
|
|
* improved widestring infrastructure manager
|
|
|
|
|
|
Revision 1.27 2005/01/24 18:51:23 olle
|