unix.pp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. BSD parts (c) 2000 by Marco van de Voort
  5. members of the Free Pascal development team.
  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. Unit Unix;
  13. Interface
  14. Uses BaseUnix,UnixType;
  15. {$if defined(BSD) and defined(FPC_USE_LIBC)}
  16. {$define USE_VFORK}
  17. {$endif}
  18. {$i aliasptp.inc}
  19. { Get Types and Constants only exported in this unit }
  20. {$i unxconst.inc}
  21. // We init to zero to be able to put timezone stuff under IFDEF, and still
  22. // keep the code working.
  23. // We can't do this hear, since unixutil functions access this.
  24. // var
  25. // Tzseconds : Longint = 0;
  26. {********************
  27. File
  28. ********************}
  29. Const
  30. P_IN = 1; // pipes (?)
  31. P_OUT = 2;
  32. Const
  33. LOCK_SH = 1; // flock constants ?
  34. LOCK_EX = 2;
  35. LOCK_UN = 8;
  36. LOCK_NB = 4;
  37. Type
  38. Tpipe = baseunix.tfildes; // compability.
  39. {******************************************************************************
  40. Procedure/Functions
  41. ******************************************************************************}
  42. {**************************
  43. Time/Date Handling
  44. ***************************}
  45. var
  46. tzdaylight : boolean;
  47. tzname : array[boolean] of pchar;
  48. {$IFNDEF DONT_READ_TIMEZONE} // allows to disable linking in and trying for platforms
  49. // it doesn't (yet) work for.
  50. { timezone support }
  51. procedure GetLocalTimezone(timer:cint;var leap_correct,leap_hit:cint);
  52. procedure GetLocalTimezone(timer:cint);
  53. procedure ReadTimezoneFile(fn:string);
  54. function GetTimezoneFile:string;
  55. {$ENDIF}
  56. {**************************
  57. Process Handling
  58. ***************************}
  59. //
  60. // These are much better, in nearly all ways.
  61. //
  62. function FpExecLE (Const PathName:AnsiString;const S:Array Of AnsiString;MyEnv:ppchar):cint;
  63. function FpExecL(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
  64. function FpExecLP(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
  65. function FpExecV(Const PathName:AnsiString;args:ppchar):cint;
  66. function FpExecVP(Const PathName:AnsiString;args:ppchar):cint;
  67. function FpExecVPE(Const PathName:AnsiString;args,env:ppchar):cint;
  68. Function Shell (const Command:String):cint;
  69. Function Shell (const Command:AnsiString):cint;
  70. Function fpSystem(const Command:AnsiString):cint;
  71. Function WaitProcess (Pid:cint):cint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  72. Function WIFSTOPPED (Status: Integer): Boolean;
  73. Function W_EXITCODE (ReturnCode, Signal: Integer): Integer;
  74. Function W_STOPCODE (Signal: Integer): Integer;
  75. {**************************
  76. File Handling
  77. ***************************}
  78. {$ifndef FPC_USE_LIBC} // defined using cdecl for libc.
  79. Function fsync (fd : cint) : cint;
  80. Function fpFlock (fd,mode : cint) : cint ;
  81. Function fStatFS (Fd: cint;Var Info:tstatfs):cint;
  82. Function StatFS (Path:pchar;Var Info:tstatfs):cint;
  83. {$endif}
  84. Function fpFlock (var T : text;mode : cint) : cint;
  85. Function fpFlock (var F : File;mode : cint) : cint;
  86. Function SelectText (var T:Text;TimeOut :PTimeVal):cint;
  87. Function SelectText (var T:Text;TimeOut :cint):cint;
  88. {**************************
  89. Directory Handling
  90. ***************************}
  91. procedure SeekDir(p:pdir;loc:clong);
  92. function TellDir(p:pdir):TOff;
  93. {**************************
  94. Pipe/Fifo/Stream
  95. ***************************}
  96. Function AssignPipe (var pipe_in,pipe_out:cint):cint;
  97. Function AssignPipe (var pipe_in,pipe_out:text):cint;
  98. Function AssignPipe (var pipe_in,pipe_out:file):cint;
  99. //Function PClose (Var F:text) : cint;
  100. //Function PClose (Var F:file) : cint;
  101. Function POpen (var F:text;const Prog:Ansistring;rw:char):cint;
  102. Function POpen (var F:file;const Prog:Ansistring;rw:char):cint;
  103. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:ansiString;const args : array of ansistring) : cint;
  104. Function AssignStream(Var StreamIn,Streamout,streamerr:text;Const Prog:ansiString;const args : array of ansistring) : cint;
  105. Function GetDomainName:String;
  106. Function GetHostName:String;
  107. {**************************
  108. Memory functions
  109. ***************************}
  110. const
  111. PROT_READ = $1; { page can be read }
  112. PROT_WRITE = $2; { page can be written }
  113. PROT_EXEC = $4; { page can be executed }
  114. PROT_NONE = $0; { page can not be accessed }
  115. MAP_SHARED = $1; { Share changes }
  116. // MAP_PRIVATE = $2; { Changes are private }
  117. MAP_TYPE = $f; { Mask for type of mapping }
  118. MAP_FIXED = $10; { Interpret addr exactly }
  119. // MAP_ANONYMOUS = $20; { don't use a file }
  120. {$ifdef Linux}
  121. MAP_GROWSDOWN = $100; { stack-like segment }
  122. MAP_DENYWRITE = $800; { ETXTBSY }
  123. MAP_EXECUTABLE = $1000; { mark it as an executable }
  124. MAP_LOCKED = $2000; { pages are locked }
  125. MAP_NORESERVE = $4000; { don't check for reservations }
  126. {$else}
  127. {$ifdef FreeBSD}
  128. // FreeBSD defines MAP_COPY=MAP_PRIVATE=$2;
  129. MAP_FILE = $0000; { map from file (default) }
  130. MAP_ANON = $1000; { allocated from memory, swap space }
  131. MAP_RENAME = $0020; { Sun: rename private pages to file }
  132. MAP_NORESERVE = $0040; { Sun: don't reserve needed swap area }
  133. MAP_INHERIT = $0080; { region is retained after exec }
  134. MAP_NOEXTEND = $0100; { for MAP_FILE, don't change file size }
  135. MAP_HASSEMAPHORE = $0200; { region may contain semaphores }
  136. MAP_STACK = $0400; { region grows down, like a stack }
  137. MAP_NOSYNC = $0800; { page to but do not sync underlying file}
  138. MAP_NOCORE = $20000;{ dont include these pages in a coredump}
  139. {$endif}
  140. {$endif}
  141. {**************************
  142. Utility functions
  143. ***************************}
  144. Type
  145. TFSearchOption = (NoCurrentDirectory,
  146. CurrentDirectoryFirst,
  147. CurrentDirectoryLast);
  148. Function FSearch (const path:AnsiString;dirlist:Ansistring;CurrentDirStrategy:TFSearchOption):AnsiString;
  149. Function FSearch (const path:AnsiString;dirlist:AnsiString):AnsiString;
  150. procedure SigRaise (sig:integer);
  151. {$ifdef FPC_USE_LIBC}
  152. const clib = 'c';
  153. {$i unxdeclh.inc}
  154. {$else}
  155. {$i unxsysch.inc} // calls used in system and not reexported from baseunix
  156. {$endif}
  157. {******************************************************************************
  158. Implementation
  159. ******************************************************************************}
  160. {$i unxovlh.inc}
  161. Implementation
  162. Uses UnixUtil, // tzseconds
  163. Strings {$ifndef FPC_USE_LIBC},Syscall{$endif};
  164. {$i unxovl.inc}
  165. {$ifndef FPC_USE_LIBC}
  166. {$i syscallh.inc}
  167. {$i unxsysc.inc}
  168. {$endif}
  169. { Get the definitions of textrec and filerec }
  170. {$i textrec.inc}
  171. {$i filerec.inc}
  172. {$i unxfunc.inc} { Platform specific implementations }
  173. Function getenv(name:string):Pchar; external name 'FPC_SYSC_FPGETENV';
  174. {******************************************************************************
  175. Process related calls
  176. ******************************************************************************}
  177. { Most calls of WaitPID do not handle the result correctly, this funktion treats errors more correctly }
  178. Function WaitProcess(Pid:cint):cint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  179. var
  180. r,s : cint;
  181. begin
  182. s:=$7F00;
  183. repeat
  184. r:=fpWaitPid(Pid,@s,0);
  185. if (r=-1) and (fpgeterrno=ESysEIntr) Then
  186. r:=0;
  187. until (r<>0);
  188. if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
  189. WaitProcess:=-1 // return -1 to indicate an error. fpwaitpid updated it.
  190. else
  191. begin
  192. if wifexited(s) then
  193. WaitProcess:=wexitstatus(s)
  194. else if (s>0) then // Until now there is not use of the highest bit , but check this for the future
  195. WaitProcess:=-s // normal case
  196. else
  197. WaitProcess:=s; // s<0 should not occur, but wie return also a negativ value
  198. end;
  199. end;
  200. function intFpExecVEMaybeP (Const PathName:AnsiString;Args,MyEnv:ppchar;SearchPath:Boolean):cint;
  201. // does an ExecVE, but still has to handle P
  202. // execv variants call this directly, execl variants indirectly via
  203. // intfpexecl
  204. Var
  205. NewCmd : ansistring;
  206. ThePath : AnsiString;
  207. Begin
  208. If SearchPath and (pos('/',pathname)=0) Then
  209. Begin
  210. // The above could be better. (check if not escaped/quoted '/'s) ?
  211. // (Jilles says this is ok)
  212. // Stevens says only search if newcmd contains no '/'
  213. // fsearch is not ansistring clean yet.
  214. ThePath:=fpgetenv('PATH');
  215. if thepath='' then
  216. thepath:='.'; // FreeBSD uses _PATH_DEFPATH = /usr/bin:/bin
  217. // but a quick check showed that _PATH_DEFPATH
  218. // varied from OS to OS
  219. newcmd:=FSearch(pathname,thepath,NoCurrentDirectory);
  220. // FreeBSD libc keeps on trying till a file is successfully run.
  221. // Stevens says "try each path prefix"
  222. // execp puts newcmd here.
  223. args^:=pchar(newcmd);
  224. End else
  225. newcmd:=pathname;
  226. // repeat
  227. // if searchpath then args^:=pchar(commandtorun)
  228. IntFpExecVEMaybeP:=fpExecVE(newcmd,Args,MyEnv);
  229. {
  230. // Code that if exec fails due to permissions, tries to run it with sh
  231. // Should we deallocate p on fail? -> no fpexit is run no matter what
  232. //
  233. }
  234. // if intfpexecvemaybep=-1 then zoekvolgende file.
  235. // until (Goexit) or SearchExit;
  236. {
  237. If IntFpExec=-1 Then
  238. Begin
  239. Error:=fpGetErrno
  240. Case Error of
  241. ESysE2Big : Exit(-1);
  242. ESysELoop,
  243. : Exit(-1);
  244. }
  245. end;
  246. function intFpExecl (Const PathName:AnsiString;const s:array of ansistring;MyEnv:ppchar;SearchPath:Boolean):cint;
  247. { Handles the array of ansistring -> ppchar conversion.
  248. Base for the the "l" variants.
  249. }
  250. var p:ppchar;
  251. begin
  252. If PathName='' Then
  253. Begin
  254. fpsetErrno(ESysEnoEnt);
  255. Exit(-1); // Errno?
  256. End;
  257. p:=ArrayStringToPPchar(s,1);
  258. if p=NIL Then
  259. Begin
  260. GetMem(p,2*sizeof(pchar));
  261. if p=nil then
  262. begin
  263. {$ifdef xunix}
  264. fpseterrno(ESysEnoMem);
  265. {$endif}
  266. fpseterrno(ESysEnoEnt);
  267. exit(-1);
  268. end;
  269. p[1]:=nil;
  270. End;
  271. p^:=pchar(PathName);
  272. IntFPExecL:=intFpExecVEMaybeP(PathName,p,MyEnv,SearchPath);
  273. // If we come here, no attempts were executed successfully.
  274. Freemem(p);
  275. end;
  276. function FpExecLE (Const PathName:AnsiString;const S:Array Of AnsiString;MyEnv:ppchar):cint;
  277. Begin
  278. FpExecLE:=intFPExecl(PathName,s,MyEnv,false);
  279. End;
  280. function FpExecL(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
  281. Begin
  282. FpExecL:=intFPExecl(PathName,S,EnvP,false);
  283. End;
  284. function FpExecLP(Const PathName:AnsiString;const S:Array Of AnsiString):cint;
  285. Begin
  286. FpExecLP:=intFPExecl(PathName,S,EnvP,True);
  287. End;
  288. function FpExecV(Const PathName:AnsiString;args:ppchar):cint;
  289. Begin
  290. fpexecV:=intFpExecVEMaybeP (PathName,args,envp,false);
  291. End;
  292. function FpExecVP(Const PathName:AnsiString;args:ppchar):cint;
  293. Begin
  294. fpexecVP:=intFpExecVEMaybeP (PathName,args,envp,true);
  295. End;
  296. function FpExecVPE(Const PathName:AnsiString;args,env:ppchar):cint;
  297. Begin
  298. fpexecVPE:=intFpExecVEMaybeP (PathName,args,env,true);
  299. End;
  300. // exect and execvP (ExecCapitalP) are not implement
  301. // Non POSIX anyway.
  302. // Exect turns on tracing for the process
  303. // execvP has the searchpath as array of ansistring ( const char *search_path)
  304. {$define FPC_USE_FPEXEC}
  305. {$if defined(FPC_USE_FPEXEC) and not defined(USE_VFORK)}
  306. {$define SHELL_USE_FPEXEC}
  307. {$endif}
  308. Function Shell(const Command:String):cint;
  309. {
  310. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  311. The current environment is passed to the shell.
  312. It waits for the shell to exit, and returns its exit status.
  313. If the Exec call failed exit status 127 is reported.
  314. }
  315. { Changed the structure:
  316. - the previous version returns an undefinied value if fork fails
  317. - it returns the status of Waitpid instead of the Process returnvalue (see the doc to Shell)
  318. - it uses exit(127) not ExitProc (The Result in pp386: going on Compiling in 2 processes!)
  319. - ShellArgs are now released
  320. - The Old CreateShellArg gives back pointers to a local var
  321. }
  322. var
  323. {$ifndef SHELL_USE_FPEXEC}
  324. p : ppchar;
  325. {$endif}
  326. pid : cint;
  327. begin
  328. {$ifndef SHELL_USE_FPEXEC}
  329. p:=CreateShellArgv(command);
  330. {$endif}
  331. {$ifdef USE_VFORK}
  332. pid:=fpvfork;
  333. {$else USE_VFORK}
  334. pid:=fpfork;
  335. {$endif USE_VFORK}
  336. if pid=0 then // We are in the Child
  337. begin
  338. {This is the child.}
  339. {$ifndef SHELL_USE_FPEXEC}
  340. fpExecve(p^,p,envp);
  341. {$else}
  342. fpexecl('/bin/sh',['-c',Command]);
  343. {$endif}
  344. fpExit(127); // was Exit(127)
  345. end
  346. else if (pid<>-1) then // Successfull started
  347. Shell:=WaitProcess(pid)
  348. else // no success
  349. Shell:=-1; // indicate an error
  350. {$ifndef SHELL_USE_FPEXEC}
  351. FreeShellArgV(p);
  352. {$endif}
  353. end;
  354. Function Shell(const Command:AnsiString):cint;
  355. {
  356. AnsiString version of Shell
  357. }
  358. var
  359. {$ifndef SHELL_USE_FPEXEC}
  360. p : ppchar;
  361. {$endif}
  362. pid : cint;
  363. begin { Changes as above }
  364. {$ifndef SHELL_USE_FPEXEC}
  365. p:=CreateShellArgv(command);
  366. {$endif}
  367. {$ifdef USE_VFORK}
  368. pid:=fpvfork;
  369. {$else USE_VFORK}
  370. pid:=fpfork;
  371. {$endif USE_VFORK}
  372. if pid=0 then // We are in the Child
  373. begin
  374. {$ifdef SHELL_USE_FPEXEC}
  375. fpexecl('/bin/sh',['-c',Command]);
  376. {$else}
  377. fpExecve(p^,p,envp);
  378. {$endif}
  379. fpExit(127); // was exit(127)!! We must exit the Process, not the function
  380. end
  381. else if (pid<>-1) then // Successfull started
  382. Shell:=WaitProcess(pid)
  383. else // no success
  384. Shell:=-1;
  385. {$ifndef SHELL_USE_FPEXEC}
  386. FreeShellArgV(p);
  387. {$ENDIF}
  388. end;
  389. {$ifdef FPC_USE_LIBC}
  390. function xfpsystem(p:pchar):cint; cdecl; external clib name 'system';
  391. Function fpSystem(const Command:AnsiString):cint;
  392. begin
  393. fpsystem:=xfpsystem(pchar(command));
  394. end;
  395. {$else}
  396. Function fpSystem(const Command:AnsiString):cint;
  397. {
  398. AnsiString version of Shell
  399. }
  400. var
  401. pid,savedpid : cint;
  402. pstat : cint;
  403. ign,intact,
  404. quitact : SigactionRec;
  405. newsigblock,
  406. oldsigblock : tsigset;
  407. begin { Changes as above }
  408. if command='' then exit(1);
  409. ign.sa_handler:=SigActionHandler(SIG_IGN);
  410. fpsigemptyset(ign.sa_mask);
  411. ign.sa_flags:=0;
  412. fpsigaction(SIGINT, @ign, @intact);
  413. fpsigaction(SIGQUIT, @ign, @quitact);
  414. fpsigemptyset(newsigblock);
  415. fpsigaddset(newsigblock,SIGCHLD);
  416. fpsigprocmask(SIG_BLOCK,newsigblock,oldsigblock);
  417. pid:=fpfork;
  418. if pid=0 then // We are in the Child
  419. begin
  420. fpsigaction(SIGINT,@intact,NIL);
  421. fpsigaction(SIGQUIT,@quitact,NIL);
  422. fpsigprocmask(SIG_SETMASK,@oldsigblock,NIL);
  423. fpexecl('/bin/sh',['-c',Command]);
  424. fpExit(127); // was exit(127)!! We must exit the Process, not the function
  425. end
  426. else if (pid<>-1) then // Successfull started
  427. begin
  428. savedpid:=pid;
  429. repeat
  430. pid:=fpwaitpid(savedpid,@pstat,0);
  431. until (pid<>-1) and (fpgeterrno()<>ESysEintr);
  432. if pid=-1 Then
  433. fpsystem:=-1
  434. else
  435. fpsystem:=pstat;
  436. end
  437. else // no success
  438. fpsystem:=-1;
  439. fpsigaction(SIGINT,@intact,NIL);
  440. fpsigaction(SIGQUIT,@quitact,NIL);
  441. fpsigprocmask(SIG_SETMASK,@oldsigblock,NIL);
  442. end;
  443. {$endif}
  444. Function WIFSTOPPED(Status: Integer): Boolean;
  445. begin
  446. WIFSTOPPED:=((Status and $FF)=$7F);
  447. end;
  448. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  449. begin
  450. W_EXITCODE:=(ReturnCode shl 8) or Signal;
  451. end;
  452. Function W_STOPCODE(Signal: Integer): Integer;
  453. begin
  454. W_STOPCODE:=(Signal shl 8) or $7F;
  455. end;
  456. {$IFNDEF DONT_READ_TIMEZONE}
  457. { Include timezone handling routines which use /usr/share/timezone info }
  458. {$i timezone.inc}
  459. {$endif}
  460. {******************************************************************************
  461. FileSystem calls
  462. ******************************************************************************}
  463. Function fpFlock (var T : text;mode : cint) : cint;
  464. begin
  465. fpFlock:=fpFlock(TextRec(T).Handle,mode);
  466. end;
  467. Function fpFlock (var F : File;mode : cint) :cint;
  468. begin
  469. fpFlock:=fpFlock(FileRec(F).Handle,mode);
  470. end;
  471. Function SelectText(var T:Text;TimeOut :PTimeval):cint;
  472. Var
  473. F:TfdSet;
  474. begin
  475. if textrec(t).mode=fmclosed then
  476. begin
  477. fpseterrno(ESysEBADF);
  478. exit(-1);
  479. end;
  480. FpFD_ZERO(f);
  481. fpFD_SET(textrec(T).handle,f);
  482. if textrec(T).mode=fminput then
  483. SelectText:=fpselect(textrec(T).handle+1,@f,nil,nil,TimeOut)
  484. else
  485. SelectText:=fpselect(textrec(T).handle+1,nil,@f,nil,TimeOut);
  486. end;
  487. Function SelectText(var T:Text;TimeOut :cint):cint;
  488. var
  489. p : PTimeVal;
  490. tv : TimeVal;
  491. begin
  492. if TimeOut=-1 then
  493. p:=nil
  494. else
  495. begin
  496. tv.tv_Sec:=Timeout div 1000;
  497. tv.tv_Usec:=(Timeout mod 1000)*1000;
  498. p:=@tv;
  499. end;
  500. SelectText:=SelectText(T,p);
  501. end;
  502. {******************************************************************************
  503. Directory
  504. ******************************************************************************}
  505. procedure SeekDir(p:pdir;loc:clong);
  506. begin
  507. if p=nil then
  508. begin
  509. fpseterrno(ESysEBADF);
  510. exit;
  511. end;
  512. {$if not(defined(bsd)) and not(defined(solaris)) }
  513. p^.dd_nextoff:=fplseek(p^.dd_fd,loc,seek_set);
  514. {$endif}
  515. p^.dd_size:=0;
  516. p^.dd_loc:=0;
  517. end;
  518. function TellDir(p:pdir):TOff;
  519. begin
  520. if p=nil then
  521. begin
  522. fpseterrno(ESysEBADF);
  523. telldir:=-1;
  524. exit;
  525. end;
  526. telldir:=fplseek(p^.dd_fd,0,seek_cur)
  527. { We could try to use the nextoff field here, but on my 1.2.13
  528. kernel, this gives nothing... This may have to do with
  529. the readdir implementation of libc... I also didn't find any trace of
  530. the field in the kernel code itself, So I suspect it is an artifact of libc.
  531. Michael. }
  532. end;
  533. {******************************************************************************
  534. Pipes/Fifo
  535. ******************************************************************************}
  536. Procedure OpenPipe(var F:Text);
  537. begin
  538. case textrec(f).mode of
  539. fmoutput :
  540. if textrec(f).userdata[1]<>P_OUT then
  541. textrec(f).mode:=fmclosed;
  542. fminput :
  543. if textrec(f).userdata[1]<>P_IN then
  544. textrec(f).mode:=fmclosed;
  545. else
  546. textrec(f).mode:=fmclosed;
  547. end;
  548. end;
  549. Function IOPipe(var F:text):cint;
  550. begin
  551. IOPipe:=0;
  552. case textrec(f).mode of
  553. fmoutput :
  554. begin
  555. { first check if we need something to write, else we may
  556. get a SigPipe when Close() is called (PFV) }
  557. if textrec(f).bufpos>0 then
  558. IOPipe:=fpwrite(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  559. end;
  560. fminput : Begin
  561. textrec(f).bufend:=fpread(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  562. IOPipe:=textrec(f).bufend;
  563. End;
  564. end;
  565. textrec(f).bufpos:=0;
  566. end;
  567. Function FlushPipe(var F:Text):cint;
  568. begin
  569. FlushPipe:=0;
  570. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  571. FlushPipe:=IOPipe(f);
  572. textrec(f).bufpos:=0;
  573. end;
  574. Function ClosePipe(var F:text):cint;
  575. begin
  576. textrec(f).mode:=fmclosed;
  577. ClosePipe:=fpclose(textrec(f).handle);
  578. end;
  579. Function AssignPipe(var pipe_in,pipe_out:text):cint;
  580. {
  581. Sets up a pair of file variables, which act as a pipe. The first one can
  582. be read from, the second one can be written to.
  583. }
  584. var
  585. f_in,f_out : cint;
  586. begin
  587. if AssignPipe(f_in,f_out)=-1 then
  588. exit(-1);
  589. { Set up input }
  590. Assign(Pipe_in,'');
  591. Textrec(Pipe_in).Handle:=f_in;
  592. Textrec(Pipe_in).Mode:=fmInput;
  593. Textrec(Pipe_in).userdata[1]:=P_IN;
  594. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  595. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  596. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  597. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  598. { Set up output }
  599. Assign(Pipe_out,'');
  600. Textrec(Pipe_out).Handle:=f_out;
  601. Textrec(Pipe_out).Mode:=fmOutput;
  602. Textrec(Pipe_out).userdata[1]:=P_OUT;
  603. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  604. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  605. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  606. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  607. AssignPipe:=0;
  608. end;
  609. Function AssignPipe(var pipe_in,pipe_out:file):cint;
  610. {
  611. Sets up a pair of file variables, which act as a pipe. The first one can
  612. be read from, the second one can be written to.
  613. If the operation was unsuccesful,
  614. }
  615. var
  616. f_in,f_out : cint;
  617. begin
  618. if AssignPipe(f_in,f_out)=-1 then
  619. exit(-1);
  620. { Set up input }
  621. Assign(Pipe_in,'');
  622. Filerec(Pipe_in).Handle:=f_in;
  623. Filerec(Pipe_in).Mode:=fmInput;
  624. Filerec(Pipe_in).recsize:=1;
  625. Filerec(Pipe_in).userdata[1]:=P_IN;
  626. { Set up output }
  627. Assign(Pipe_out,'');
  628. Filerec(Pipe_out).Handle:=f_out;
  629. Filerec(Pipe_out).Mode:=fmoutput;
  630. Filerec(Pipe_out).recsize:=1;
  631. Filerec(Pipe_out).userdata[1]:=P_OUT;
  632. AssignPipe:=0;
  633. end;
  634. Function PCloseText(Var F:text):cint;
  635. {
  636. May not use @PClose due overloading
  637. }
  638. begin
  639. PCloseText:=PClose(f);
  640. end;
  641. Function POpen(var F:text;const Prog:Ansistring;rw:char):cint;
  642. {
  643. Starts the program in 'Prog' and makes it's input or out put the
  644. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  645. F, will be read from stdin by the program in 'Prog'. The inverse is true
  646. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  647. read from 'f'.
  648. }
  649. var
  650. pipi,
  651. pipo : text;
  652. pid : cint;
  653. pl : ^cint;
  654. {$if not defined(FPC_USE_FPEXEC) or defined(USE_VFORK)}
  655. pp : array[0..3] of pchar;
  656. temp : string[255];
  657. {$endif not FPC_USE_FPEXEC or USE_VFORK}
  658. ret : cint;
  659. begin
  660. rw:=upcase(rw);
  661. if not (rw in ['R','W']) then
  662. begin
  663. FpSetErrno(ESysEnoent);
  664. exit(-1);
  665. end;
  666. ret:=AssignPipe(pipi,pipo);
  667. if ret=-1 then
  668. exit(-1);
  669. {$ifdef USE_VFORK}
  670. pid:=fpvfork;
  671. {$else USE_VFORK}
  672. pid:=fpfork;
  673. {$endif USE_VFORK}
  674. if pid=-1 then
  675. begin
  676. close(pipi);
  677. close(pipo);
  678. exit(-1);
  679. end;
  680. if pid=0 then
  681. begin
  682. { We're in the child }
  683. if rw='W' then
  684. begin
  685. if (textrec(pipi).handle <> stdinputhandle) then
  686. begin
  687. ret:=fpdup2(pipi,input);
  688. {$ifdef USE_VFORK}
  689. fpclose(textrec(pipi).handle);
  690. {$else USE_VFORK}
  691. close(pipi);
  692. {$endif USE_VFORK}
  693. end;
  694. {$ifdef USE_VFORK}
  695. fpclose(textrec(pipo).handle);
  696. {$else USE_VFORK}
  697. close(pipo);
  698. {$endif USE_VFORK}
  699. if ret=-1 then
  700. fpexit(127);
  701. end
  702. else
  703. begin
  704. {$ifdef USE_VFORK}
  705. fpclose(textrec(pipi).handle);
  706. {$else USE_VFORK}
  707. close(pipi);
  708. {$endif USE_VFORK}
  709. if (textrec(pipo).handle <> stdoutputhandle) then
  710. begin
  711. ret:=fpdup2(pipo,output);
  712. {$ifdef USE_VFORK}
  713. fpclose(textrec(pipo).handle);
  714. {$else USE_VFORK}
  715. close(pipo);
  716. {$endif USE_VFORK}
  717. end;
  718. if ret=-1 then
  719. fpexit(127);
  720. end;
  721. {$if defined(FPC_USE_FPEXEC) and not defined(USE_VFORK)}
  722. fpexecl(pchar('/bin/sh'),['-c',Prog]);
  723. {$else}
  724. temp:='/bin/sh'#0'-c'#0;
  725. pp[0]:=@temp[1];
  726. pp[1]:=@temp[9];
  727. pp[2]:=@prog[1];
  728. pp[3]:=Nil;
  729. fpExecve('/bin/sh',@pp,envp);
  730. {$endif}
  731. fpexit(127);
  732. end
  733. else
  734. begin
  735. { We're in the parent }
  736. if rw='W' then
  737. begin
  738. close(pipi);
  739. f:=pipo;
  740. end
  741. else
  742. begin
  743. close(pipo);
  744. f:=pipi;
  745. end;
  746. textrec(f).bufptr:=@textrec(f).buffer;
  747. {Save the process ID - needed when closing }
  748. pl:=pcint(@textrec(f).userdata[2]);
  749. { avoid alignment error on sparc }
  750. move(pid,pl^,sizeof(pid));
  751. textrec(f).closefunc:=@PCloseText;
  752. end;
  753. POpen:=0;
  754. end;
  755. Function POpen(var F:file;const Prog:Ansistring;rw:char):cint;
  756. {
  757. Starts the program in 'Prog' and makes it's input or out put the
  758. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  759. F, will be read from stdin by the program in 'Prog'. The inverse is true
  760. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  761. read from 'f'.
  762. }
  763. var
  764. pipi,
  765. pipo : file;
  766. pid : cint;
  767. pl : ^cint;
  768. {$if not defined(FPC_USE_FPEXEC) or defined(USE_VFORK)}
  769. pp : array[0..3] of pchar;
  770. temp : string[255];
  771. {$endif not FPC_USE_FPEXEC or USE_VFORK}
  772. ret : cint;
  773. begin
  774. rw:=upcase(rw);
  775. if not (rw in ['R','W']) then
  776. begin
  777. FpSetErrno(ESysEnoent);
  778. exit(-1);
  779. end;
  780. ret:=AssignPipe(pipi,pipo);
  781. if ret=-1 then
  782. exit(-1);
  783. {$ifdef USE_VFORK}
  784. pid:=fpvfork;
  785. {$else USE_VFORK}
  786. pid:=fpfork;
  787. {$endif USE_VFORK}
  788. if pid=-1 then
  789. begin
  790. close(pipi);
  791. close(pipo);
  792. exit(-1);
  793. end;
  794. if pid=0 then
  795. begin
  796. { We're in the child }
  797. if rw='W' then
  798. begin
  799. if (filerec(pipi).handle <> stdinputhandle) then
  800. begin
  801. ret:=fpdup2(filerec(pipi).handle,stdinputhandle);
  802. {$ifdef USE_VFORK}
  803. fpclose(filerec(pipi).handle);
  804. {$else USE_VFORK}
  805. close(pipi);
  806. {$endif USE_VFORK}
  807. end;
  808. {$ifdef USE_VFORK}
  809. fpclose(filerec(pipo).handle);
  810. {$else USE_VFORK}
  811. close(pipo);
  812. {$endif USE_VFORK}
  813. if ret=-1 then
  814. fpexit(127);
  815. end
  816. else
  817. begin
  818. {$ifdef USE_VFORK}
  819. fpclose(filerec(pipi).handle);
  820. {$else USE_VFORK}
  821. close(pipi);
  822. {$endif USE_VFORK}
  823. if (filerec(pipo).handle <> stdoutputhandle) then
  824. begin
  825. ret:=fpdup2(filerec(pipo).handle,stdoutputhandle);
  826. {$ifdef USE_VFORK}
  827. fpclose(filerec(pipo).handle);
  828. {$else USE_VFORK}
  829. close(pipo);
  830. {$endif USE_VFORK}
  831. end;
  832. if ret=-1 then
  833. fpexit(127);
  834. end;
  835. {$if defined(FPC_USE_FPEXEC) and not defined(USE_VFORK)}
  836. fpexecl(pchar('/bin/sh'),['-c',Prog]);
  837. {$else}
  838. temp:='/bin/sh'#0'-c'#0;
  839. pp[0]:=@temp[1];
  840. pp[1]:=@temp[9];
  841. pp[2]:=@prog[1];
  842. pp[3]:=Nil;
  843. fpExecve('/bin/sh',@pp,envp);
  844. {$endif}
  845. fpexit(127);
  846. end
  847. else
  848. begin
  849. { We're in the parent }
  850. if rw='W' then
  851. begin
  852. close(pipi);
  853. f:=pipo;
  854. end
  855. else
  856. begin
  857. close(pipo);
  858. f:=pipi;
  859. end;
  860. {Save the process ID - needed when closing }
  861. pl:=pcint(@filerec(f).userdata[2]);
  862. { avoid alignment error on sparc }
  863. move(pid,pl^,sizeof(pid));
  864. end;
  865. POpen:=0;
  866. end;
  867. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:ansiString;const args : array of ansistring) : cint;
  868. {
  869. Starts the program in 'Prog' and makes its input and output the
  870. other end of two pipes, which are the stdin and stdout of a program
  871. specified in 'Prog'.
  872. streamout can be used to write to the program, streamin can be used to read
  873. the output of the program. See the following diagram :
  874. Parent Child
  875. STreamout --> Input
  876. Streamin <-- Output
  877. Return value is the process ID of the process being spawned, or -1 in case of failure.
  878. }
  879. var
  880. pipi,
  881. pipo : text;
  882. pid : cint;
  883. pl : ^cint;
  884. begin
  885. AssignStream:=-1;
  886. if AssignPipe(streamin,pipo)=-1 Then
  887. exit(-1);
  888. if AssignPipe(pipi,streamout)=-1 Then
  889. begin
  890. close(streamin);
  891. close(pipo);
  892. exit(-1);
  893. end;
  894. pid:=fpfork;
  895. if pid=-1 then
  896. begin
  897. close(pipi);
  898. close(pipo);
  899. close (streamin);
  900. close (streamout);
  901. exit;
  902. end;
  903. if pid=0 then
  904. begin
  905. { We're in the child }
  906. { Close what we don't need }
  907. close(streamout);
  908. close(streamin);
  909. if fpdup2(pipi,input)=-1 Then
  910. halt(127);
  911. close(pipi);
  912. If fpdup2(pipo,output)=-1 Then
  913. halt (127);
  914. close(pipo);
  915. fpExecl(Prog,args);
  916. halt(127);
  917. end
  918. else
  919. begin
  920. { we're in the parent}
  921. close(pipo);
  922. close(pipi);
  923. {Save the process ID - needed when closing }
  924. pl:=pcint(@textrec(StreamIn).userdata[2]);
  925. { avoid alignment error on sparc }
  926. move(pid,pl^,sizeof(pid));
  927. textrec(StreamIn).closefunc:=@PCloseText;
  928. {Save the process ID - needed when closing }
  929. pl:=pcint(@textrec(StreamOut).userdata[2]);
  930. { avoid alignment error on sparc }
  931. move(pid,pl^,sizeof(pid));
  932. textrec(StreamOut).closefunc:=@PCloseText;
  933. AssignStream:=Pid;
  934. end;
  935. end;
  936. Function AssignStream(Var StreamIn,Streamout,streamerr:text;Const Prog:ansiString;const args : array of ansistring) : cint;
  937. {
  938. Starts the program in 'prog' and makes its input, output and error output the
  939. other end of three pipes, which are the stdin, stdout and stderr of a program
  940. specified in 'prog'.
  941. StreamOut can be used to write to the program, StreamIn can be used to read
  942. the output of the program, StreamErr reads the error output of the program.
  943. See the following diagram :
  944. Parent Child
  945. StreamOut --> StdIn (input)
  946. StreamIn <-- StdOut (output)
  947. StreamErr <-- StdErr (error output)
  948. }
  949. var
  950. PipeIn, PipeOut, PipeErr: text;
  951. pid: cint;
  952. pl: ^cint;
  953. begin
  954. AssignStream := -1;
  955. // Assign pipes
  956. if AssignPipe(StreamIn, PipeOut)=-1 Then
  957. Exit(-1);
  958. If AssignPipe(StreamErr, PipeErr)=-1 Then
  959. begin
  960. Close(StreamIn);
  961. Close(PipeOut);
  962. exit(-1);
  963. end;
  964. if AssignPipe(PipeIn, StreamOut)=-1 Then
  965. begin
  966. Close(StreamIn);
  967. Close(PipeOut);
  968. Close(StreamErr);
  969. Close(PipeErr);
  970. exit(-1);
  971. end;
  972. // Fork
  973. pid := fpFork;
  974. if pid=-1 then begin
  975. Close(StreamIn);
  976. Close(PipeOut);
  977. Close(StreamErr);
  978. Close(PipeErr);
  979. Close(PipeIn);
  980. Close(StreamOut);
  981. exit(-1);
  982. end;
  983. if pid = 0 then begin
  984. // *** We are in the child ***
  985. // Close what we don not need
  986. Close(StreamOut);
  987. Close(StreamIn);
  988. Close(StreamErr);
  989. // Connect pipes
  990. if fpdup2(PipeIn, Input)=-1 Then
  991. Halt(127);
  992. Close(PipeIn);
  993. if fpdup2(PipeOut, Output)=-1 Then
  994. Halt(127);
  995. Close(PipeOut);
  996. if fpdup2(PipeErr, StdErr)=-1 Then
  997. Halt(127);
  998. Close(PipeErr);
  999. // Execute program
  1000. fpExecl(Prog,args);
  1001. Halt(127);
  1002. end else begin
  1003. // *** We are in the parent ***
  1004. Close(PipeErr);
  1005. Close(PipeOut);
  1006. Close(PipeIn);
  1007. // Save the process ID - needed when closing
  1008. pl := pcint(@TextRec(StreamIn).userdata[2]);
  1009. { avoid alignment error on sparc }
  1010. move(pid,pl^,sizeof(pid));
  1011. TextRec(StreamIn).closefunc := @PCloseText;
  1012. // Save the process ID - needed when closing
  1013. pl := pcint(@TextRec(StreamOut).userdata[2]);
  1014. { avoid alignment error on sparc }
  1015. move(pid,pl^,sizeof(pid));
  1016. TextRec(StreamOut).closefunc := @PCloseText;
  1017. // Save the process ID - needed when closing
  1018. pl := pcint(@TextRec(StreamErr).userdata[2]);
  1019. { avoid alignment error on sparc }
  1020. move(pid,pl^,sizeof(pid));
  1021. TextRec(StreamErr).closefunc := @PCloseText;
  1022. AssignStream := pid;
  1023. end;
  1024. end;
  1025. {******************************************************************************
  1026. General information calls
  1027. ******************************************************************************}
  1028. {$ifdef Linux}
  1029. Function GetDomainName:String; { linux only!}
  1030. // domainname is a glibc extension.
  1031. {
  1032. Get machines domain name. Returns empty string if not set.
  1033. }
  1034. Var
  1035. Sysn : utsname;
  1036. begin
  1037. If fpUname(sysn)<>0 then
  1038. getdomainname:=''
  1039. else
  1040. getdomainname:=strpas(@Sysn.domain[0]);
  1041. end;
  1042. {$endif}
  1043. {$ifdef sunos}
  1044. { sunos doesn't support GetDomainName, see also
  1045. http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18
  1046. }
  1047. Function GetDomainName:String;
  1048. begin
  1049. GetDomainName:='';
  1050. end;
  1051. {$endif sunos}
  1052. {$ifdef BSD}
  1053. function intGetDomainName(Name:PChar; NameLen:Cint):cint;
  1054. {$ifndef FPC_USE_LIBC}
  1055. external name 'FPC_SYSC_GETDOMAINNAME';
  1056. {$else FPC_USE_LIBC}
  1057. cdecl; external clib name 'getdomainname';
  1058. {$endif FPC_USE_LIBC}
  1059. Function GetDomainName:String; { linux only!}
  1060. // domainname is a glibc extension.
  1061. {
  1062. Get machines domain name. Returns empty string if not set.
  1063. }
  1064. begin
  1065. if intGetDomainName(@getdomainname[1],255)=-1 then
  1066. getdomainname:=''
  1067. else
  1068. getdomainname[0]:=chr(strlen(@getdomainname[1]));
  1069. end;
  1070. {$endif}
  1071. Function GetHostName:String;
  1072. {
  1073. Get machines name. Returns empty string if not set.
  1074. }
  1075. Var
  1076. Sysn : utsname;
  1077. begin
  1078. If fpuname(sysn)=-1 then
  1079. gethostname:=''
  1080. else
  1081. gethostname:=strpas(@Sysn.nodename[0]);
  1082. end;
  1083. {******************************************************************************
  1084. Signal handling calls
  1085. ******************************************************************************}
  1086. procedure SigRaise(sig:integer);
  1087. begin
  1088. fpKill(fpGetPid,Sig);
  1089. end;
  1090. {******************************************************************************
  1091. Utility calls
  1092. ******************************************************************************}
  1093. Function FSearch(const path:AnsiString;dirlist:Ansistring;CurrentDirStrategy:TFSearchOption):AnsiString;
  1094. {
  1095. Searches for a file 'path' in the list of direcories in 'dirlist'.
  1096. returns an empty string if not found. Wildcards are NOT allowed.
  1097. If dirlist is empty, it is set to '.'
  1098. This function tries to make FSearch use ansistrings, and decrease
  1099. stringhandling overhead at the same time.
  1100. }
  1101. Var
  1102. mydir,NewDir : ansistring;
  1103. p1 : cint;
  1104. Info : Stat;
  1105. i,j : cint;
  1106. p : pchar;
  1107. Begin
  1108. if CurrentDirStrategy=CurrentDirectoryFirst Then
  1109. Dirlist:='.:'+dirlist; {Make sure current dir is first to be searched.}
  1110. if CurrentDirStrategy=CurrentDirectoryLast Then
  1111. Dirlist:=dirlist+':.'; {Make sure current dir is last to be searched.}
  1112. {Replace ':' and ';' with #0}
  1113. for p1:=1 to length(dirlist) do
  1114. if (dirlist[p1]=':') or (dirlist[p1]=';') then
  1115. dirlist[p1]:=#0;
  1116. {Check for WildCards}
  1117. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  1118. FSearch:='' {No wildcards allowed in these things.}
  1119. Else
  1120. Begin
  1121. p:=pchar(dirlist);
  1122. i:=length(dirlist);
  1123. j:=1;
  1124. Repeat
  1125. mydir:=ansistring(p);
  1126. if (length(mydir)>0) and (mydir[length(mydir)]<>'/') then
  1127. mydir:=mydir+'/';
  1128. NewDir:=mydir+Path;
  1129. if (FpStat(NewDir,Info)>=0) and
  1130. (not fpS_ISDIR(Info.st_Mode)) then
  1131. Begin
  1132. If Pos('./',NewDir)=1 Then
  1133. Delete(NewDir,1,2);
  1134. {DOS strips off an initial .\}
  1135. End
  1136. Else
  1137. NewDir:='';
  1138. while (j<=i) and (p^<>#0) do begin inc(j); inc(p); end;
  1139. if p^=#0 then inc(p);
  1140. Until (j>=i) or (Length(NewDir) > 0);
  1141. FSearch:=NewDir;
  1142. End;
  1143. End;
  1144. Function FSearch(const path:AnsiString;dirlist:Ansistring):AnsiString;
  1145. Begin
  1146. FSearch:=FSearch(path,dirlist,CurrentDirectoryFirst);
  1147. End;
  1148. {--------------------------------
  1149. Stat.Mode Macro's
  1150. --------------------------------}
  1151. Initialization
  1152. {$IFNDEF DONT_READ_TIMEZONE}
  1153. InitLocalTime;
  1154. {$endif}
  1155. finalization
  1156. {$IFNDEF DONT_READ_TIMEZONE}
  1157. DoneLocalTime;
  1158. {$endif}
  1159. End.