sysutils.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 by the Free Pascal development team.
  4. Sysutils unit for netware (libc)
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit sysutils;
  12. interface
  13. {$MODE objfpc}
  14. { force ansistrings }
  15. {$H+}
  16. uses Libc,DOS;
  17. TYPE
  18. TNetwareLibcFindData =
  19. RECORD
  20. DirP : Pdirent; { used for opendir }
  21. EntryP: Pdirent; { and readdir }
  22. Magic : longint; { to avoid abends with uninitialized TSearchRec }
  23. _mask : string; { search mask i.e. *.* }
  24. _dir : string; { directory where to search }
  25. _attr : longint; { specified attribute }
  26. fname : string; { full pathname of found file }
  27. END;
  28. {$DEFINE HAS_SLEEP}
  29. {$DEFINE HAS_OSERROR}
  30. { Include platform independent interface part }
  31. {$i sysutilh.inc}
  32. { additional NetWare file flags}
  33. CONST
  34. faSHARE = M_A_SHARE shr 16; // Sharable file
  35. //faNO_SUBALLOC = $00000800; // Don't sub alloc. this file
  36. faTRANS = M_A_TRANS shr 16; // Transactional file (TTS usable)
  37. //faREADAUD = $00004000; // clib only: Read audit
  38. //faWRITAUD = $00008000; // clib only: Write audit
  39. faIMMPURG = M_A_IMMPURG shr 16; // Immediate purge
  40. faNORENAM = M_A_NORENAM shr 16; // Rename inhibit
  41. faNODELET = M_A_NODELET shr 16; // Delete inhibit
  42. faNOCOPY = M_A_NOCOPY shr 16; // Copy inhibit
  43. //faFILE_MIGRATED = $00400000; // clib only: File has been migrated
  44. //faDONT_MIGRATE = $00800000; // clib only: Don't migrate this file
  45. faIMMEDIATE_COMPRESS = M_A_IMMCOMPRESS shr 16; // Compress this file immediately
  46. faFILE_COMPRESSED = M_A_FILE_COMPRESSED shr 16; // File is compressed
  47. faDONT_COMPRESS = M_A_DONT_COMPRESS shr 16; // Don't compress this file
  48. faCANT_COMPRESS = M_A_CANT_COMPRESS shr 16; // Can't compress this file
  49. //faATTR_ARCHIVE = $40000000; // clib only: Entry has had an EA modified,
  50. // an ownerID changed, or trustee
  51. // info changed, etc.
  52. faSetNetwareAttrs = M_A_BITS_SIGNIFICANT; // if this is set, netware flags are changed also
  53. implementation
  54. uses
  55. sysconst;
  56. {$DEFINE FPC_FEXPAND_DRIVES}
  57. {$DEFINE FPC_FEXPAND_VOLUMES}
  58. {$DEFINE FPC_FEXPAND_NO_DEFAULT_PATHS}
  59. { Include platform independent implementation part }
  60. {$i sysutils.inc}
  61. {****************************************************************************
  62. File Functions
  63. ****************************************************************************}
  64. Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
  65. VAR NWOpenFlags : longint;
  66. BEGIN
  67. NWOpenFlags:=0;
  68. Case (Mode and 3) of
  69. 0 : NWOpenFlags:=NWOpenFlags or O_RDONLY;
  70. 1 : NWOpenFlags:=NWOpenFlags or O_WRONLY;
  71. 2 : NWOpenFlags:=NWOpenFlags or O_RDWR;
  72. end;
  73. FileOpen := Fpopen (pchar(FileName),NWOpenFlags);
  74. //!! We need to set locking based on Mode !!
  75. end;
  76. Function FileCreate (Const FileName : String) : THandle;
  77. begin
  78. FileCreate:=Fpopen(Pchar(FileName),O_RdWr or O_Creat or O_Trunc or O_Binary);
  79. if FileCreate >= 0 then
  80. FileSetAttr (Filename, 0); // dont know why but open always sets ReadOnly flag
  81. end;
  82. Function FileCreate (Const FileName : String; mode:longint) : THandle;
  83. begin
  84. FileCreate:=FileCreate (FileName);
  85. end;
  86. Function FileRead (Handle : THandle; Var Buffer; Count : longint) : Longint;
  87. begin
  88. FileRead:=libc.fpread (Handle,@Buffer,Count);
  89. end;
  90. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
  91. begin
  92. FileWrite:=libc.fpwrite (Handle,@Buffer,Count);
  93. end;
  94. Function FileSeek (Handle : THandle; FOffset,Origin : Longint) : Longint;
  95. begin
  96. FileSeek:=libc.fplseek (Handle,FOffset,Origin);
  97. end;
  98. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
  99. begin
  100. FileSeek:=libc.fplseek64 (Handle,FOffset,Origin);
  101. end;
  102. Procedure FileClose (Handle : THandle);
  103. begin
  104. libc.fpclose(Handle);
  105. end;
  106. Function FileTruncate (Handle : THandle; Size: Longint) : boolean;
  107. begin
  108. FileTruncate:=(libc.fpchsize(Handle,Size) = 0);
  109. end;
  110. Function FileLock (Handle : THandle; FOffset,FLen : Longint) : Longint;
  111. begin
  112. {$warning FileLock not implemented}
  113. //FileLock := _lock (Handle,FOffset,FLen);
  114. FileLock := -1;
  115. end;
  116. Function FileLock (Handle : THandle; FOffset,FLen : Int64) : Longint;
  117. begin
  118. {$warning need to add 64bit FileLock call }
  119. //FileLock := FileLock (Handle, longint(FOffset),longint(FLen));
  120. FileLock := -1;
  121. end;
  122. Function FileUnlock (Handle : THandle; FOffset,FLen : Longint) : Longint;
  123. begin
  124. //FileUnlock := _unlock (Handle,FOffset,FLen);
  125. {$warning FileUnLock not implemented}
  126. FileUnlock := -1;
  127. end;
  128. Function FileUnlock (Handle : THandle; FOffset,FLen : Int64) : Longint;
  129. begin
  130. {$warning need to add 64bit FileUnlock call }
  131. //FileUnlock := FileUnlock (Handle, longint(FOffset),longint(FLen));
  132. FileUnlock := -1;
  133. end;
  134. Function FileAge (Const FileName : String): Longint;
  135. var Info : TStat;
  136. TM : TTM;
  137. begin
  138. If Fpstat (pchar(FileName),Info) <> 0 then
  139. exit(-1)
  140. else
  141. begin
  142. localtime_r (Info.st_mtim.tv_sec,tm);
  143. with TM do
  144. result:=DateTimeToFileDate(EncodeDate(tm_year+1900,tm_mon+1,tm_mday)+EncodeTime(tm_hour,tm_min,tm_sec,0));
  145. end;
  146. end;
  147. Function FileExists (Const FileName : String) : Boolean;
  148. VAR Info : TStat;
  149. begin
  150. FileExists:=(Fpstat(pchar(filename),Info) = 0);
  151. end;
  152. Function UnixToWinAge(UnixAge : time_t): Longint;
  153. Var tm : TTm;
  154. begin
  155. libc.localtime_r (UnixAge, tm);
  156. with tm do
  157. Result:=DateTimeToFileDate(EncodeDate(tm_year+1900,tm_mon+1,tm_mday)+EncodeTime(tm_hour,tm_min,tm_sec,0));
  158. end;
  159. {returns true if attributes match}
  160. function find_setfields (var f : TsearchRec; var AttrsOk : boolean) : longint;
  161. var
  162. StatBuf : TStat;
  163. fname : string;
  164. begin
  165. result := 0;
  166. with F do
  167. begin
  168. if FindData.Magic = $AD02 then
  169. begin
  170. attr := (Pdirent(FindData.EntryP)^.d_mode shr 16) and $ffff;
  171. size := Pdirent(FindData.EntryP)^.d_size;
  172. name := strpas (Pdirent(FindData.EntryP)^.d_name);
  173. fname := FindData._dir + name;
  174. if Fpstat (pchar(fname),StatBuf) = 0 then
  175. time := UnixToWinAge (StatBuf.st_mtim.tv_sec)
  176. else
  177. time := 0;
  178. AttrsOk := false;
  179. if (f.FindData._attr and faHidden) = 0 then
  180. if attr and faHidden > 0 then exit;
  181. if (f.FindData._attr and faDirectory) = 0 then
  182. if attr and faDirectory > 0 then exit;
  183. if (f.FindData._attr and faSysFile) = 0 then
  184. if attr and faSysFile > 0 then exit;
  185. AttrsOk := true;
  186. end else
  187. begin
  188. FillChar (f,sizeof(f),0);
  189. result := 18;
  190. end;
  191. end;
  192. end;
  193. function findfirst(const path : string;attr : longint; out Rslt : TsearchRec) : longint;
  194. var
  195. path0 : string;
  196. p : longint;
  197. begin
  198. IF path = '' then
  199. begin
  200. result := 18;
  201. exit;
  202. end;
  203. Rslt.FindData._attr := attr;
  204. p := length (path);
  205. while (p > 0) and (not (path[p] in ['\','/'])) do
  206. dec (p);
  207. if p > 0 then
  208. begin
  209. Rslt.FindData._mask := copy (path,p+1,255);
  210. Rslt.FindData._dir := copy (path,1,p);
  211. end else
  212. begin
  213. Rslt.FindData._mask := path;
  214. Rslt.FindData._dir := GetCurrentDir;
  215. if (Rslt.FindData._dir[length(Rslt.FindData._dir)] <> '/') and
  216. (Rslt.FindData._dir[length(Rslt.FindData._dir)] <> '\') then
  217. Rslt.FindData._dir := Rslt.FindData._dir + '/';
  218. end;
  219. if Rslt.FindData._mask = '*' then Rslt.FindData._mask := '';
  220. if Rslt.FindData._mask = '*.*' then Rslt.FindData._mask := '';
  221. //writeln (stderr,'mask: "',Rslt._mask,'" dir:"',path0,'"');
  222. Pdirent(Rslt.FindData.DirP) := opendir (pchar(Rslt.FindData._dir));
  223. if Rslt.FindData.DirP = nil then
  224. result := 18
  225. else begin
  226. Rslt.FindData.Magic := $AD02;
  227. result := findnext (Rslt);
  228. end;
  229. end;
  230. function findnext(var Rslt : TsearchRec) : longint;
  231. var attrsOk : boolean;
  232. begin
  233. if Rslt.FindData.Magic <> $AD02 then
  234. begin
  235. result := 18;
  236. exit;
  237. end;
  238. result:=0;
  239. repeat
  240. Pdirent(Rslt.FindData.EntryP) := readdir (Pdirent(Rslt.FindData.DirP));
  241. if Rslt.FindData.EntryP = nil then
  242. result := 18
  243. else
  244. result := find_setfields (Rslt,attrsOk);
  245. if (result = 0) and (attrsOk) then
  246. begin
  247. if Rslt.FindData._mask = #0 then exit;
  248. if fnmatch(@Rslt.FindData._mask[1],Pdirent(Rslt.FindData.EntryP)^.d_name,FNM_CASEFOLD) = 0 then
  249. exit;
  250. end;
  251. until result <> 0;
  252. end;
  253. Procedure FindClose(Var f: TSearchRec);
  254. begin
  255. if F.FindData.Magic <> $AD02 then exit;
  256. doserror:=0;
  257. closedir (Pdirent(f.FindData.DirP));
  258. FillChar (f,sizeof(f),0);
  259. end;
  260. Function FileGetDate (Handle : THandle) : Longint;
  261. Var Info : TStat;
  262. _PTM : PTM;
  263. begin
  264. If Fpfstat(Handle,Info) <> 0 then
  265. Result:=-1
  266. else
  267. begin
  268. _PTM := localtime (Info.st_mtim.tv_sec);
  269. IF _PTM = NIL THEN
  270. exit(-1)
  271. else
  272. with _PTM^ do
  273. Result:=DateTimeToFileDate(EncodeDate(tm_year+1900,tm_mon+1,tm_mday)+EncodeTime(tm_hour,tm_min,tm_sec,0));
  274. end;
  275. end;
  276. Function FileSetDate (Handle : THandle; Age : Longint) : Longint;
  277. Begin
  278. {dont know how to do that, utime needs filename}
  279. result := -1;
  280. end;
  281. Function FileGetAttr (Const FileName : String) : Longint;
  282. Var Info : TStat;
  283. begin
  284. If Fpstat (pchar(FileName),Info) <> 0 then
  285. Result:=-1
  286. Else
  287. Result := (Info.st_mode shr 16) and $ffff;
  288. end;
  289. Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
  290. var
  291. StatBuf : TStat;
  292. newMode : longint;
  293. begin
  294. if Fpstat (pchar(Filename),StatBuf) = 0 then
  295. begin
  296. {what should i do here ?
  297. only support sysutils-standard attributes or also support the extensions defined
  298. only for netware libc ?
  299. For now i allow the complete attributes if the bit faSetNetwareAttrs is set. Otherwise
  300. only the standard attributes can be modified}
  301. if attr and faSetNetwareAttrs > 0 then
  302. begin
  303. newmode := ((attr shl 16) and $ffff0000) or M_A_BITS_SIGNIFICANT;
  304. end else
  305. begin
  306. attr := (attr and $2f) shl 16;
  307. newmode := StatBuf.st_mode and ($ffff0000-M_A_RDONLY-M_A_HIDDEN- M_A_SYSTEM-M_A_SUBDIR-M_A_ARCH);
  308. newmode := newmode or (attr shl 16) or M_A_BITS_SIGNIFICANT;
  309. end;
  310. if Fpchmod (pchar(Filename),newMode) < 0 then
  311. result := ___errno^ else
  312. result := 0;
  313. end else
  314. result := ___errno^;
  315. end;
  316. Function DeleteFile (Const FileName : String) : Boolean;
  317. begin
  318. Result:= (libc.UnLink (pchar(FileName)) = 0);
  319. end;
  320. Function RenameFile (Const OldName, NewName : String) : Boolean;
  321. begin
  322. RenameFile:=(libc.rename(pchar(OldName),pchar(NewName)) = 0);
  323. end;
  324. {****************************************************************************
  325. Disk Functions
  326. ****************************************************************************}
  327. {
  328. The Diskfree and Disksize functions need a file on the specified drive, since this
  329. is required for the statfs system call.
  330. These filenames are set in drivestr[0..26], and have been preset to :
  331. 0 - '.' (default drive - hence current dir is ok.)
  332. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  333. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  334. 3 - '/' (C: equivalent of dos is the root partition)
  335. 4..26 (can be set by you're own applications)
  336. ! Use AddDisk() to Add new drives !
  337. They both return -1 when a failure occurs.
  338. }
  339. Const
  340. FixDriveStr : array[0..3] of pchar=(
  341. '.',
  342. 'a:.',
  343. 'b:.',
  344. 'sys:/'
  345. );
  346. var
  347. Drives : byte;
  348. DriveStr : array[4..26] of pchar;
  349. Procedure AddDisk(const path:string);
  350. begin
  351. if not (DriveStr[Drives]=nil) then
  352. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  353. GetMem(DriveStr[Drives],length(Path)+1);
  354. StrPCopy(DriveStr[Drives],path);
  355. inc(Drives);
  356. if Drives>26 then
  357. Drives:=4;
  358. end;
  359. Function DiskFree(Drive: Byte): int64;
  360. //var fs : Tstatfs;
  361. Begin
  362. { if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  363. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  364. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  365. else
  366. Diskfree:=-1;}
  367. DiskFree := -1;
  368. ConsolePrintf ('warning: fpc sysutils.diskfree not implemented'#13#10);
  369. {$warning DiskFree not implemented (does it make sense ?) }
  370. End;
  371. Function DiskSize(Drive: Byte): int64;
  372. //var fs : statfs;
  373. Begin
  374. { if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  375. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  376. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  377. else
  378. DiskSize:=-1;}
  379. DiskSize := -1;
  380. ConsolePrintf ('warning: fpc sysutils.disksize not implemented'#13#10);
  381. {$warning DiskSize not implemented (does it make sense ?) }
  382. End;
  383. Function GetCurrentDir : String;
  384. begin
  385. GetDir (0,Result);
  386. end;
  387. Function SetCurrentDir (Const NewDir : String) : Boolean;
  388. begin
  389. Libc.FpChDir(pchar(NewDir));
  390. result := (___errno^ = 0);
  391. end;
  392. Function CreateDir (Const NewDir : String) : Boolean;
  393. begin
  394. Libc.FpMkDir(pchar(NewDir),0);
  395. result := (___errno^ = 0);
  396. end;
  397. Function RemoveDir (Const Dir : String) : Boolean;
  398. begin
  399. libc.FpRmDir(pchar(Dir));
  400. result := (___errno^ = 0);
  401. end;
  402. function DirectoryExists (const Directory: string): boolean;
  403. var Info : TStat;
  404. begin
  405. If Fpstat (pchar(Directory),Info) <> 0 then
  406. exit(false)
  407. else
  408. Exit ((Info.st_mode and M_A_SUBDIR) <> 0);
  409. end;
  410. {****************************************************************************
  411. Misc Functions
  412. ****************************************************************************}
  413. procedure Beep;
  414. begin
  415. RingBell;
  416. end;
  417. {****************************************************************************
  418. Locale Functions
  419. ****************************************************************************}
  420. Procedure GetLocalTime(var SystemTime: TSystemTime);
  421. var t : TTime;
  422. tm: Ttm;
  423. begin
  424. libc.time(t);
  425. libc.localtime_r(t,tm);
  426. with SystemTime do
  427. begin
  428. Hour := tm.tm_hour;
  429. Minute := tm.tm_min;
  430. Second := tm.tm_sec;
  431. MilliSecond := 0;
  432. Day := tm.tm_mday;
  433. Month := tm.tm_mon+1;
  434. Year := tm.tm_year+1900;
  435. end;
  436. end;
  437. Procedure InitAnsi;
  438. Var i : longint;
  439. begin
  440. { Fill table entries 0 to 127 }
  441. for i := 0 to 96 do
  442. UpperCaseTable[i] := chr(i);
  443. for i := 97 to 122 do
  444. UpperCaseTable[i] := chr(i - 32);
  445. for i := 123 to 191 do
  446. UpperCaseTable[i] := chr(i);
  447. Move (CPISO88591UCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  448. for i := 0 to 64 do
  449. LowerCaseTable[i] := chr(i);
  450. for i := 65 to 90 do
  451. LowerCaseTable[i] := chr(i + 32);
  452. for i := 91 to 191 do
  453. LowerCaseTable[i] := chr(i);
  454. Move (CPISO88591LCT,UpperCaseTable[192],SizeOf(CPISO88591UCT));
  455. end;
  456. Procedure InitInternational;
  457. begin
  458. InitInternationalGeneric;
  459. InitAnsi;
  460. end;
  461. function SysErrorMessage(ErrorCode: Integer): String;
  462. begin
  463. Result:=''; // only found perror that prints the message
  464. end;
  465. {****************************************************************************
  466. OS utility functions
  467. ****************************************************************************}
  468. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  469. begin
  470. Result:=StrPas(libc.getenv(PChar(EnvVar)));
  471. end;
  472. Function GetEnvironmentVariableCount : Integer;
  473. begin
  474. Result:=FPCCountEnvVar(EnvP);
  475. end;
  476. Function GetEnvironmentString(Index : Integer) : String;
  477. begin
  478. Result:=FPCGetEnvStrFromP(Envp,Index);
  479. end;
  480. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
  481. var
  482. params:array of AnsiString;
  483. count,i: longint;
  484. Buf : pchar;
  485. p : pchar;
  486. CLine: AnsiString;
  487. begin
  488. cLine := ComLine;
  489. buf:=pchar(CLine);
  490. count:=0;
  491. while(buf^<>#0) do
  492. begin
  493. while (buf^ in [' ',#9,#10]) do
  494. inc(buf);
  495. inc(count);
  496. while not (buf^ in [' ',#0,#9,#10]) do
  497. inc(buf);
  498. end;
  499. i := 0;
  500. setlength(params,count);
  501. buf:=pchar(CLine);
  502. while(buf^<>#0) do
  503. begin
  504. while (buf^ in [' ',#9,#10]) do
  505. inc(buf);
  506. p := buf;
  507. while not (buf^ in [' ',#0,#9,#10]) do
  508. inc(buf);
  509. if buf^ <> #0 then
  510. begin
  511. buf^ := #0;
  512. inc(buf);
  513. end;
  514. params[i]:=p;
  515. inc(i);
  516. end;
  517. result := ExecuteProcess (Path, params);
  518. end;
  519. Function GetLastOSError : Integer;
  520. begin
  521. Result:=Integer(GetLastError);
  522. end;
  523. {******************************************************************************
  524. --- Exec ---
  525. ******************************************************************************}
  526. const maxargs=256;
  527. function ExecuteProcess (const Path: AnsiString;
  528. const ComLine: array of AnsiString): integer;
  529. var c : comstr;
  530. i : integer;
  531. args : array[0..maxargs+1] of pchar;
  532. arg0 : string;
  533. numargs,wstat : integer;
  534. Wiring : TWiring;
  535. newPath : string;
  536. e : EOSError;
  537. begin
  538. if pos ('.',path) = 0 then
  539. arg0 := fexpand(path+'.nlm')
  540. else
  541. arg0 := fexpand (path);
  542. args[0] := pchar(arg0);
  543. numargs := 0;
  544. for I := 0 to High (ComLine) do
  545. if numargs < maxargs then
  546. begin
  547. inc(numargs);
  548. args[numargs] := pchar(ComLine[i]);
  549. end;
  550. args[numargs+1] := nil;
  551. Wiring.infd := StdInputHandle; //textrec(Stdin).Handle;
  552. Wiring.outfd:= textrec(stdout).Handle;
  553. Wiring.errfd:= textrec(stderr).Handle;
  554. i := procve(args[0],
  555. PROC_CURRENT_SPACE+PROC_INHERIT_CWD,
  556. envP, // const char * env[] If passed as NULL, the child process inherits the parent.s environment at the time of the call.
  557. @Wiring, // wiring_t *wiring, Pass NULL to inherit system defaults for wiring.
  558. nil, // struct fd_set *fds, Not currently implemented. Pass in NULL.
  559. nil, // void *appdata, Not currently implemented. Pass in NULL.
  560. 0, // size_t appdata_size, Not currently implemented. Pass in 0
  561. nil, // void *reserved, Reserved. Pass NULL.
  562. @args); // const char *argv[]
  563. if i <> -1 then
  564. begin
  565. Fpwaitpid(i,@wstat,0);
  566. result := wstat;
  567. end else
  568. begin
  569. e:=EOSError.CreateFmt(SExecuteProcessFailed,[arg0,___errno^]);
  570. e.ErrorCode:=___errno^;
  571. raise e;
  572. end;
  573. end;
  574. procedure Sleep(milliseconds: Cardinal);
  575. begin
  576. libc._delay (milliseconds);
  577. end;
  578. {****************************************************************************
  579. Initialization code
  580. ****************************************************************************}
  581. Initialization
  582. InitExceptions; { Initialize exceptions. OS independent }
  583. InitInternational; { Initialize internationalization settings }
  584. Finalization
  585. DoneExceptions;
  586. end.