sysutils.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. Sysutils unit for netware
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit sysutils;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$MODE objfpc}
  17. {$MODESWITCH OUT}
  18. {$IFDEF UNICODERTL}
  19. {$MODESWITCH UNICODESTRINGS}
  20. {$ELSE}
  21. {$H+}
  22. {$ENDIF}
  23. {$modeswitch typehelpers}
  24. {$modeswitch advancedrecords}
  25. {$IFDEF FPC_DOTTEDUNITS}
  26. uses TP.DOS;
  27. {$ELSE FPC_DOTTEDUNITS}
  28. uses DOS;
  29. {$ENDIF FPC_DOTTEDUNITS}
  30. {$I nwsys.inc}
  31. {$I errno.inc}
  32. {$DEFINE HAS_SLEEP}
  33. {$DEFINE HAS_OSERROR}
  34. { used OS file system APIs use ansistring }
  35. {$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  36. { OS has an ansistring/single byte environment variable API }
  37. {$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL}
  38. {$DEFINE executeprocuni} (* Only 1 byte version of ExecuteProcess is provided by the OS *)
  39. TYPE
  40. TNetwareFindData =
  41. RECORD
  42. DirP : PNWDirEnt; { used for opendir }
  43. EntryP: PNWDirEnt; { and readdir }
  44. Magic : WORD; { to avoid abends with uninitialized TSearchRec }
  45. END;
  46. { Include platform independent interface part }
  47. {$i sysutilh.inc}
  48. { additional NetWare file flags}
  49. CONST
  50. faSHARE = $00000080; { Sharable file }
  51. faNO_SUBALLOC = $00000800; { Don't sub alloc. this file }
  52. faTRANS = $00001000; { Transactional file (TTS usable) }
  53. faREADAUD = $00004000; { Read audit }
  54. faWRITAUD = $00008000; { Write audit }
  55. faIMMPURG = $00010000; { Immediate purge }
  56. faNORENAM = $00020000; { Rename inhibit }
  57. faNODELET = $00040000; { Delete inhibit }
  58. faNOCOPY = $00080000; { Copy inhibit }
  59. faFILE_MIGRATED = $00400000; { File has been migrated }
  60. faDONT_MIGRATE = $00800000; { Don't migrate this file }
  61. faIMMEDIATE_COMPRESS = $02000000; { Compress this file immediately }
  62. faFILE_COMPRESSED = $04000000; { File is compressed }
  63. faDONT_COMPRESS = $08000000; { Don't compress this file }
  64. faCANT_COMPRESS = $20000000; { Can't compress this file }
  65. faATTR_ARCHIVE = $40000000; { Entry has had an EA modified, }
  66. { an ownerID changed, or trustee }
  67. { info changed, etc. }
  68. implementation
  69. {$IFDEF FPC_DOTTEDUNITS}
  70. uses
  71. System.SysConst;
  72. {$ELSE FPC_DOTTEDUNITS}
  73. uses
  74. sysconst;
  75. {$ENDIF FPC_DOTTEDUNITS}
  76. {$define FPC_FEXPAND_DRIVES}
  77. {$define FPC_FEXPAND_VOLUMES}
  78. {$define FPC_FEXPAND_NO_DEFAULT_PATHS}
  79. { Include platform independent implementation part }
  80. {$i sysutils.inc}
  81. {****************************************************************************
  82. File Functions
  83. ****************************************************************************}
  84. Function FileOpen (Const FileName : rawbytestring; Mode : Integer) : THandle;
  85. VAR NWOpenFlags : longint;
  86. SystemFileName: RawByteString;
  87. begin
  88. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  89. NWOpenFlags:=0;
  90. Case (Mode and 3) of
  91. 0 : NWOpenFlags:=NWOpenFlags or O_RDONLY;
  92. 1 : NWOpenFlags:=NWOpenFlags or O_WRONLY;
  93. 2 : NWOpenFlags:=NWOpenFlags or O_RDWR;
  94. end;
  95. FileOpen := _open (PAnsiChar(SystemFileName),NWOpenFlags,0);
  96. //!! We need to set locking based on Mode !!
  97. end;
  98. Function FileCreate (Const FileName : RawByteString) : THandle;
  99. VAR SystemFileName: RawByteString;
  100. begin
  101. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  102. FileCreate:=_open(PAnsiChar(SystemFileName),O_RdWr or O_Creat or O_Trunc,0);
  103. end;
  104. Function FileCreate (Const FileName : RawByteString; Rights:longint) : THandle;
  105. begin
  106. FileCreate:=FileCreate (FileName);
  107. end;
  108. Function FileCreate (Const FileName : RawByteString; ShareMode: Longint; Rights:longint) : THandle;
  109. begin
  110. FileCreate:=FileCreate (FileName);
  111. end;
  112. Function FileRead (Handle : THandle; Out Buffer; Count : longint) : longint;
  113. begin
  114. FileRead:=_read (Handle,@Buffer,Count);
  115. end;
  116. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : longint;
  117. begin
  118. FileWrite:=_write (Handle,@Buffer,Count);
  119. end;
  120. Function FileSeek (Handle : THandle; FOffset,Origin : Longint) : Longint;
  121. begin
  122. FileSeek:=_lseek (Handle,FOffset,Origin);
  123. end;
  124. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
  125. begin
  126. {$warning need to add 64bit FileSeek }
  127. FileSeek:=FileSeek(Handle,Longint(FOffset),Longint(Origin));
  128. end;
  129. Procedure FileClose (Handle : THandle);
  130. begin
  131. _close(Handle);
  132. end;
  133. Function FileTruncate (Handle : THandle; Size: Int64) : boolean;
  134. begin
  135. if Size > high (longint) then
  136. FileTruncate := false
  137. {$WARNING Possible support for 64-bit FS to be checked!}
  138. else
  139. FileTruncate:=(_chsize(Handle,Size) = 0);
  140. end;
  141. Function FileAge (Const FileName : RawByteString): Int64;
  142. var Handle: longint;
  143. begin
  144. Handle := FileOpen(FileName, 0);
  145. if Handle <> -1 then
  146. begin
  147. result := FileGetDate(Handle);
  148. FileClose(Handle);
  149. end
  150. else
  151. result := -1;
  152. end;
  153. Function FileLock (Handle,FOffset,FLen : Longint) : Longint;
  154. begin
  155. FileLock := _lock (Handle,FOffset,FLen);
  156. end;
  157. Function FileLock (Handle : Longint; FOffset,FLen : Int64) : Longint;
  158. begin
  159. {$warning need to add 64bit FileLock call }
  160. FileLock := FileLock (Handle, longint(FOffset),longint(FLen));
  161. end;
  162. Function FileUnlock (Handle,FOffset,FLen : Longint) : Longint;
  163. begin
  164. FileUnlock := _unlock (Handle,FOffset,FLen);
  165. end;
  166. Function FileUnlock (Handle : Longint; FOffset,FLen : Int64) : Longint;
  167. begin
  168. {$warning need to add 64bit FileUnlock call }
  169. FileUnlock := FileUnlock (Handle, longint(FOffset),longint(FLen));
  170. end;
  171. Function FileAge (Const FileName : String): Int64;
  172. VAR Info : NWStatBufT;
  173. PTM : PNWTM;
  174. begin
  175. If _stat (PAnsiChar(FileName),Info) <> 0 then
  176. exit(-1)
  177. else
  178. begin
  179. PTM := _localtime (Info.st_mtime);
  180. IF PTM = NIL THEN
  181. exit(-1)
  182. else
  183. WITH PTM^ DO
  184. Result:=DateTimeToFileDate(EncodeDate(tm_year+1900,tm_mon+1,tm_mday)+EncodeTime(tm_hour,tm_min,tm_sec,0));
  185. end;
  186. end;
  187. function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
  188. begin
  189. Result := False;
  190. end;
  191. Function FileExists (Const FileName : RawByteString; FollowLink : Boolean) : Boolean;
  192. VAR Info : NWStatBufT;
  193. SystemFileName: RawByteString;
  194. begin
  195. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  196. FileExists:=(_stat(PAnsiChar(SystemFileName),Info) = 0);
  197. end;
  198. Function DirectoryExists (Const Directory : RawByteString; FollowLink : Boolean) : Boolean;
  199. Var
  200. Dir : RawByteString;
  201. drive : byte;
  202. FADir, StoredIORes : longint;
  203. begin
  204. Dir:=Directory;
  205. if (length(dir)=2) and (dir[2]=':') and
  206. ((dir[1] in ['A'..'Z']) or (dir[1] in ['a'..'z'])) then
  207. begin
  208. { We want to test GetCurDir }
  209. if dir[1] in ['A'..'Z'] then
  210. drive:=ord(dir[1])-ord('A')+1
  211. else
  212. drive:=ord(dir[1])-ord('a')+1;
  213. {$push}
  214. {$I-}
  215. StoredIORes:=InOutRes;
  216. InOutRes:=0;
  217. GetDir(drive,dir);
  218. if InOutRes <> 0 then
  219. begin
  220. InOutRes:=StoredIORes;
  221. result:=false;
  222. exit;
  223. end;
  224. end;
  225. {$pop}
  226. if (Length (Dir) > 1) and
  227. (Dir [Length (Dir)] in AllowDirectorySeparators) and
  228. (* Do not remove '\' after ':' (root directory of a drive)
  229. or in '\\' (invalid path, possibly broken UNC path). *)
  230. not (Dir [Length (Dir) - 1] in (AllowDriveSeparators + AllowDirectorySeparators)) then
  231. dir:=copy(dir,1,length(dir)-1);
  232. (* FileGetAttr returns -1 on error *)
  233. FADir := FileGetAttr (Dir);
  234. Result := (FADir <> -1) and
  235. ((FADir and faDirectory) = faDirectory);
  236. end;
  237. PROCEDURE find_setfields (VAR f : TAbstractSearchRec; VAR Name : RawByteString);
  238. VAR T : Dos.DateTime;
  239. BEGIN
  240. WITH F DO
  241. BEGIN
  242. IF FindData.Magic = $AD01 THEN
  243. BEGIN
  244. {attr := FindData.EntryP^.d_attr AND $FF;} // lowest 8 bit -> same as dos
  245. attr := FindData.EntryP^.d_attr; { return complete netware attributes }
  246. UnpackTime(FindData.EntryP^.d_time + (LONGINT (FindData.EntryP^.d_date) SHL 16), T);
  247. time := DateTimeToFileDate(EncodeDate(T.Year,T.Month,T.day)+EncodeTime(T.Hour,T.Min,T.Sec,0));
  248. size := FindData.EntryP^.d_size;
  249. name := FindData.EntryP^.d_nameDOS;
  250. SetCodePage(name, DefaultFileSystemCodePage, false);
  251. END ELSE
  252. BEGIN
  253. name := '';
  254. END;
  255. END;
  256. END;
  257. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
  258. var
  259. SystemEncodedPath: RawByteString;
  260. begin
  261. IF path = '' then
  262. exit (18);
  263. SystemEncodedPath := ToSingleByteFileSystemEncodedFileName(Path);
  264. Rslt.FindData.DirP := _opendir (PAnsiChar(SystemEncodedPath));
  265. IF Rslt.FindData.DirP = NIL THEN
  266. exit (18);
  267. IF attr <> faAnyFile THEN
  268. _SetReaddirAttribute (Rslt.FindData.DirP, attr);
  269. Rslt.FindData.Magic := $AD01;
  270. Rslt.FindData.EntryP := _readdir (Rslt.FindData.DirP);
  271. if Rslt.FindData.EntryP = nil then
  272. begin
  273. _closedir (Rslt.FindData.DirP);
  274. Rslt.FindData.DirP := NIL;
  275. result := 18;
  276. end else
  277. begin
  278. find_setfields (Rslt,Name);
  279. result := 0;
  280. end;
  281. end;
  282. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
  283. begin
  284. IF Rslt.FindData.Magic <> $AD01 THEN
  285. exit (18);
  286. Rslt.FindData.EntryP := _readdir (Rslt.FindData.DirP);
  287. IF Rslt.FindData.EntryP = NIL THEN
  288. exit (18);
  289. find_setfields (Rslt,Name);
  290. result := 0;
  291. end;
  292. Procedure InternalFindClose (var Handle: THandle; var FindData: TFindData);
  293. begin
  294. IF FindData.Magic = $AD01 THEN
  295. BEGIN
  296. IF FindData.DirP <> NIL THEN
  297. _closedir (FindData.DirP);
  298. FindData.Magic := 0;
  299. FindData.DirP := NIL;
  300. FindData.EntryP := NIL;
  301. END;
  302. end;
  303. Function FileGetDate (Handle : THandle) : Int64;
  304. Var Info : NWStatBufT;
  305. PTM : PNWTM;
  306. begin
  307. If _fstat(Handle,Info) <> 0 then
  308. Result:=-1
  309. else
  310. begin
  311. PTM := _localtime (Info.st_mtime);
  312. IF PTM = NIL THEN
  313. exit(-1)
  314. else
  315. WITH PTM^ DO
  316. Result:=DateTimeToFileDate(EncodeDate(tm_year+1900,tm_mon+1,tm_mday)+EncodeTime(tm_hour,tm_min,tm_sec,0));
  317. end;
  318. end;
  319. Function FileSetDate (Handle : THandle; Age : Int64) : Longint;
  320. begin
  321. { i think its impossible under netware from FileHandle. I dident found a way to get the
  322. complete pathname of a filehandle, that would be needed for ChangeDirectoryEntry }
  323. FileSetDate:=-1;
  324. ConsolePrintf ('warning: fpc sysutils.FileSetDate not implemented'#13#10,0);
  325. {$warning FileSetDate not implemented (i think is impossible) }
  326. end;
  327. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  328. Var Info : NWStatBufT;
  329. SystemFileName: RawByteString;
  330. begin
  331. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  332. If _stat (PAnsiChar(SystemFileName),Info) <> 0 then
  333. Result:=-1
  334. Else
  335. Result := Info.st_attr AND $FFFF;
  336. end;
  337. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  338. VAR MS : NWModifyStructure;
  339. SystemFileName: RawByteString;
  340. begin
  341. { The Attr parameter is not used! }
  342. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  343. FillChar (MS, SIZEOF (MS), 0);
  344. if _ChangeDirectoryEntry (PAnsiChar (SystemFilename), MS, MFileAtrributesBit, 0) <> 0 then
  345. result := -1
  346. else
  347. result := 0;
  348. end;
  349. Function DeleteFile (Const FileName : RawByteString) : Boolean;
  350. var
  351. SystemFileName: RawByteString;
  352. begin
  353. SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
  354. Result:= (_UnLink (PAnsiChar(SystemFileName)) = 0);
  355. end;
  356. Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
  357. var
  358. OldSystemFileName, NewSystemFileName: RawByteString;
  359. begin
  360. OldSystemFileName:=ToSingleByteFileSystemEncodedFileName(OldName);
  361. NewSystemFileName:=ToSingleByteFileSystemEncodedFileName(NewName);
  362. RenameFile:=(_rename(PAnsiChar(OldSystemFileName),PAnsiChar(NewSystemFileName)) = 0);
  363. end;
  364. {****************************************************************************
  365. Disk Functions
  366. ****************************************************************************}
  367. {
  368. The Diskfree and Disksize functions need a file on the specified drive, since this
  369. is required for the statfs system call.
  370. These filenames are set in drivestr[0..26], and have been preset to :
  371. 0 - '.' (default drive - hence current dir is ok.)
  372. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  373. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  374. 3 - '/' (C: equivalent of dos is the root partition)
  375. 4..26 (can be set by you're own applications)
  376. ! Use AddDisk() to Add new drives !
  377. They both return -1 when a failure occurs.
  378. }
  379. Const
  380. FixDriveStr : array[0..3] of PAnsiChar=(
  381. '.',
  382. 'a:.',
  383. 'b:.',
  384. 'sys:/'
  385. );
  386. var
  387. Drives : byte;
  388. DriveStr : array[4..26] of PAnsiChar;
  389. Procedure AddDisk(const path:string);
  390. begin
  391. if not (DriveStr[Drives]=nil) then
  392. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  393. GetMem(DriveStr[Drives],length(Path)+1);
  394. StrPCopy(DriveStr[Drives],path);
  395. inc(Drives);
  396. if Drives>26 then
  397. Drives:=4;
  398. end;
  399. Function DiskFree(Drive: Byte): int64;
  400. //var fs : statfs;
  401. Begin
  402. { if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  403. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  404. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  405. else
  406. Diskfree:=-1;}
  407. DiskFree := -1;
  408. ConsolePrintf ('warning: fpc sysutils.diskfree not implemented'#13#10,0);
  409. {$warning DiskFree not implemented (does it make sense ?) }
  410. End;
  411. Function DiskSize(Drive: Byte): int64;
  412. //var fs : statfs;
  413. Begin
  414. { if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  415. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  416. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  417. else
  418. DiskSize:=-1;}
  419. DiskSize := -1;
  420. ConsolePrintf ('warning: fpc sysutils.disksize not implemented'#13#10,0);
  421. {$warning DiskSize not implemented (does it make sense ?) }
  422. End;
  423. function DirectoryExists (const Directory: string; FollowLink : Boolean): boolean;
  424. var
  425. Info : NWStatBufT;
  426. SystemFileName: RawByteString;
  427. begin
  428. SystemFileName:=ToSingleByteFileSystemEncodedFileName(Directory);
  429. If _stat (PAnsiChar(SystemFileName),Info) <> 0 then
  430. exit(false)
  431. else
  432. Exit ((Info.st_attr and faDirectory) <> 0);
  433. end;
  434. {****************************************************************************
  435. Misc Functions
  436. ****************************************************************************}
  437. procedure SysBeep;
  438. begin
  439. _RingTheBell;
  440. end;
  441. {****************************************************************************
  442. Locale Functions
  443. ****************************************************************************}
  444. Procedure GetLocalTime(var SystemTime: TSystemTime);
  445. var xx : word;
  446. begin
  447. Dos.GetTime(SystemTime.Hour, SystemTime.Minute, SystemTime.Second, xx);
  448. Dos.GetDate(SystemTime.Year, SystemTime.Month, SystemTime.Day, xx);
  449. SystemTime.MilliSecond := 0;
  450. end;
  451. Procedure InitAnsi;
  452. Var i : longint;
  453. begin
  454. { Fill table entries 0 to 127 }
  455. for i := 0 to 96 do
  456. UpperCaseTable[i] := chr(i);
  457. for i := 97 to 122 do
  458. UpperCaseTable[i] := chr(i - 32);
  459. for i := 123 to 191 do
  460. UpperCaseTable[i] := chr(i);
  461. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  462. for i := 0 to 64 do
  463. LowerCaseTable[i] := chr(i);
  464. for i := 65 to 90 do
  465. LowerCaseTable[i] := chr(i + 32);
  466. for i := 91 to 191 do
  467. LowerCaseTable[i] := chr(i);
  468. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  469. end;
  470. Procedure InitInternational;
  471. begin
  472. InitInternationalGeneric;
  473. InitAnsi;
  474. end;
  475. function SysErrorMessage(ErrorCode: Integer): String;
  476. begin
  477. Result:=''; // StrError(ErrorCode);
  478. end;
  479. {****************************************************************************
  480. OS utility functions
  481. ****************************************************************************}
  482. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  483. begin
  484. Result:=_getenv(PAnsiChar(EnvVar));
  485. end;
  486. Function GetEnvironmentVariableCount : Integer;
  487. begin
  488. // Result:=FPCCountEnvVar(EnvP);
  489. Result:=0;
  490. end;
  491. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  492. begin
  493. // Result:=FPCGetEnvStrFromP(Envp,Index);
  494. Result:='';
  495. end;
  496. function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
  497. var
  498. e : EOSError;
  499. CommandLine: RawByteString;
  500. begin
  501. dos.exec(path,comline);
  502. if (Dos.DosError <> 0) then
  503. begin
  504. if ComLine <> '' then
  505. CommandLine := Path + ' ' + ComLine
  506. else
  507. CommandLine := Path;
  508. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,Dos.DosError]);
  509. e.ErrorCode:=Dos.DosError;
  510. raise e;
  511. end;
  512. Result := DosExitCode;
  513. end;
  514. function ExecuteProcess (const Path: RawByteString;
  515. const ComLine: array of RawByteString;Flags:TExecuteFlags=[]): integer;
  516. var
  517. CommandLine: RawByteString;
  518. I: integer;
  519. begin
  520. Commandline := '';
  521. for I := 0 to High (ComLine) do
  522. if Pos (' ', ComLine [I]) <> 0 then
  523. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  524. else
  525. CommandLine := CommandLine + ' ' + Comline [I];
  526. ExecuteProcess := ExecuteProcess (Path, CommandLine);
  527. end;
  528. procedure Sleep(milliseconds: Cardinal);
  529. begin
  530. _delay (milliseconds);
  531. end;
  532. Function GetLastOSError : Integer;
  533. begin
  534. Result:=Integer(__get_errno_ptr^);
  535. end;
  536. {****************************************************************************
  537. Initialization code
  538. ****************************************************************************}
  539. Initialization
  540. InitExceptions; { Initialize exceptions. OS independent }
  541. InitInternational; { Initialize internationalization settings }
  542. OnBeep:=@SysBeep;
  543. Finalization
  544. FreeTerminateProcs;
  545. DoneExceptions;
  546. end.