unix.pp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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:=@(textrec(f).userdata[2]);
  749. pl^:=pid;
  750. textrec(f).closefunc:=@PCloseText;
  751. end;
  752. POpen:=0;
  753. end;
  754. Function POpen(var F:file;const Prog:Ansistring;rw:char):cint;
  755. {
  756. Starts the program in 'Prog' and makes it's input or out put the
  757. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  758. F, will be read from stdin by the program in 'Prog'. The inverse is true
  759. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  760. read from 'f'.
  761. }
  762. var
  763. pipi,
  764. pipo : file;
  765. pid : cint;
  766. pl : ^cint;
  767. {$if not defined(FPC_USE_FPEXEC) or defined(USE_VFORK)}
  768. pp : array[0..3] of pchar;
  769. temp : string[255];
  770. {$endif not FPC_USE_FPEXEC or USE_VFORK}
  771. ret : cint;
  772. begin
  773. rw:=upcase(rw);
  774. if not (rw in ['R','W']) then
  775. begin
  776. FpSetErrno(ESysEnoent);
  777. exit(-1);
  778. end;
  779. ret:=AssignPipe(pipi,pipo);
  780. if ret=-1 then
  781. exit(-1);
  782. {$ifdef USE_VFORK}
  783. pid:=fpvfork;
  784. {$else USE_VFORK}
  785. pid:=fpfork;
  786. {$endif USE_VFORK}
  787. if pid=-1 then
  788. begin
  789. close(pipi);
  790. close(pipo);
  791. exit(-1);
  792. end;
  793. if pid=0 then
  794. begin
  795. { We're in the child }
  796. if rw='W' then
  797. begin
  798. if (filerec(pipi).handle <> stdinputhandle) then
  799. begin
  800. ret:=fpdup2(filerec(pipi).handle,stdinputhandle);
  801. {$ifdef USE_VFORK}
  802. fpclose(filerec(pipi).handle);
  803. {$else USE_VFORK}
  804. close(pipi);
  805. {$endif USE_VFORK}
  806. end;
  807. {$ifdef USE_VFORK}
  808. fpclose(filerec(pipo).handle);
  809. {$else USE_VFORK}
  810. close(pipo);
  811. {$endif USE_VFORK}
  812. if ret=-1 then
  813. fpexit(127);
  814. end
  815. else
  816. begin
  817. {$ifdef USE_VFORK}
  818. fpclose(filerec(pipi).handle);
  819. {$else USE_VFORK}
  820. close(pipi);
  821. {$endif USE_VFORK}
  822. if (filerec(pipo).handle <> stdoutputhandle) then
  823. begin
  824. ret:=fpdup2(filerec(pipo).handle,stdoutputhandle);
  825. {$ifdef USE_VFORK}
  826. fpclose(filerec(pipo).handle);
  827. {$else USE_VFORK}
  828. close(pipo);
  829. {$endif USE_VFORK}
  830. end;
  831. if ret=1 then
  832. fpexit(127);
  833. end;
  834. {$if defined(FPC_USE_FPEXEC) and not defined(USE_VFORK)}
  835. fpexecl(pchar('/bin/sh'),['-c',Prog]);
  836. {$else}
  837. temp:='/bin/sh'#0'-c'#0;
  838. pp[0]:=@temp[1];
  839. pp[1]:=@temp[9];
  840. pp[2]:=@prog[1];
  841. pp[3]:=Nil;
  842. fpExecve('/bin/sh',@pp,envp);
  843. {$endif}
  844. fpexit(127);
  845. end
  846. else
  847. begin
  848. { We're in the parent }
  849. if rw='W' then
  850. begin
  851. close(pipi);
  852. f:=pipo;
  853. end
  854. else
  855. begin
  856. close(pipo);
  857. f:=pipi;
  858. end;
  859. {Save the process ID - needed when closing }
  860. pl:=@(filerec(f).userdata[2]);
  861. pl^:=pid;
  862. end;
  863. POpen:=0;
  864. end;
  865. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:ansiString;const args : array of ansistring) : cint;
  866. {
  867. Starts the program in 'Prog' and makes its input and output the
  868. other end of two pipes, which are the stdin and stdout of a program
  869. specified in 'Prog'.
  870. streamout can be used to write to the program, streamin can be used to read
  871. the output of the program. See the following diagram :
  872. Parent Child
  873. STreamout --> Input
  874. Streamin <-- Output
  875. Return value is the process ID of the process being spawned, or -1 in case of failure.
  876. }
  877. var
  878. pipi,
  879. pipo : text;
  880. pid : cint;
  881. pl : ^cint;
  882. begin
  883. AssignStream:=-1;
  884. if AssignPipe(streamin,pipo)=-1 Then
  885. exit(-1);
  886. if AssignPipe(pipi,streamout)=-1 Then
  887. begin
  888. close(streamin);
  889. close(pipo);
  890. exit(-1);
  891. end;
  892. pid:=fpfork;
  893. if pid=-1 then
  894. begin
  895. close(pipi);
  896. close(pipo);
  897. close (streamin);
  898. close (streamout);
  899. exit;
  900. end;
  901. if pid=0 then
  902. begin
  903. { We're in the child }
  904. { Close what we don't need }
  905. close(streamout);
  906. close(streamin);
  907. if fpdup2(pipi,input)=-1 Then
  908. halt(127);
  909. close(pipi);
  910. If fpdup2(pipo,output)=-1 Then
  911. halt (127);
  912. close(pipo);
  913. fpExecl(Prog,args);
  914. halt(127);
  915. end
  916. else
  917. begin
  918. { we're in the parent}
  919. close(pipo);
  920. close(pipi);
  921. {Save the process ID - needed when closing }
  922. pl:=@(textrec(StreamIn).userdata[2]);
  923. pl^:=pid;
  924. textrec(StreamIn).closefunc:=@PCloseText;
  925. {Save the process ID - needed when closing }
  926. pl:=@(textrec(StreamOut).userdata[2]);
  927. pl^:=pid;
  928. textrec(StreamOut).closefunc:=@PCloseText;
  929. AssignStream:=Pid;
  930. end;
  931. end;
  932. Function AssignStream(Var StreamIn,Streamout,streamerr:text;Const Prog:ansiString;const args : array of ansistring) : cint;
  933. {
  934. Starts the program in 'prog' and makes its input, output and error output the
  935. other end of three pipes, which are the stdin, stdout and stderr of a program
  936. specified in 'prog'.
  937. StreamOut can be used to write to the program, StreamIn can be used to read
  938. the output of the program, StreamErr reads the error output of the program.
  939. See the following diagram :
  940. Parent Child
  941. StreamOut --> StdIn (input)
  942. StreamIn <-- StdOut (output)
  943. StreamErr <-- StdErr (error output)
  944. }
  945. var
  946. PipeIn, PipeOut, PipeErr: text;
  947. pid: cint;
  948. pl: ^cint;
  949. begin
  950. AssignStream := -1;
  951. // Assign pipes
  952. if AssignPipe(StreamIn, PipeOut)=-1 Then
  953. Exit(-1);
  954. If AssignPipe(StreamErr, PipeErr)=-1 Then
  955. begin
  956. Close(StreamIn);
  957. Close(PipeOut);
  958. exit(-1);
  959. end;
  960. if AssignPipe(PipeIn, StreamOut)=-1 Then
  961. begin
  962. Close(StreamIn);
  963. Close(PipeOut);
  964. Close(StreamErr);
  965. Close(PipeErr);
  966. exit(-1);
  967. end;
  968. // Fork
  969. pid := fpFork;
  970. if pid=-1 then begin
  971. Close(StreamIn);
  972. Close(PipeOut);
  973. Close(StreamErr);
  974. Close(PipeErr);
  975. Close(PipeIn);
  976. Close(StreamOut);
  977. exit(-1);
  978. end;
  979. if pid = 0 then begin
  980. // *** We are in the child ***
  981. // Close what we don not need
  982. Close(StreamOut);
  983. Close(StreamIn);
  984. Close(StreamErr);
  985. // Connect pipes
  986. if fpdup2(PipeIn, Input)=-1 Then
  987. Halt(127);
  988. Close(PipeIn);
  989. if fpdup2(PipeOut, Output)=-1 Then
  990. Halt(127);
  991. Close(PipeOut);
  992. if fpdup2(PipeErr, StdErr)=-1 Then
  993. Halt(127);
  994. Close(PipeErr);
  995. // Execute program
  996. fpExecl(Prog,args);
  997. Halt(127);
  998. end else begin
  999. // *** We are in the parent ***
  1000. Close(PipeErr);
  1001. Close(PipeOut);
  1002. Close(PipeIn);
  1003. // Save the process ID - needed when closing
  1004. pl := @(TextRec(StreamIn).userdata[2]);
  1005. pl^ := pid;
  1006. TextRec(StreamIn).closefunc := @PCloseText;
  1007. // Save the process ID - needed when closing
  1008. pl := @(TextRec(StreamOut).userdata[2]);
  1009. pl^ := pid;
  1010. TextRec(StreamOut).closefunc := @PCloseText;
  1011. // Save the process ID - needed when closing
  1012. pl := @(TextRec(StreamErr).userdata[2]);
  1013. pl^ := pid;
  1014. TextRec(StreamErr).closefunc := @PCloseText;
  1015. AssignStream := pid;
  1016. end;
  1017. end;
  1018. {******************************************************************************
  1019. General information calls
  1020. ******************************************************************************}
  1021. {$ifdef Linux}
  1022. Function GetDomainName:String; { linux only!}
  1023. // domainname is a glibc extension.
  1024. {
  1025. Get machines domain name. Returns empty string if not set.
  1026. }
  1027. Var
  1028. Sysn : utsname;
  1029. begin
  1030. If fpUname(sysn)<>0 then
  1031. getdomainname:=''
  1032. else
  1033. getdomainname:=strpas(@Sysn.domain[0]);
  1034. end;
  1035. {$endif}
  1036. {$ifdef sunos}
  1037. { sunos doesn't support GetDomainName, see also
  1038. http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18
  1039. }
  1040. Function GetDomainName:String;
  1041. begin
  1042. GetDomainName:='';
  1043. end;
  1044. {$endif sunos}
  1045. {$ifdef BSD}
  1046. function intGetDomainName(Name:PChar; NameLen:Cint):cint;
  1047. {$ifndef FPC_USE_LIBC}
  1048. external name 'FPC_SYSC_GETDOMAINNAME';
  1049. {$else FPC_USE_LIBC}
  1050. cdecl; external clib name 'getdomainname';
  1051. {$endif FPC_USE_LIBC}
  1052. Function GetDomainName:String; { linux only!}
  1053. // domainname is a glibc extension.
  1054. {
  1055. Get machines domain name. Returns empty string if not set.
  1056. }
  1057. begin
  1058. if intGetDomainName(@getdomainname[1],255)=-1 then
  1059. getdomainname:=''
  1060. else
  1061. getdomainname[0]:=chr(strlen(@getdomainname[1]));
  1062. end;
  1063. {$endif}
  1064. Function GetHostName:String;
  1065. {
  1066. Get machines name. Returns empty string if not set.
  1067. }
  1068. Var
  1069. Sysn : utsname;
  1070. begin
  1071. If fpuname(sysn)=-1 then
  1072. gethostname:=''
  1073. else
  1074. gethostname:=strpas(@Sysn.nodename[0]);
  1075. end;
  1076. {******************************************************************************
  1077. Signal handling calls
  1078. ******************************************************************************}
  1079. procedure SigRaise(sig:integer);
  1080. begin
  1081. fpKill(fpGetPid,Sig);
  1082. end;
  1083. {******************************************************************************
  1084. Utility calls
  1085. ******************************************************************************}
  1086. Function FSearch(const path:AnsiString;dirlist:Ansistring;CurrentDirStrategy:TFSearchOption):AnsiString;
  1087. {
  1088. Searches for a file 'path' in the list of direcories in 'dirlist'.
  1089. returns an empty string if not found. Wildcards are NOT allowed.
  1090. If dirlist is empty, it is set to '.'
  1091. This function tries to make FSearch use ansistrings, and decrease
  1092. stringhandling overhead at the same time.
  1093. }
  1094. Var
  1095. mydir,NewDir : ansistring;
  1096. p1 : cint;
  1097. Info : Stat;
  1098. i,j : cint;
  1099. p : pchar;
  1100. Begin
  1101. if CurrentDirStrategy=CurrentDirectoryFirst Then
  1102. Dirlist:='.:'+dirlist; {Make sure current dir is first to be searched.}
  1103. if CurrentDirStrategy=CurrentDirectoryLast Then
  1104. Dirlist:=dirlist+':.'; {Make sure current dir is last to be searched.}
  1105. {Replace ':' and ';' with #0}
  1106. for p1:=1 to length(dirlist) do
  1107. if (dirlist[p1]=':') or (dirlist[p1]=';') then
  1108. dirlist[p1]:=#0;
  1109. {Check for WildCards}
  1110. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  1111. FSearch:='' {No wildcards allowed in these things.}
  1112. Else
  1113. Begin
  1114. p:=pchar(dirlist);
  1115. i:=length(dirlist);
  1116. j:=1;
  1117. Repeat
  1118. mydir:=ansistring(p);
  1119. if (length(mydir)>0) and (mydir[length(mydir)]<>'/') then
  1120. mydir:=mydir+'/';
  1121. NewDir:=mydir+Path;
  1122. if (FpStat(NewDir,Info)>=0) and
  1123. (not fpS_ISDIR(Info.st_Mode)) then
  1124. Begin
  1125. If Pos('./',NewDir)=1 Then
  1126. Delete(NewDir,1,2);
  1127. {DOS strips off an initial .\}
  1128. End
  1129. Else
  1130. NewDir:='';
  1131. while (j<=i) and (p^<>#0) do begin inc(j); inc(p); end;
  1132. if p^=#0 then inc(p);
  1133. Until (j>=i) or (Length(NewDir) > 0);
  1134. FSearch:=NewDir;
  1135. End;
  1136. End;
  1137. Function FSearch(const path:AnsiString;dirlist:Ansistring):AnsiString;
  1138. Begin
  1139. FSearch:=FSearch(path,dirlist,CurrentDirectoryFirst);
  1140. End;
  1141. {--------------------------------
  1142. Stat.Mode Macro's
  1143. --------------------------------}
  1144. Initialization
  1145. {$IFNDEF DONT_READ_TIMEZONE}
  1146. InitLocalTime;
  1147. {$endif}
  1148. finalization
  1149. {$IFNDEF DONT_READ_TIMEZONE}
  1150. DoneLocalTime;
  1151. {$endif}
  1152. End.