unix.pp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. BSD parts (c) 2000 by Marco van de Voort
  6. members of the Free Pascal development team.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY;without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. Unit Unix;
  14. Interface
  15. Uses UnixUtil,BaseUnix;
  16. { Get Types and Constants }
  17. {$i sysconst.inc}
  18. {$i systypes.inc}
  19. {Get error numbers, some more signal definitions and other OS dependant
  20. types (that are not POSIX) }
  21. {i errno.inc}
  22. {$I signal.inc}
  23. {$i ostypes.inc}
  24. {********************
  25. File
  26. ********************}
  27. Const
  28. P_IN = 1; // pipes (?)
  29. P_OUT = 2;
  30. Const
  31. LOCK_SH = 1; // flock constants ?
  32. LOCK_EX = 2;
  33. LOCK_UN = 8;
  34. LOCK_NB = 4;
  35. Type
  36. Tpipe = array[1..2] of cint;
  37. pglob = ^tglob;
  38. tglob = record
  39. name : pchar;
  40. next : pglob;
  41. end;
  42. {******************************************************************************
  43. Procedure/Functions
  44. ******************************************************************************}
  45. {**************************
  46. Time/Date Handling
  47. ***************************}
  48. var
  49. tzdaylight : boolean;
  50. tzname : array[boolean] of pchar;
  51. { timezone support }
  52. procedure GetLocalTimezone(timer:cint;var leap_correct,leap_hit:cint);
  53. procedure GetLocalTimezone(timer:cint);
  54. procedure ReadTimezoneFile(fn:string);
  55. function GetTimezoneFile:string;
  56. Function GetEpochTime: cint;
  57. procedure GetTime (var hour,min,sec,msec,usec:word);
  58. procedure GetTime (var hour,min,sec,sec100:word);
  59. procedure GetTime (var hour,min,sec:word);
  60. Procedure GetDate (Var Year,Month,Day:Word);
  61. Procedure GetDateTime (Var Year,Month,Day,hour,minute,second:Word);
  62. function SetTime (Hour,Min,Sec:word) : Boolean;
  63. function SetDate (Year,Month,Day:Word) : Boolean;
  64. function SetDateTime (Year,Month,Day,hour,minute,second:Word) : Boolean;
  65. {**************************
  66. Process Handling
  67. ***************************}
  68. function CreateShellArgV (const prog:string):ppchar;
  69. function CreateShellArgV (const prog:Ansistring):ppchar;
  70. Function Execv (const path:pathstr;args:ppchar):cint;
  71. Function Execv (const path: AnsiString;args:ppchar):cint;
  72. Function Execvp (Path: Pathstr;Args:ppchar;Ep:ppchar):cint;
  73. Function Execvp (Path: AnsiString; Args:ppchar;Ep:ppchar):cint;
  74. Function Execl (const Todo: String):cint;
  75. Function Execl (const Todo: Ansistring):cint;
  76. Function Execle (Todo: String;Ep:ppchar):cint;
  77. Function Execle (Todo: AnsiString;Ep:ppchar):cint;
  78. Function Execlp (Todo: string;Ep:ppchar):cint;
  79. Function Execlp (Todo: Ansistring;Ep:ppchar):cint;
  80. Function Shell (const Command:String):cint;
  81. Function Shell (const Command:AnsiString):cint;
  82. 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}
  83. Function WIFSTOPPED (Status: Integer): Boolean;
  84. Function W_EXITCODE (ReturnCode, Signal: Integer): Integer;
  85. Function W_STOPCODE (Signal: Integer): Integer;
  86. {**************************
  87. File Handling
  88. ***************************}
  89. {$ifndef FPC_USE_LIBC} // defined using cdecl for libc.
  90. Function fsync (fd : cint) : cint;
  91. Function Flock (fd,mode : cint) : cint ;
  92. //Function StatFS (Path:Pathstr;Var Info:tstatfs):cint; -> to ovlh.inc
  93. Function fStatFS (Fd: cint;Var Info:tstatfs):cint;
  94. {$endif}
  95. Function Flock (var T : text;mode : cint) : cint;
  96. Function Flock (var F : File;mode : cint) : cint;
  97. Function SelectText (var T:Text;TimeOut :PTimeVal):cint;
  98. Function SelectText (var T:Text;TimeOut :cint):cint;
  99. {**************************
  100. Directory Handling
  101. ***************************}
  102. procedure SeekDir(p:pdir;loc:clong);
  103. function TellDir(p:pdir):clong;
  104. {**************************
  105. Pipe/Fifo/Stream
  106. ***************************}
  107. Function AssignPipe (var pipe_in,pipe_out:cint):cint;
  108. Function AssignPipe (var pipe_in,pipe_out:text):cint;
  109. Function AssignPipe (var pipe_in,pipe_out:file):cint;
  110. //Function PClose (Var F:text) : cint;
  111. //Function PClose (Var F:file) : cint;
  112. Function POpen (var F:text;const Prog:String;rw:char):cint;
  113. Function POpen (var F:file;const Prog:String;rw:char):cint;
  114. function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : cint;
  115. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): cint;
  116. {$ifndef BSD}
  117. Function GetDomainName:String;
  118. Function GetHostName:String;
  119. {$endif}
  120. {**************************
  121. Memory functions
  122. ***************************}
  123. const
  124. PROT_READ = $1; { page can be read }
  125. PROT_WRITE = $2; { page can be written }
  126. PROT_EXEC = $4; { page can be executed }
  127. PROT_NONE = $0; { page can not be accessed }
  128. MAP_SHARED = $1; { Share changes }
  129. // MAP_PRIVATE = $2; { Changes are private }
  130. MAP_TYPE = $f; { Mask for type of mapping }
  131. MAP_FIXED = $10; { Interpret addr exactly }
  132. // MAP_ANONYMOUS = $20; { don't use a file }
  133. MAP_GROWSDOWN = $100; { stack-like segment }
  134. MAP_DENYWRITE = $800; { ETXTBSY }
  135. MAP_EXECUTABLE = $1000; { mark it as an executable }
  136. MAP_LOCKED = $2000; { pages are locked }
  137. MAP_NORESERVE = $4000; { don't check for reservations }
  138. {**************************
  139. Utility functions
  140. ***************************}
  141. Function FExpand (Const Path: PathStr):PathStr;
  142. Function FSearch (const path:pathstr;dirlist:string):pathstr;
  143. Function Glob (Const path:pathstr):pglob;
  144. Procedure Globfree (var p:pglob);
  145. procedure SigRaise (sig:integer);
  146. {$ifdef FPC_USE_LIBC}
  147. {$i unxdeclh.inc}
  148. {$else}
  149. {$i unxsysch.inc} // calls used in system and not reexported from baseunix
  150. {$endif}
  151. {******************************************************************************
  152. Implementation
  153. ******************************************************************************}
  154. {$i unxovlh.inc}
  155. Implementation
  156. Uses Strings{$ifndef FPC_USE_LIBC},Syscall{$endif};
  157. {$i unxovl.inc}
  158. {$ifndef FPC_USE_LIBC}
  159. {$i syscallh.inc}
  160. {$i ossysch.inc}
  161. {$i unxsysc.inc}
  162. {$endif}
  163. { Get the definitions of textrec and filerec }
  164. {$i textrec.inc}
  165. {$i filerec.inc}
  166. {$ifndef FPC_USE_LIBC}
  167. { Raw System calls are in Syscalls.inc}
  168. {$ifdef Linux} // Linux has more "oldlinux" compability.
  169. {$i sysc11.inc}
  170. {$else}
  171. {$i syscalls.inc}
  172. {$endif}
  173. {$endif}
  174. {$i unixsysc.inc} {Has platform specific libc part under ifdef, besides
  175. syscalls}
  176. Function getenv(name:string):Pchar; external name 'FPC_SYSC_FPGETENV';
  177. {******************************************************************************
  178. Process related calls
  179. ******************************************************************************}
  180. { Most calls of WaitPID do not handle the result correctly, this funktion treats errors more correctly }
  181. 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}
  182. var ret,r,s : cint;
  183. begin
  184. s:=$7F00;
  185. repeat
  186. r:=fpWaitPid(Pid,@s,0);
  187. if (r=-1) and (fpgeterrno=ESysEIntr) Then
  188. r:=0;
  189. until (r<>-1);
  190. if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
  191. WaitProcess:=-1 // return -1 to indicate an error. fpwaitpid updated it.
  192. else
  193. begin
  194. {$ifndef Solaris}
  195. { at least correct for Linux and Darwin (JM) }
  196. if (s and $7F)=0 then // Only this is a valid returncode
  197. {$else}
  198. if (s and $FF)=0 then // Only this is a valid returncode
  199. {$endif}
  200. WaitProcess:=s shr 8
  201. else if (s>0) then // Until now there is not use of the highest bit , but check this for the future
  202. WaitProcess:=-s // normal case
  203. else
  204. WaitProcess:=s; // s<0 should not occur, but wie return also a negativ value
  205. end;
  206. end;
  207. function InternalCreateShellArgV(cmd:pChar; len:cint):ppchar;
  208. {
  209. Create an argv which executes a command in a shell using /bin/sh -c
  210. }
  211. const Shell = '/bin/sh'#0'-c'#0;
  212. var
  213. pp,p : ppchar;
  214. // temp : string; !! Never pass a local var back!!
  215. begin
  216. getmem(pp,4*4);
  217. p:=pp;
  218. p^:=@Shell[1];
  219. inc(p);
  220. p^:=@Shell[9];
  221. inc(p);
  222. getmem(p^,len+1);
  223. move(cmd^,p^^,len);
  224. pchar(p^)[len]:=#0;
  225. inc(p);
  226. p^:=Nil;
  227. InternalCreateShellArgV:=pp;
  228. end;
  229. function CreateShellArgV(const prog:string):ppchar;
  230. begin
  231. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
  232. end;
  233. function CreateShellArgV(const prog:Ansistring):ppchar;
  234. {
  235. Create an argv which executes a command in a shell using /bin/sh -c
  236. using a AnsiString;
  237. }
  238. begin
  239. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog)); // if ppc works like delphi this also work when @prog[1] is invalid (len=0)
  240. end;
  241. procedure FreeShellArgV(p:ppchar);
  242. begin
  243. if (p<>nil) then begin
  244. freemem(p[2]);
  245. freemem(p);
  246. end;
  247. end;
  248. Function Execv(const path: AnsiString;args:ppchar):cint;
  249. {
  250. Overloaded ansistring version.
  251. }
  252. begin
  253. Execv:=fpExecVe(Path,Args,envp);
  254. end;
  255. Function Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar):cint;
  256. {
  257. Overloaded ansistring version
  258. }
  259. var
  260. thepath : Ansistring;
  261. begin
  262. if path[1]<>'/' then
  263. begin
  264. Thepath:=strpas(fpgetenv('PATH'));
  265. if thepath='' then
  266. thepath:='.';
  267. Path:=FSearch(path,thepath)
  268. end
  269. else
  270. Path:='';
  271. if Path='' then
  272. Begin
  273. fpsetErrno(ESysEnoEnt);
  274. Exit(-1);
  275. end
  276. else
  277. Execvp:=fpExecve(Path,args,ep);
  278. end;
  279. Function Execv(const path:pathstr;args:ppchar):cint;
  280. {
  281. Replaces the current program by the program specified in path,
  282. arguments in args are passed to Execve.
  283. the current environment is passed on.
  284. }
  285. begin
  286. Execv:=fpExecve(path,args,envp);
  287. end;
  288. Function Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar):cint;
  289. {
  290. This does the same as Execve, only it searches the PATH environment
  291. for the place of the Executable, except when Path starts with a slash.
  292. if the PATH environment variable is unavailable, the path is set to '.'
  293. }
  294. var
  295. thepath : string;
  296. begin
  297. if path[1]<>'/' then
  298. begin
  299. Thepath:=strpas(fpgetenv('PATH'));
  300. if thepath='' then
  301. thepath:='.';
  302. Path:=FSearch(path,thepath)
  303. end
  304. else
  305. Path:='';
  306. if Path='' then
  307. Begin
  308. fpsetErrno(ESysEnoEnt);
  309. Exit(-1);
  310. end
  311. else
  312. execvp:=fpExecve(Path,args,ep);
  313. end;
  314. Function Execle(Todo:string;Ep:ppchar):cint;
  315. {
  316. This procedure takes the string 'Todo', parses it for command and
  317. command options, and Executes the command with the given options.
  318. The string 'Todo' shoud be of the form 'command options', options
  319. separated by commas.
  320. the PATH environment is not searched for 'command'.
  321. The specified environment(in 'ep') is passed on to command
  322. }
  323. var
  324. p : ppchar;
  325. begin
  326. p:=StringToPPChar(ToDo);
  327. if (p=nil) or (p^=nil) then
  328. Begin
  329. fpsetErrno(ESysEnoEnt);
  330. Exit(-1);
  331. end
  332. else
  333. execle:=fpExecVE(p^,p,EP);
  334. end;
  335. function Execle(Todo:AnsiString;Ep:ppchar):cint;
  336. {
  337. This procedure takes the string 'Todo', parses it for command and
  338. command options, and Executes the command with the given options.
  339. The string 'Todo' shoud be of the form 'command options', options
  340. separated by commas.
  341. the PATH environment is not searched for 'command'.
  342. The specified environment(in 'ep') is passed on to command
  343. }
  344. var
  345. p : ppchar;
  346. begin
  347. p:=StringToPPChar(ToDo);
  348. if (p=nil) or (p^=nil) then
  349. Begin
  350. fpsetErrno(ESysEnoEnt);
  351. Exit(-1);
  352. end;
  353. ExecLe:=fpExecVE(p^,p,EP);
  354. end;
  355. Function Execl(const Todo:string):cint;
  356. {
  357. This procedure takes the string 'Todo', parses it for command and
  358. command options, and Executes the command with the given options.
  359. The string 'Todo' shoud be of the form 'command options', options
  360. separated by commas.
  361. the PATH environment is not searched for 'command'.
  362. The current environment is passed on to command
  363. }
  364. begin
  365. Execl:=ExecLE(ToDo,EnvP);
  366. end;
  367. Function Execlp(Todo:string;Ep:ppchar):cint;
  368. {
  369. This procedure takes the string 'Todo', parses it for command and
  370. command options, and Executes the command with the given options.
  371. The string 'Todo' shoud be of the form 'command options', options
  372. separated by commas.
  373. the PATH environment is searched for 'command'.
  374. The specified environment (in 'ep') is passed on to command
  375. }
  376. var
  377. p : ppchar;
  378. begin
  379. p:=StringToPPchar(todo);
  380. if (p=nil) or (p^=nil) then
  381. Begin
  382. fpsetErrno(ESysEnoEnt);
  383. Exit(-1);
  384. end;
  385. Execlp:=ExecVP(StrPas(p^),p,EP);
  386. end;
  387. Function Execlp(Todo: Ansistring;Ep:ppchar):cint;
  388. {
  389. Overloaded ansistring version.
  390. }
  391. var
  392. p : ppchar;
  393. begin
  394. p:=StringToPPchar(todo);
  395. if (p=nil) or (p^=nil) then
  396. Begin
  397. fpsetErrno(ESysEnoEnt);
  398. Exit(-1);
  399. end;
  400. execlp:=ExecVP(StrPas(p^),p,EP);
  401. end;
  402. Function Shell(const Command:String):cint;
  403. {
  404. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  405. The current environment is passed to the shell.
  406. It waits for the shell to exit, and returns its exit status.
  407. If the Exec call failed exit status 127 is reported.
  408. }
  409. { Changed the structure:
  410. - the previous version returns an undefinied value if fork fails
  411. - it returns the status of Waitpid instead of the Process returnvalue (see the doc to Shell)
  412. - it uses exit(127) not ExitProc (The Result in pp386: going on Compiling in 2 processes!)
  413. - ShellArgs are now released
  414. - The Old CreateShellArg gives back pointers to a local var
  415. }
  416. var
  417. p : ppchar;
  418. pid : cint;
  419. begin
  420. p:=CreateShellArgv(command);
  421. pid:=fpfork;
  422. if pid=0 then // We are in the Child
  423. begin
  424. {This is the child.}
  425. fpExecve(p^,p,envp);
  426. fpExit(127); // was Exit(127)
  427. end
  428. else if (pid<>-1) then // Successfull started
  429. Shell:=WaitProcess(pid)
  430. else // no success
  431. Shell:=-1; // indicate an error
  432. FreeShellArgV(p);
  433. end;
  434. Function Shell(const Command:AnsiString):cint;
  435. {
  436. AnsiString version of Shell
  437. }
  438. var
  439. p : ppchar;
  440. pid : cint;
  441. begin { Changes as above }
  442. p:=CreateShellArgv(command);
  443. pid:=fpfork;
  444. if pid=0 then // We are in the Child
  445. begin
  446. fpExecve(p^,p,envp);
  447. fpExit(127); // was exit(127)!! We must exit the Process, not the function
  448. end
  449. else if (pid<>-1) then // Successfull started
  450. Shell:=WaitProcess(pid)
  451. else // no success
  452. Shell:=-1;
  453. FreeShellArgV(p);
  454. end;
  455. Function WIFSTOPPED(Status: Integer): Boolean;
  456. begin
  457. WIFSTOPPED:=((Status and $FF)=$7F);
  458. end;
  459. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  460. begin
  461. W_EXITCODE:=(ReturnCode shl 8) or Signal;
  462. end;
  463. Function W_STOPCODE(Signal: Integer): Integer;
  464. begin
  465. W_STOPCODE:=(Signal shl 8) or $7F;
  466. end;
  467. {******************************************************************************
  468. Date and Time related calls
  469. ******************************************************************************}
  470. Function GetEpochTime: cint;
  471. {
  472. Get the number of seconds since 00:00, January 1 1970, GMT
  473. the time NOT corrected any way
  474. }
  475. begin
  476. GetEpochTime:=fptime;
  477. end;
  478. procedure GetTime(var hour,min,sec,msec,usec:word);
  479. {
  480. Gets the current time, adjusted to local time
  481. }
  482. var
  483. year,day,month:Word;
  484. tz:timeval;
  485. begin
  486. fpgettimeofday(@tz,nil);
  487. EpochToLocal(tz.tv_sec,year,month,day,hour,min,sec);
  488. msec:=tz.tv_usec div 1000;
  489. usec:=tz.tv_usec mod 1000;
  490. end;
  491. procedure GetTime(var hour,min,sec,sec100:word);
  492. {
  493. Gets the current time, adjusted to local time
  494. }
  495. var
  496. usec : word;
  497. begin
  498. gettime(hour,min,sec,sec100,usec);
  499. sec100:=sec100 div 10;
  500. end;
  501. Procedure GetTime(Var Hour,Min,Sec:Word);
  502. {
  503. Gets the current time, adjusted to local time
  504. }
  505. var
  506. msec,usec : Word;
  507. Begin
  508. gettime(hour,min,sec,msec,usec);
  509. End;
  510. Procedure GetDate(Var Year,Month,Day:Word);
  511. {
  512. Gets the current date, adjusted to local time
  513. }
  514. var
  515. hour,minute,second : word;
  516. Begin
  517. EpochToLocal(fptime,year,month,day,hour,minute,second);
  518. End;
  519. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  520. {
  521. Gets the current date, adjusted to local time
  522. }
  523. Begin
  524. EpochToLocal(fptime,year,month,day,hour,minute,second);
  525. End;
  526. {$ifndef BSD}
  527. {$ifdef linux}
  528. Function stime (t : cint) : Boolean;
  529. begin
  530. stime:=do_SysCall(Syscall_nr_stime,cint(@t))=0;
  531. end;
  532. {$endif}
  533. {$endif}
  534. {$ifdef BSD}
  535. Function stime (t : cint) : Boolean;
  536. begin
  537. end;
  538. {$endif}
  539. Function SetTime(Hour,Min,Sec:word) : boolean;
  540. var
  541. Year, Month, Day : Word;
  542. begin
  543. GetDate (Year, Month, Day);
  544. SetTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Min, Sec ) );
  545. end;
  546. Function SetDate(Year,Month,Day:Word) : boolean;
  547. var
  548. Hour, Minute, Second, Sec100 : Word;
  549. begin
  550. GetTime ( Hour, Minute, Second, Sec100 );
  551. SetDate:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  552. end;
  553. Function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
  554. begin
  555. SetDateTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  556. end;
  557. { Include timezone handling routines which use /usr/share/timezone info }
  558. {$i timezone.inc}
  559. {******************************************************************************
  560. FileSystem calls
  561. ******************************************************************************}
  562. Function Execl(const Todo:Ansistring):cint;
  563. {
  564. Overloaded AnsiString Version of ExecL.
  565. }
  566. begin
  567. Execl:=ExecLE(ToDo,EnvP);
  568. end;
  569. Function Flock (var T : text;mode : cint) : cint;
  570. begin
  571. Flock:=Flock(TextRec(T).Handle,mode);
  572. end;
  573. Function Flock (var F : File;mode : cint) :cint;
  574. begin
  575. Flock:=Flock(FileRec(F).Handle,mode);
  576. end;
  577. Function SelectText(var T:Text;TimeOut :PTimeval):cint;
  578. Var
  579. F:TfdSet;
  580. begin
  581. if textrec(t).mode=fmclosed then
  582. begin
  583. fpseterrno(ESysEBADF);
  584. exit(-1);
  585. end;
  586. FpFD_ZERO(f);
  587. fpFD_SET(textrec(T).handle,f);
  588. if textrec(T).mode=fminput then
  589. SelectText:=fpselect(textrec(T).handle+1,@f,nil,nil,TimeOut)
  590. else
  591. SelectText:=fpselect(textrec(T).handle+1,nil,@f,nil,TimeOut);
  592. end;
  593. Function SelectText(var T:Text;TimeOut :cint):cint;
  594. var
  595. p : PTimeVal;
  596. tv : TimeVal;
  597. begin
  598. if TimeOut=-1 then
  599. p:=nil
  600. else
  601. begin
  602. tv.tv_Sec:=Timeout div 1000;
  603. tv.tv_Usec:=(Timeout mod 1000)*1000;
  604. p:=@tv;
  605. end;
  606. SelectText:=SelectText(T,p);
  607. end;
  608. {******************************************************************************
  609. Directory
  610. ******************************************************************************}
  611. procedure SeekDir(p:pdir;loc:clong);
  612. begin
  613. if p=nil then
  614. begin
  615. fpseterrno(ESysEBADF);
  616. exit;
  617. end;
  618. {$ifndef bsd}
  619. p^.dd_nextoff:=fplseek(p^.dd_fd,loc,seek_set);
  620. {$endif}
  621. p^.dd_size:=0;
  622. p^.dd_loc:=0;
  623. end;
  624. function TellDir(p:pdir):clong;
  625. begin
  626. if p=nil then
  627. begin
  628. fpseterrno(ESysEBADF);
  629. telldir:=-1;
  630. exit;
  631. end;
  632. telldir:=fplseek(p^.dd_fd,0,seek_cur)
  633. { We could try to use the nextoff field here, but on my 1.2.13
  634. kernel, this gives nothing... This may have to do with
  635. the readdir implementation of libc... I also didn't find any trace of
  636. the field in the kernel code itself, So I suspect it is an artifact of libc.
  637. Michael. }
  638. end;
  639. {******************************************************************************
  640. Pipes/Fifo
  641. ******************************************************************************}
  642. Procedure OpenPipe(var F:Text);
  643. begin
  644. case textrec(f).mode of
  645. fmoutput :
  646. if textrec(f).userdata[1]<>P_OUT then
  647. textrec(f).mode:=fmclosed;
  648. fminput :
  649. if textrec(f).userdata[1]<>P_IN then
  650. textrec(f).mode:=fmclosed;
  651. else
  652. textrec(f).mode:=fmclosed;
  653. end;
  654. end;
  655. Function IOPipe(var F:text):cint;
  656. begin
  657. IOPipe:=0;
  658. case textrec(f).mode of
  659. fmoutput :
  660. begin
  661. { first check if we need something to write, else we may
  662. get a SigPipe when Close() is called (PFV) }
  663. if textrec(f).bufpos>0 then
  664. IOPipe:=fpwrite(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  665. end;
  666. fminput : Begin
  667. textrec(f).bufend:=fpread(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  668. IOPipe:=textrec(f).bufend;
  669. End;
  670. end;
  671. textrec(f).bufpos:=0;
  672. end;
  673. Function FlushPipe(var F:Text):cint;
  674. begin
  675. FlushPipe:=0;
  676. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  677. FlushPipe:=IOPipe(f);
  678. textrec(f).bufpos:=0;
  679. end;
  680. Function ClosePipe(var F:text):cint;
  681. begin
  682. textrec(f).mode:=fmclosed;
  683. ClosePipe:=fpclose(textrec(f).handle);
  684. end;
  685. Function AssignPipe(var pipe_in,pipe_out:text):cint;
  686. {
  687. Sets up a pair of file variables, which act as a pipe. The first one can
  688. be read from, the second one can be written to.
  689. }
  690. var
  691. f_in,f_out : cint;
  692. begin
  693. if AssignPipe(f_in,f_out)=-1 then
  694. exit(-1);
  695. { Set up input }
  696. Assign(Pipe_in,'');
  697. Textrec(Pipe_in).Handle:=f_in;
  698. Textrec(Pipe_in).Mode:=fmInput;
  699. Textrec(Pipe_in).userdata[1]:=P_IN;
  700. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  701. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  702. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  703. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  704. { Set up output }
  705. Assign(Pipe_out,'');
  706. Textrec(Pipe_out).Handle:=f_out;
  707. Textrec(Pipe_out).Mode:=fmOutput;
  708. Textrec(Pipe_out).userdata[1]:=P_OUT;
  709. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  710. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  711. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  712. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  713. AssignPipe:=0;
  714. end;
  715. Function AssignPipe(var pipe_in,pipe_out:file):cint;
  716. {
  717. Sets up a pair of file variables, which act as a pipe. The first one can
  718. be read from, the second one can be written to.
  719. If the operation was unsuccesful,
  720. }
  721. var
  722. f_in,f_out : cint;
  723. begin
  724. if AssignPipe(f_in,f_out)=-1 then
  725. exit(-1);
  726. { Set up input }
  727. Assign(Pipe_in,'');
  728. Filerec(Pipe_in).Handle:=f_in;
  729. Filerec(Pipe_in).Mode:=fmInput;
  730. Filerec(Pipe_in).recsize:=1;
  731. Filerec(Pipe_in).userdata[1]:=P_IN;
  732. { Set up output }
  733. Assign(Pipe_out,'');
  734. Filerec(Pipe_out).Handle:=f_out;
  735. Filerec(Pipe_out).Mode:=fmoutput;
  736. Filerec(Pipe_out).recsize:=1;
  737. Filerec(Pipe_out).userdata[1]:=P_OUT;
  738. AssignPipe:=0;
  739. end;
  740. Function PCloseText(Var F:text):cint;
  741. {
  742. May not use @PClose due overloading
  743. }
  744. begin
  745. PCloseText:=PClose(f);
  746. end;
  747. function POpen(var F:text;const Prog:String;rw:char):cint;
  748. {
  749. Starts the program in 'Prog' and makes it's input or out put the
  750. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  751. F, will be read from stdin by the program in 'Prog'. The inverse is true
  752. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  753. read from 'f'.
  754. }
  755. var
  756. pipi,
  757. pipo : text;
  758. pid : pid_t;
  759. pl : ^cint;
  760. pp : ppchar;
  761. ret : cint;
  762. begin
  763. rw:=upcase(rw);
  764. if not (rw in ['R','W']) then
  765. begin
  766. FpSetErrno(ESysEnoent);
  767. exit(-1);
  768. end;
  769. if AssignPipe(pipi,pipo)=-1 Then
  770. Exit(-1);
  771. pid:=fpfork;
  772. if pid=-1 then
  773. begin
  774. close(pipi);
  775. close(pipo);
  776. exit(-1);
  777. end;
  778. if pid=0 then
  779. begin
  780. { We're in the child }
  781. if rw='W' then
  782. begin
  783. close(pipo);
  784. ret:=fpdup2(pipi,input);
  785. close(pipi);
  786. if ret=-1 then
  787. halt(127);
  788. end
  789. else
  790. begin
  791. close(pipi);
  792. ret:=fpdup2(pipo,output);
  793. close(pipo);
  794. if ret=-1 then
  795. halt(127);
  796. end;
  797. pp:=createshellargv(prog);
  798. fpExecve(pp^,pp,envp);
  799. halt(127);
  800. end
  801. else
  802. begin
  803. { We're in the parent }
  804. if rw='W' then
  805. begin
  806. close(pipi);
  807. f:=pipo;
  808. textrec(f).bufptr:=@textrec(f).buffer;
  809. end
  810. else
  811. begin
  812. close(pipo);
  813. f:=pipi;
  814. textrec(f).bufptr:=@textrec(f).buffer;
  815. end;
  816. {Save the process ID - needed when closing }
  817. pl:=@(textrec(f).userdata[2]);
  818. pl^:=pid;
  819. textrec(f).closefunc:=@PCloseText;
  820. end;
  821. ret:=0;
  822. end;
  823. Function POpen(var F:file;const Prog:String;rw:char):cint;
  824. {
  825. Starts the program in 'Prog' and makes it's input or out put the
  826. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  827. F, will be read from stdin by the program in 'Prog'. The inverse is true
  828. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  829. read from 'f'.
  830. }
  831. var
  832. pipi,
  833. pipo : file;
  834. pid : cint;
  835. pl : ^cint;
  836. p,pp : ppchar;
  837. temp : string[255];
  838. ret : cint;
  839. begin
  840. rw:=upcase(rw);
  841. if not (rw in ['R','W']) then
  842. begin
  843. FpSetErrno(ESysEnoent);
  844. exit(-1);
  845. end;
  846. ret:=AssignPipe(pipi,pipo);
  847. if ret=-1 then
  848. exit(-1);
  849. pid:=fpfork;
  850. if pid=-1 then
  851. begin
  852. close(pipi);
  853. close(pipo);
  854. exit(-1);
  855. end;
  856. if pid=0 then
  857. begin
  858. { We're in the child }
  859. if rw='W' then
  860. begin
  861. close(pipo);
  862. ret:=fpdup2(filerec(pipi).handle,stdinputhandle);
  863. close(pipi);
  864. if ret=-1 then
  865. halt(127);
  866. end
  867. else
  868. begin
  869. close(pipi);
  870. ret:=fpdup2(filerec(pipo).handle,stdoutputhandle);
  871. close(pipo);
  872. if ret=1 then
  873. halt(127);
  874. end;
  875. getmem(pp,sizeof(pchar)*4);
  876. temp:='/bin/sh'#0'-c'#0+prog+#0;
  877. p:=pp;
  878. p^:=@temp[1];
  879. inc(p);
  880. p^:=@temp[9];
  881. inc(p);
  882. p^:=@temp[12];
  883. inc(p);
  884. p^:=Nil;
  885. fpExecve(ansistring('/bin/sh'),pp,envp);
  886. halt(127);
  887. end
  888. else
  889. begin
  890. { We're in the parent }
  891. if rw='W' then
  892. begin
  893. close(pipi);
  894. f:=pipo;
  895. end
  896. else
  897. begin
  898. close(pipo);
  899. f:=pipi;
  900. end;
  901. {Save the process ID - needed when closing }
  902. pl:=@(filerec(f).userdata[2]);
  903. pl^:=pid;
  904. end;
  905. POpen:=0;
  906. end;
  907. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : cint;
  908. {
  909. Starts the program in 'Prog' and makes its input and output the
  910. other end of two pipes, which are the stdin and stdout of a program
  911. specified in 'Prog'.
  912. streamout can be used to write to the program, streamin can be used to read
  913. the output of the program. See the following diagram :
  914. Parent Child
  915. STreamout --> Input
  916. Streamin <-- Output
  917. Return value is the process ID of the process being spawned, or -1 in case of failure.
  918. }
  919. var
  920. pipi,
  921. pipo : text;
  922. pid : cint;
  923. pl : ^cint;
  924. begin
  925. AssignStream:=-1;
  926. if AssignPipe(streamin,pipo)=-1 Then
  927. exit(-1);
  928. if AssignPipe(pipi,streamout)=-1 Then // shouldn't this close streamin and pipo?
  929. exit(-1);
  930. pid:=fpfork;
  931. if pid=-1 then
  932. begin
  933. close(pipi);
  934. close(pipo);
  935. close (streamin);
  936. close (streamout);
  937. exit;
  938. end;
  939. if pid=0 then
  940. begin
  941. { We're in the child }
  942. { Close what we don't need }
  943. close(streamout);
  944. close(streamin);
  945. if fpdup2(pipi,input)=-1 Then
  946. halt(127);
  947. close(pipi);
  948. If fpdup2(pipo,output)=-1 Then
  949. halt (127);
  950. close(pipo);
  951. Execl(Prog);
  952. halt(127);
  953. end
  954. else
  955. begin
  956. { we're in the parent}
  957. close(pipo);
  958. close(pipi);
  959. {Save the process ID - needed when closing }
  960. pl:=@(textrec(StreamIn).userdata[2]);
  961. pl^:=pid;
  962. textrec(StreamIn).closefunc:=@PCloseText;
  963. {Save the process ID - needed when closing }
  964. pl:=@(textrec(StreamOut).userdata[2]);
  965. pl^:=pid;
  966. textrec(StreamOut).closefunc:=@PCloseText;
  967. AssignStream:=Pid;
  968. end;
  969. end;
  970. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String):cint;
  971. {
  972. Starts the program in 'prog' and makes its input, output and error output the
  973. other end of three pipes, which are the stdin, stdout and stderr of a program
  974. specified in 'prog'.
  975. StreamOut can be used to write to the program, StreamIn can be used to read
  976. the output of the program, StreamErr reads the error output of the program.
  977. See the following diagram :
  978. Parent Child
  979. StreamOut --> StdIn (input)
  980. StreamIn <-- StdOut (output)
  981. StreamErr <-- StdErr (error output)
  982. }
  983. var
  984. PipeIn, PipeOut, PipeErr: text;
  985. pid: cint;
  986. pl: ^cint;
  987. begin
  988. AssignStream := -1;
  989. // Assign pipes
  990. if AssignPipe(StreamIn, PipeOut)=-1 Then
  991. Exit(-1);
  992. If AssignPipe(StreamErr, PipeErr)=-1 Then
  993. begin
  994. Close(StreamIn);
  995. Close(PipeOut);
  996. exit(-1);
  997. end;
  998. if AssignPipe(PipeIn, StreamOut)=-1 Then
  999. begin
  1000. Close(StreamIn);
  1001. Close(PipeOut);
  1002. Close(StreamErr);
  1003. Close(PipeErr);
  1004. exit(-1);
  1005. end;
  1006. // Fork
  1007. pid := fpFork;
  1008. if pid=-1 then begin
  1009. Close(StreamIn);
  1010. Close(PipeOut);
  1011. Close(StreamErr);
  1012. Close(PipeErr);
  1013. Close(PipeIn);
  1014. Close(StreamOut);
  1015. exit(-1);
  1016. end;
  1017. if pid = 0 then begin
  1018. // *** We are in the child ***
  1019. // Close what we don not need
  1020. Close(StreamOut);
  1021. Close(StreamIn);
  1022. Close(StreamErr);
  1023. // Connect pipes
  1024. if fpdup2(PipeIn, Input)=-1 Then
  1025. Halt(127);
  1026. Close(PipeIn);
  1027. if fpdup2(PipeOut, Output)=-1 Then
  1028. Halt(127);
  1029. Close(PipeOut);
  1030. if fpdup2(PipeErr, StdErr)=-1 Then
  1031. Halt(127);
  1032. Close(PipeErr);
  1033. // Execute program
  1034. Execl(Prog);
  1035. Halt(127);
  1036. end else begin
  1037. // *** We are in the parent ***
  1038. Close(PipeErr);
  1039. Close(PipeOut);
  1040. Close(PipeIn);
  1041. // Save the process ID - needed when closing
  1042. pl := @(TextRec(StreamIn).userdata[2]);
  1043. pl^ := pid;
  1044. TextRec(StreamIn).closefunc := @PCloseText;
  1045. // Save the process ID - needed when closing
  1046. pl := @(TextRec(StreamOut).userdata[2]);
  1047. pl^ := pid;
  1048. TextRec(StreamOut).closefunc := @PCloseText;
  1049. // Save the process ID - needed when closing
  1050. pl := @(TextRec(StreamErr).userdata[2]);
  1051. pl^ := pid;
  1052. TextRec(StreamErr).closefunc := @PCloseText;
  1053. AssignStream := pid;
  1054. end;
  1055. end;
  1056. {******************************************************************************
  1057. General information calls
  1058. ******************************************************************************}
  1059. {$ifndef BSD}
  1060. Function GetDomainName:String; { linux only!}
  1061. // domainname is a glibc extension.
  1062. {
  1063. Get machines domain name. Returns empty string if not set.
  1064. }
  1065. Var
  1066. Sysn : utsname;
  1067. begin
  1068. If fpUname(sysn)<>0 then
  1069. getdomainname:=''
  1070. else
  1071. getdomainname:=strpas(@Sysn.domain[0]);
  1072. end;
  1073. {$endif}
  1074. Function GetHostName:String;
  1075. {
  1076. Get machines name. Returns empty string if not set.
  1077. }
  1078. Var
  1079. Sysn : utsname;
  1080. begin
  1081. If fpuname(sysn)=-1 then
  1082. gethostname:=''
  1083. else
  1084. gethostname:=strpas(@Sysn.nodename[0]);
  1085. end;
  1086. {******************************************************************************
  1087. Signal handling calls
  1088. ******************************************************************************}
  1089. procedure SigRaise(sig:integer);
  1090. begin
  1091. fpKill(fpGetPid,Sig);
  1092. end;
  1093. {******************************************************************************
  1094. Utility calls
  1095. ******************************************************************************}
  1096. {
  1097. Function Octal(l:cint):cint;
  1098. {
  1099. Convert an octal specified number to decimal;
  1100. }
  1101. var
  1102. octnr,
  1103. oct : cint;
  1104. begin
  1105. octnr:=0;
  1106. oct:=0;
  1107. while (l>0) do
  1108. begin
  1109. oct:=oct or ((l mod 10) shl octnr);
  1110. l:=l div 10;
  1111. inc(octnr,3);
  1112. end;
  1113. Octal:=oct;
  1114. end;
  1115. }
  1116. {$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
  1117. {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
  1118. {$I fexpand.inc}
  1119. {$UNDEF FPC_FEXPAND_GETENVPCHAR}
  1120. {$UNDEF FPC_FEXPAND_TILDE}
  1121. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  1122. {
  1123. Searches for a file 'path' in the list of direcories in 'dirlist'.
  1124. returns an empty string if not found. Wildcards are NOT allowed.
  1125. If dirlist is empty, it is set to '.'
  1126. }
  1127. Var
  1128. NewDir : PathStr;
  1129. p1 : cint;
  1130. Info : Stat;
  1131. Begin
  1132. {Replace ':' with ';'}
  1133. for p1:=1to length(dirlist) do
  1134. if dirlist[p1]=':' then
  1135. dirlist[p1]:=';';
  1136. {Check for WildCards}
  1137. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  1138. FSearch:='' {No wildcards allowed in these things.}
  1139. Else
  1140. Begin
  1141. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  1142. Repeat
  1143. p1:=Pos(';',DirList);
  1144. If p1=0 Then
  1145. p1:=255;
  1146. NewDir:=Copy(DirList,1,P1 - 1);
  1147. if NewDir[Length(NewDir)]<>'/' then
  1148. NewDir:=NewDir+'/';
  1149. NewDir:=NewDir+Path;
  1150. Delete(DirList,1,p1);
  1151. if (FpStat(NewDir,Info)>=0) and
  1152. (not fpS_ISDIR(Info.st_Mode)) then
  1153. Begin
  1154. If Pos('./',NewDir)=1 Then
  1155. Delete(NewDir,1,2);
  1156. {DOS strips off an initial .\}
  1157. End
  1158. Else
  1159. NewDir:='';
  1160. Until (DirList='') or (Length(NewDir) > 0);
  1161. FSearch:=NewDir;
  1162. End;
  1163. End;
  1164. Procedure Globfree(var p : pglob);
  1165. {
  1166. Release memory occupied by pglob structure, and names in it.
  1167. sets p to nil.
  1168. }
  1169. var
  1170. temp : pglob;
  1171. begin
  1172. while assigned(p) do
  1173. begin
  1174. temp:=p^.next;
  1175. if assigned(p^.name) then
  1176. freemem(p^.name);
  1177. dispose(p);
  1178. p:=temp;
  1179. end;
  1180. end;
  1181. Function Glob(Const path:pathstr):pglob;
  1182. {
  1183. Fills a tglob structure with entries matching path,
  1184. and returns a pointer to it. Returns nil on error,
  1185. linuxerror is set accordingly.
  1186. }
  1187. var
  1188. temp,
  1189. temp2 : string[255];
  1190. thedir : pdir;
  1191. buffer : pdirent;
  1192. root,
  1193. current : pglob;
  1194. begin
  1195. { Get directory }
  1196. temp:=dirname(path);
  1197. if temp='' then
  1198. temp:='.';
  1199. temp:=temp+#0;
  1200. thedir:=fpopendir(@temp[1]);
  1201. if thedir=nil then
  1202. exit(nil);
  1203. temp:=basename(path,''); { get the pattern }
  1204. if thedir^.dd_fd<0 then
  1205. exit(nil);
  1206. {get the entries}
  1207. root:=nil;
  1208. current:=nil;
  1209. repeat
  1210. buffer:=fpreaddir(thedir^);
  1211. if buffer=nil then
  1212. break;
  1213. temp2:=strpas(@(buffer^.d_name[0]));
  1214. if fnmatch(temp,temp2) then
  1215. begin
  1216. if root=nil then
  1217. begin
  1218. new(root);
  1219. current:=root;
  1220. end
  1221. else
  1222. begin
  1223. new(current^.next);
  1224. current:=current^.next;
  1225. end;
  1226. if current=nil then
  1227. begin
  1228. fpseterrno(ESysENOMEM);
  1229. globfree(root);
  1230. break;
  1231. end;
  1232. current^.next:=nil;
  1233. getmem(current^.name,length(temp2)+1);
  1234. if current^.name=nil then
  1235. begin
  1236. fpseterrno(ESysENOMEM);
  1237. globfree(root);
  1238. break;
  1239. end;
  1240. move(buffer^.d_name[0],current^.name^,length(temp2)+1);
  1241. end;
  1242. until false;
  1243. fpclosedir(thedir^);
  1244. glob:=root;
  1245. end;
  1246. {--------------------------------
  1247. Stat.Mode Macro's
  1248. --------------------------------}
  1249. Initialization
  1250. InitLocalTime;
  1251. finalization
  1252. DoneLocalTime;
  1253. End.
  1254. {
  1255. $Log$
  1256. Revision 1.53 2003-12-30 12:24:01 marco
  1257. * FPC_USE_LIBC
  1258. Revision 1.52 2003/12/08 17:16:30 peter
  1259. * fsearch should only find files
  1260. Revision 1.51 2003/11/19 17:11:40 marco
  1261. * termio unit
  1262. Revision 1.50 2003/11/19 10:54:32 marco
  1263. * some simple restructures
  1264. Revision 1.49 2003/11/17 11:28:08 marco
  1265. * Clone moved to linux, + few small unit unix changes
  1266. Revision 1.48 2003/11/17 10:05:51 marco
  1267. * threads for FreeBSD. Not working tho
  1268. Revision 1.47 2003/11/14 17:30:14 marco
  1269. * weeehoo linuxerror is no more :-)
  1270. Revision 1.46 2003/11/14 16:44:48 marco
  1271. * stream functions converted to work without linuxerror
  1272. Revision 1.45 2003/11/13 18:44:06 marco
  1273. * small fi
  1274. Revision 1.44 2003/11/12 22:19:45 marco
  1275. * more linuxeror fixes
  1276. Revision 1.43 2003/11/03 09:42:28 marco
  1277. * Peter's Cardinal<->Longint fixes patch
  1278. Revision 1.42 2003/10/30 16:42:58 marco
  1279. * fixes for old syscall() convention removing
  1280. Revision 1.41 2003/10/12 19:40:43 marco
  1281. * ioctl fixes. IDE now starts, but
  1282. Revision 1.40 2003/09/29 14:36:06 peter
  1283. * fixed for stricter compiler
  1284. Revision 1.39 2003/09/27 12:51:33 peter
  1285. * fpISxxx macros renamed to C compliant fpS_ISxxx
  1286. Revision 1.38 2003/09/20 12:38:29 marco
  1287. * FCL now compiles for FreeBSD with new 1.1. Now Linux.
  1288. Revision 1.37 2003/09/17 19:07:44 marco
  1289. * more fixes for Unix<->unixutil
  1290. Revision 1.36 2003/09/17 17:30:46 marco
  1291. * Introduction of unixutil
  1292. Revision 1.35 2003/09/16 21:46:27 marco
  1293. * small fixes, checking things on linux
  1294. Revision 1.34 2003/09/16 20:52:24 marco
  1295. * small cleanups. Mostly killing of already commented code in unix etc
  1296. Revision 1.33 2003/09/16 16:13:56 marco
  1297. * fdset functions renamed to fp<posix name>
  1298. Revision 1.32 2003/09/15 20:08:49 marco
  1299. * small fixes. FreeBSD now cycles
  1300. Revision 1.31 2003/09/14 20:15:01 marco
  1301. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  1302. Revision 1.30 2003/07/08 21:23:24 peter
  1303. * sparc fixes
  1304. Revision 1.29 2003/05/30 19:58:40 marco
  1305. * Getting NetBSD/i386 to compile.
  1306. Revision 1.28 2003/05/29 19:16:16 marco
  1307. * fixed a small *BSD gotcha
  1308. Revision 1.27 2003/05/24 20:39:54 jonas
  1309. * fixed ExitCode translation in WaitProcess for Linux and Darwin (and
  1310. probably other BSD's as well)
  1311. Revision 1.26 2003/03/11 08:27:59 michael
  1312. * stringtoppchar should use tabs instead of backspace as delimiter
  1313. Revision 1.25 2002/12/18 16:50:39 marco
  1314. * Unix RTL generic parts. Linux working, *BSD will follow shortly
  1315. Revision 1.24 2002/09/07 16:01:28 peter
  1316. * old logs removed and tabs fixed
  1317. Revision 1.23 2002/08/06 13:30:46 sg
  1318. * replaced some Longints with Cardinals, to mach the C headers
  1319. * updated the termios record
  1320. Revision 1.22 2002/03/05 20:04:25 michael
  1321. + Patch from Sebastian for FCNTL call
  1322. Revision 1.21 2002/01/02 12:22:54 marco
  1323. * Removed ifdef arround getepoch.
  1324. }