sysutils.pp 19 KB

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