sysutils.pp 19 KB

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