unix.pp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  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 BaseUnix;
  16. {// i ostypes.inc}
  17. { Get Types and Constants }
  18. {$i sysconst.inc}
  19. {$i systypes.inc}
  20. { Get System call numbers and error-numbers}
  21. {$i sysnr.inc}
  22. {$i errno.inc}
  23. {$I signal.inc}
  24. {$i ostypes.inc}
  25. var
  26. LinuxError : Longint;
  27. {********************
  28. Process
  29. ********************}
  30. const
  31. { For getting/setting priority }
  32. Prio_Process = 0;
  33. Prio_PGrp = 1;
  34. Prio_User = 2;
  35. {$ifdef Solaris}
  36. WNOHANG = $100;
  37. WUNTRACED = $4;
  38. {$ELSE}
  39. WNOHANG = $1;
  40. WUNTRACED = $2;
  41. __WCLONE = $80000000;
  42. {$ENDIF}
  43. {********************
  44. File
  45. ********************}
  46. Const
  47. P_IN = 1;
  48. P_OUT = 2;
  49. Const
  50. LOCK_SH = 1;
  51. LOCK_EX = 2;
  52. LOCK_UN = 8;
  53. LOCK_NB = 4;
  54. Type
  55. Tpipe = array[1..2] of longint;
  56. pglob = ^tglob;
  57. tglob = record
  58. name : pchar;
  59. next : pglob;
  60. end;
  61. ComStr = String[255];
  62. PathStr = String[255];
  63. DirStr = String[255];
  64. NameStr = String[255];
  65. ExtStr = String[255];
  66. const
  67. { For File control mechanism }
  68. F_GetFd = 1;
  69. F_SetFd = 2;
  70. F_GetFl = 3;
  71. F_SetFl = 4;
  72. {$ifdef Solaris}
  73. F_DupFd = 0;
  74. F_Dup2Fd = 9;
  75. F_GetOwn = 23;
  76. F_SetOwn = 24;
  77. F_GetLk = 14;
  78. F_SetLk = 6;
  79. F_SetLkW = 7;
  80. F_FreeSp = 11;
  81. {$else}
  82. F_GetLk = 5;
  83. F_SetLk = 6;
  84. F_SetLkW = 7;
  85. F_SetOwn = 8;
  86. F_GetOwn = 9;
  87. {$endif}
  88. {********************
  89. IOCtl(TermIOS)
  90. ********************}
  91. {Is too freebsd/Linux specific}
  92. {$I termios.inc}
  93. {******************************************************************************
  94. Procedure/Functions
  95. ******************************************************************************}
  96. {**************************
  97. Time/Date Handling
  98. ***************************}
  99. var
  100. tzdaylight : boolean;
  101. tzseconds : longint;
  102. tzname : array[boolean] of pchar;
  103. { timezone support }
  104. procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
  105. procedure GetLocalTimezone(timer:longint);
  106. procedure ReadTimezoneFile(fn:string);
  107. function GetTimezoneFile:string;
  108. Function GetEpochTime: longint;
  109. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  110. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  111. procedure GetTime(var hour,min,sec,msec,usec:word);
  112. procedure GetTime(var hour,min,sec,sec100:word);
  113. procedure GetTime(var hour,min,sec:word);
  114. Procedure GetDate(Var Year,Month,Day:Word);
  115. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  116. function SetTime(Hour,Min,Sec:word) : Boolean;
  117. function SetDate(Year,Month,Day:Word) : Boolean;
  118. function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
  119. {**************************
  120. Process Handling
  121. ***************************}
  122. function CreateShellArgV(const prog:string):ppchar;
  123. function CreateShellArgV(const prog:Ansistring):ppchar;
  124. //Procedure Execve(Path: pathstr;args:ppchar;ep:ppchar);
  125. //Procedure Execve(Path: AnsiString;args:ppchar;ep:ppchar);
  126. //Procedure Execve(path: pchar;args:ppchar;ep:ppchar);
  127. Procedure Execv(const path:pathstr;args:ppchar);
  128. Procedure Execv(const path: AnsiString;args:ppchar);
  129. Procedure Execvp(Path: Pathstr;Args:ppchar;Ep:ppchar);
  130. Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
  131. Procedure Execl(const Todo: String);
  132. Procedure Execl(const Todo: Ansistring);
  133. Procedure Execle(Todo: String;Ep:ppchar);
  134. Procedure Execle(Todo: AnsiString;Ep:ppchar);
  135. Procedure Execlp(Todo: string;Ep:ppchar);
  136. Procedure Execlp(Todo: Ansistring;Ep:ppchar);
  137. Function Shell(const Command:String):Longint;
  138. Function Shell(const Command:AnsiString):Longint;
  139. {Clone for FreeBSD is copied from the LinuxThread port, and rfork based}
  140. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  141. Function WaitProcess(Pid:longint):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  142. Function WIFSTOPPED(Status: Integer): Boolean;
  143. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  144. Function W_STOPCODE(Signal: Integer): Integer;
  145. {**************************
  146. File Handling
  147. ***************************}
  148. Function fdFlush (fd : Longint) : Boolean;
  149. Function Flock (fd,mode : longint) : boolean;
  150. Function Flock (var T : text;mode : longint) : boolean;
  151. Function Flock (var F : File;mode : longint) : boolean;
  152. Function StatFS(Path:Pathstr;Var Info:tstatfs):Boolean;
  153. Function StatFS(Fd: Longint;Var Info:tstatfs):Boolean;
  154. Function SelectText(var T:Text;TimeOut :PTimeVal):Longint;
  155. Function SelectText(var T:Text;TimeOut :Longint):Longint;
  156. {**************************
  157. Directory Handling
  158. ***************************}
  159. procedure SeekDir(p:pdir;off:longint);
  160. function TellDir(p:pdir):longint;
  161. {**************************
  162. Pipe/Fifo/Stream
  163. ***************************}
  164. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  165. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  166. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  167. Function PClose(Var F:text) : longint;
  168. Function PClose(Var F:file) : longint;
  169. Procedure POpen(var F:text;const Prog:String;rw:char);
  170. Procedure POpen(var F:file;const Prog:String;rw:char);
  171. function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  172. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  173. {$ifndef BSD}
  174. Function GetDomainName:String;
  175. Function GetHostName:String;
  176. {$endif}
  177. {**************************
  178. IOCtl/Termios Functions
  179. ***************************}
  180. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  181. Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
  182. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  183. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  184. Procedure CFMakeRaw(var tios:TermIOS);
  185. Function TCSendBreak(fd,duration:longint):boolean;
  186. Function TCSetPGrp(fd,id:longint):boolean;
  187. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  188. Function TCFlush(fd,qsel:longint):boolean;
  189. Function TCDrain(fd:longint):boolean;
  190. Function TCFlow(fd,act:longint):boolean;
  191. Function IsATTY(Handle:Longint):Boolean;
  192. Function IsATTY(f:text):Boolean;
  193. function TTYname(Handle:Longint):string;
  194. function TTYname(var F:Text):string;
  195. {**************************
  196. Memory functions
  197. ***************************}
  198. const
  199. PROT_READ = $1; { page can be read }
  200. PROT_WRITE = $2; { page can be written }
  201. PROT_EXEC = $4; { page can be executed }
  202. PROT_NONE = $0; { page can not be accessed }
  203. MAP_SHARED = $1; { Share changes }
  204. // MAP_PRIVATE = $2; { Changes are private }
  205. MAP_TYPE = $f; { Mask for type of mapping }
  206. MAP_FIXED = $10; { Interpret addr exactly }
  207. // MAP_ANONYMOUS = $20; { don't use a file }
  208. MAP_GROWSDOWN = $100; { stack-like segment }
  209. MAP_DENYWRITE = $800; { ETXTBSY }
  210. MAP_EXECUTABLE = $1000; { mark it as an executable }
  211. MAP_LOCKED = $2000; { pages are locked }
  212. MAP_NORESERVE = $4000; { don't check for reservations }
  213. {**************************
  214. Utility functions
  215. ***************************}
  216. Function Octal(l:longint):longint;
  217. Function FExpand(Const Path: PathStr):PathStr;
  218. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  219. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  220. Function Dirname(Const path:pathstr):pathstr;
  221. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  222. Function FNMatch(const Pattern,Name:string):Boolean;
  223. Function Glob(Const path:pathstr):pglob;
  224. Procedure Globfree(var p:pglob);
  225. Function StringToPPChar(Var S:String):ppchar;
  226. Function StringToPPChar(Var S:AnsiString):ppchar;
  227. Function StringToPPChar(S : Pchar):ppchar;
  228. Function GetFS(var T:Text):longint;
  229. Function GetFS(Var F:File):longint;
  230. {Filedescriptorsets}
  231. {Stat.Mode Types}
  232. Function S_ISLNK(m:word):boolean;
  233. Function S_ISSOCK(m:word):boolean;
  234. {******************************************************************************
  235. Implementation
  236. ******************************************************************************}
  237. {$i unxsysch.inc}
  238. Implementation
  239. Uses Strings;
  240. {$i syscallh.inc}
  241. {$i unxsysc.inc}
  242. {$i ossysch.inc}
  243. { Get the definitions of textrec and filerec }
  244. {$i textrec.inc}
  245. {$i filerec.inc}
  246. { Raw System calls are in Syscalls.inc}
  247. {$i syscalls.inc}
  248. {$i unixsysc.inc} {Syscalls only used in unit Unix/Linux}
  249. Function getenv(name:string):Pchar; external name 'FPC_SYSC_FPGETENV';
  250. {******************************************************************************
  251. Process related calls
  252. ******************************************************************************}
  253. { Most calls of WaitPID do not handle the result correctly, this funktion treats errors more correctly }
  254. Function WaitProcess(Pid:longint):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  255. var r,s : LongInt;
  256. begin
  257. repeat
  258. s:=$7F00;
  259. r:=fpWaitPid(Pid,s,0);
  260. until (r<>-1) or (LinuxError<>ESysEINTR);
  261. if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
  262. WaitProcess:=-1 // return -1 to indicate an error
  263. else
  264. begin
  265. {$ifndef Solaris}
  266. { at least correct for Linux and Darwin (JM) }
  267. if (s and $7F)=0 then // Only this is a valid returncode
  268. {$else}
  269. if (s and $FF)=0 then // Only this is a valid returncode
  270. {$endif}
  271. WaitProcess:=s shr 8
  272. else if (s>0) then // Until now there is not use of the highest bit , but check this for the future
  273. WaitProcess:=-s // normal case
  274. else
  275. WaitProcess:=s; // s<0 should not occur, but wie return also a negativ value
  276. end;
  277. end;
  278. function InternalCreateShellArgV(cmd:pChar; len:longint):ppchar;
  279. {
  280. Create an argv which executes a command in a shell using /bin/sh -c
  281. }
  282. const Shell = '/bin/sh'#0'-c'#0;
  283. var
  284. pp,p : ppchar;
  285. // temp : string; !! Never pass a local var back!!
  286. begin
  287. getmem(pp,4*4);
  288. p:=pp;
  289. p^:=@Shell[1];
  290. inc(p);
  291. p^:=@Shell[9];
  292. inc(p);
  293. getmem(p^,len+1);
  294. move(cmd^,p^^,len);
  295. pchar(p^)[len]:=#0;
  296. inc(p);
  297. p^:=Nil;
  298. InternalCreateShellArgV:=pp;
  299. end;
  300. function CreateShellArgV(const prog:string):ppchar;
  301. begin
  302. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
  303. end;
  304. function CreateShellArgV(const prog:Ansistring):ppchar;
  305. {
  306. Create an argv which executes a command in a shell using /bin/sh -c
  307. using a AnsiString;
  308. }
  309. begin
  310. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog)); // if ppc works like delphi this also work when @prog[1] is invalid (len=0)
  311. end;
  312. procedure FreeShellArgV(p:ppchar);
  313. begin
  314. if (p<>nil) then begin
  315. freemem(p[2]);
  316. freemem(p);
  317. end;
  318. end;
  319. Procedure Execv(const path: AnsiString;args:ppchar);
  320. {
  321. Overloaded ansistring version.
  322. }
  323. begin
  324. fpExecVe(Path,Args,envp)
  325. end;
  326. Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
  327. {
  328. Overloaded ansistring version
  329. }
  330. var
  331. thepath : Ansistring;
  332. begin
  333. if path[1]<>'/' then
  334. begin
  335. Thepath:=strpas(fpgetenv('PATH'));
  336. if thepath='' then
  337. thepath:='.';
  338. Path:=FSearch(path,thepath)
  339. end
  340. else
  341. Path:='';
  342. if Path='' then
  343. linuxerror:=ESysEnoent
  344. else
  345. fpExecve(Path,args,ep);{On error linuxerror will get set there}
  346. end;
  347. Procedure Execv(const path:pathstr;args:ppchar);
  348. {
  349. Replaces the current program by the program specified in path,
  350. arguments in args are passed to Execve.
  351. the current environment is passed on.
  352. }
  353. begin
  354. fpExecve(path,args,envp); {On error linuxerror will get set there}
  355. end;
  356. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  357. {
  358. This does the same as Execve, only it searches the PATH environment
  359. for the place of the Executable, except when Path starts with a slash.
  360. if the PATH environment variable is unavailable, the path is set to '.'
  361. }
  362. var
  363. thepath : string;
  364. begin
  365. if path[1]<>'/' then
  366. begin
  367. Thepath:=strpas(fpgetenv('PATH'));
  368. if thepath='' then
  369. thepath:='.';
  370. Path:=FSearch(path,thepath)
  371. end
  372. else
  373. Path:='';
  374. if Path='' then
  375. linuxerror:=ESysEnoent
  376. else
  377. fpExecve(Path,args,ep);{On error linuxerror will get set there}
  378. end;
  379. Procedure Execle(Todo:string;Ep:ppchar);
  380. {
  381. This procedure takes the string 'Todo', parses it for command and
  382. command options, and Executes the command with the given options.
  383. The string 'Todo' shoud be of the form 'command options', options
  384. separated by commas.
  385. the PATH environment is not searched for 'command'.
  386. The specified environment(in 'ep') is passed on to command
  387. }
  388. var
  389. p : ppchar;
  390. begin
  391. p:=StringToPPChar(ToDo);
  392. if (p=nil) or (p^=nil) then
  393. exit;
  394. fpExecVE(p^,p,EP);
  395. end;
  396. Procedure Execle(Todo:AnsiString;Ep:ppchar);
  397. {
  398. This procedure takes the string 'Todo', parses it for command and
  399. command options, and Executes the command with the given options.
  400. The string 'Todo' shoud be of the form 'command options', options
  401. separated by commas.
  402. the PATH environment is not searched for 'command'.
  403. The specified environment(in 'ep') is passed on to command
  404. }
  405. var
  406. p : ppchar;
  407. begin
  408. p:=StringToPPChar(ToDo);
  409. if (p=nil) or (p^=nil) then
  410. exit;
  411. fpExecVE(p^,p,EP);
  412. end;
  413. Procedure Execl(const Todo:string);
  414. {
  415. This procedure takes the string 'Todo', parses it for command and
  416. command options, and Executes the command with the given options.
  417. The string 'Todo' shoud be of the form 'command options', options
  418. separated by commas.
  419. the PATH environment is not searched for 'command'.
  420. The current environment is passed on to command
  421. }
  422. begin
  423. ExecLE(ToDo,EnvP);
  424. end;
  425. Procedure Execlp(Todo:string;Ep:ppchar);
  426. {
  427. This procedure takes the string 'Todo', parses it for command and
  428. command options, and Executes the command with the given options.
  429. The string 'Todo' shoud be of the form 'command options', options
  430. separated by commas.
  431. the PATH environment is searched for 'command'.
  432. The specified environment (in 'ep') is passed on to command
  433. }
  434. var
  435. p : ppchar;
  436. begin
  437. p:=StringToPPchar(todo);
  438. if (p=nil) or (p^=nil) then
  439. exit;
  440. ExecVP(StrPas(p^),p,EP);
  441. end;
  442. Procedure Execlp(Todo: Ansistring;Ep:ppchar);
  443. {
  444. Overloaded ansistring version.
  445. }
  446. var
  447. p : ppchar;
  448. begin
  449. p:=StringToPPchar(todo);
  450. if (p=nil) or (p^=nil) then
  451. exit;
  452. ExecVP(StrPas(p^),p,EP);
  453. end;
  454. Function Shell(const Command:String):Longint;
  455. {
  456. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  457. The current environment is passed to the shell.
  458. It waits for the shell to exit, and returns its exit status.
  459. If the Exec call failed exit status 127 is reported.
  460. }
  461. { Changed the structure:
  462. - the previous version returns an undefinied value if fork fails
  463. - it returns the status of Waitpid instead of the Process returnvalue (see the doc to Shell)
  464. - it uses exit(127) not ExitProc (The Result in pp386: going on Compiling in 2 processes!)
  465. - ShellArgs are now released
  466. - The Old CreateShellArg gives back pointers to a local var
  467. }
  468. var
  469. p : ppchar;
  470. pid : longint;
  471. begin
  472. p:=CreateShellArgv(command);
  473. pid:=fpfork;
  474. if pid=0 then // We are in the Child
  475. begin
  476. {This is the child.}
  477. fpExecve(p^,p,envp);
  478. fpExit(127); // was Exit(127)
  479. end
  480. else if (pid<>-1) then // Successfull started
  481. Shell:=WaitProcess(pid) {Linuxerror is set there}
  482. else // no success
  483. Shell:=-1; // indicate an error
  484. FreeShellArgV(p);
  485. end;
  486. Function Shell(const Command:AnsiString):Longint;
  487. {
  488. AnsiString version of Shell
  489. }
  490. var
  491. p : ppchar;
  492. pid : longint;
  493. begin { Changes as above }
  494. p:=CreateShellArgv(command);
  495. pid:=fpfork;
  496. if pid=0 then // We are in the Child
  497. begin
  498. fpExecve(p^,p,envp);
  499. fpExit(127); // was exit(127)!! We must exit the Process, not the function
  500. end
  501. else if (pid<>-1) then // Successfull started
  502. Shell:=WaitProcess(pid) {Linuxerror is set there}
  503. else // no success
  504. Shell:=-1;
  505. FreeShellArgV(p);
  506. end;
  507. Function WIFSTOPPED(Status: Integer): Boolean;
  508. begin
  509. WIFSTOPPED:=((Status and $FF)=$7F);
  510. end;
  511. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  512. begin
  513. W_EXITCODE:=(ReturnCode shl 8) or Signal;
  514. end;
  515. Function W_STOPCODE(Signal: Integer): Integer;
  516. begin
  517. W_STOPCODE:=(Signal shl 8) or $7F;
  518. end;
  519. {******************************************************************************
  520. Date and Time related calls
  521. ******************************************************************************}
  522. Const
  523. {Date Translation}
  524. C1970=2440588;
  525. D0 = 1461;
  526. D1 = 146097;
  527. D2 =1721119;
  528. Function GregorianToJulian(Year,Month,Day:Longint):LongInt;
  529. Var
  530. Century,XYear: LongInt;
  531. Begin
  532. If Month<=2 Then
  533. Begin
  534. Dec(Year);
  535. Inc(Month,12);
  536. End;
  537. Dec(Month,3);
  538. Century:=(longint(Year Div 100)*D1) shr 2;
  539. XYear:=(longint(Year Mod 100)*D0) shr 2;
  540. GregorianToJulian:=((((Month*153)+2) div 5)+Day)+D2+XYear+Century;
  541. End;
  542. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  543. Var
  544. YYear,XYear,Temp,TempMonth : LongInt;
  545. Begin
  546. Temp:=((JulianDN-D2) shl 2)-1;
  547. JulianDN:=Temp Div D1;
  548. XYear:=(Temp Mod D1) or 3;
  549. YYear:=(XYear Div D0);
  550. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  551. Day:=((Temp Mod 153)+5) Div 5;
  552. TempMonth:=Temp Div 153;
  553. If TempMonth>=10 Then
  554. Begin
  555. inc(YYear);
  556. dec(TempMonth,12);
  557. End;
  558. inc(TempMonth,3);
  559. Month := TempMonth;
  560. Year:=YYear+(JulianDN*100);
  561. end;
  562. Function GetEpochTime: longint;
  563. {
  564. Get the number of seconds since 00:00, January 1 1970, GMT
  565. the time NOT corrected any way
  566. }
  567. begin
  568. GetEpochTime:=fptime;
  569. end;
  570. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  571. {
  572. Transforms Epoch time into local time (hour, minute,seconds)
  573. }
  574. Var
  575. DateNum: LongInt;
  576. Begin
  577. inc(Epoch,TZSeconds);
  578. Datenum:=(Epoch Div 86400) + c1970;
  579. JulianToGregorian(DateNum,Year,Month,day);
  580. Epoch:=Abs(Epoch Mod 86400);
  581. Hour:=Epoch Div 3600;
  582. Epoch:=Epoch Mod 3600;
  583. Minute:=Epoch Div 60;
  584. Second:=Epoch Mod 60;
  585. End;
  586. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  587. {
  588. Transforms local time (year,month,day,hour,minutes,second) to Epoch time
  589. (seconds since 00:00, january 1 1970, corrected for local time zone)
  590. }
  591. Begin
  592. LocalToEpoch:=((GregorianToJulian(Year,Month,Day)-c1970)*86400)+
  593. (LongInt(Hour)*3600)+(Minute*60)+Second-TZSeconds;
  594. End;
  595. procedure GetTime(var hour,min,sec,msec,usec:word);
  596. {
  597. Gets the current time, adjusted to local time
  598. }
  599. var
  600. year,day,month:Word;
  601. tz:timeval;
  602. begin
  603. fpgettimeofday(@tz,nil);
  604. EpochToLocal(tz.tv_sec,year,month,day,hour,min,sec);
  605. msec:=tz.tv_usec div 1000;
  606. usec:=tz.tv_usec mod 1000;
  607. end;
  608. procedure GetTime(var hour,min,sec,sec100:word);
  609. {
  610. Gets the current time, adjusted to local time
  611. }
  612. var
  613. usec : word;
  614. begin
  615. gettime(hour,min,sec,sec100,usec);
  616. sec100:=sec100 div 10;
  617. end;
  618. Procedure GetTime(Var Hour,Min,Sec:Word);
  619. {
  620. Gets the current time, adjusted to local time
  621. }
  622. var
  623. msec,usec : Word;
  624. Begin
  625. gettime(hour,min,sec,msec,usec);
  626. End;
  627. Procedure GetDate(Var Year,Month,Day:Word);
  628. {
  629. Gets the current date, adjusted to local time
  630. }
  631. var
  632. hour,minute,second : word;
  633. Begin
  634. EpochToLocal(fptime,year,month,day,hour,minute,second);
  635. End;
  636. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  637. {
  638. Gets the current date, adjusted to local time
  639. }
  640. Begin
  641. EpochToLocal(fptime,year,month,day,hour,minute,second);
  642. End;
  643. {$ifndef BSD}
  644. {$ifdef linux}
  645. Function stime (t : longint) : Boolean;
  646. var
  647. sr : Syscallregs;
  648. begin
  649. sr.reg2:=longint(@t);
  650. SysCall(Syscall_nr_stime,sr);
  651. linuxerror:=fpgeterrno;;
  652. stime:=linuxerror=0;
  653. end;
  654. {$endif}
  655. {$endif}
  656. {$ifdef BSD}
  657. Function stime (t : longint) : Boolean;
  658. begin
  659. end;
  660. {$endif}
  661. Function SetTime(Hour,Min,Sec:word) : boolean;
  662. var
  663. Year, Month, Day : Word;
  664. begin
  665. GetDate (Year, Month, Day);
  666. SetTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Min, Sec ) );
  667. end;
  668. Function SetDate(Year,Month,Day:Word) : boolean;
  669. var
  670. Hour, Minute, Second, Sec100 : Word;
  671. begin
  672. GetTime ( Hour, Minute, Second, Sec100 );
  673. SetDate:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  674. end;
  675. Function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
  676. begin
  677. SetDateTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  678. end;
  679. { Include timezone handling routines which use /usr/share/timezone info }
  680. {$i timezone.inc}
  681. {******************************************************************************
  682. FileSystem calls
  683. ******************************************************************************}
  684. Procedure Execl(const Todo:Ansistring);
  685. {
  686. Overloaded AnsiString Version of ExecL.
  687. }
  688. begin
  689. ExecLE(ToDo,EnvP);
  690. end;
  691. Function Flock (var T : text;mode : longint) : boolean;
  692. begin
  693. Flock:=Flock(TextRec(T).Handle,mode);
  694. end;
  695. Function Flock (var F : File;mode : longint) : boolean;
  696. begin
  697. Flock:=Flock(FileRec(F).Handle,mode);
  698. end;
  699. Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
  700. Var
  701. F:TfdSet;
  702. begin
  703. if textrec(t).mode=fmclosed then
  704. begin
  705. LinuxError:=ESysEBADF;
  706. exit(-1);
  707. end;
  708. FpFD_ZERO(f);
  709. fpFD_SET(textrec(T).handle,f);
  710. if textrec(T).mode=fminput then
  711. SelectText:=fpselect(textrec(T).handle+1,@f,nil,nil,TimeOut)
  712. else
  713. SelectText:=fpselect(textrec(T).handle+1,nil,@f,nil,TimeOut);
  714. end;
  715. Function SelectText(var T:Text;TimeOut :Longint):Longint;
  716. var
  717. p : PTimeVal;
  718. tv : TimeVal;
  719. begin
  720. if TimeOut=-1 then
  721. p:=nil
  722. else
  723. begin
  724. tv.tv_Sec:=Timeout div 1000;
  725. tv.tv_Usec:=(Timeout mod 1000)*1000;
  726. p:=@tv;
  727. end;
  728. SelectText:=SelectText(T,p);
  729. end;
  730. {******************************************************************************
  731. Directory
  732. ******************************************************************************}
  733. procedure SeekDir(p:pdir;off:longint);
  734. begin
  735. if p=nil then
  736. begin
  737. fpseterrno(ESysEBADF);
  738. exit;
  739. end;
  740. {$ifndef bsd}
  741. p^.dd_nextoff:=fplseek(p^.dd_fd,off,seek_set);
  742. {$endif}
  743. p^.dd_size:=0;
  744. p^.dd_loc:=0;
  745. end;
  746. function TellDir(p:pdir):longint;
  747. begin
  748. if p=nil then
  749. begin
  750. fpseterrno(ESysEBADF);
  751. telldir:=-1;
  752. exit;
  753. end;
  754. telldir:=fplseek(p^.dd_fd,0,seek_cur)
  755. { We could try to use the nextoff field here, but on my 1.2.13
  756. kernel, this gives nothing... This may have to do with
  757. the readdir implementation of libc... I also didn't find any trace of
  758. the field in the kernel code itself, So I suspect it is an artifact of libc.
  759. Michael. }
  760. end;
  761. {******************************************************************************
  762. Pipes/Fifo
  763. ******************************************************************************}
  764. Procedure OpenPipe(var F:Text);
  765. begin
  766. case textrec(f).mode of
  767. fmoutput :
  768. if textrec(f).userdata[1]<>P_OUT then
  769. textrec(f).mode:=fmclosed;
  770. fminput :
  771. if textrec(f).userdata[1]<>P_IN then
  772. textrec(f).mode:=fmclosed;
  773. else
  774. textrec(f).mode:=fmclosed;
  775. end;
  776. end;
  777. Procedure IOPipe(var F:text);
  778. begin
  779. case textrec(f).mode of
  780. fmoutput :
  781. begin
  782. { first check if we need something to write, else we may
  783. get a SigPipe when Close() is called (PFV) }
  784. if textrec(f).bufpos>0 then
  785. fpwrite(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  786. end;
  787. fminput :
  788. textrec(f).bufend:=fpread(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  789. end;
  790. textrec(f).bufpos:=0;
  791. end;
  792. Procedure FlushPipe(var F:Text);
  793. begin
  794. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  795. IOPipe(f);
  796. textrec(f).bufpos:=0;
  797. end;
  798. Procedure ClosePipe(var F:text);
  799. begin
  800. textrec(f).mode:=fmclosed;
  801. fpclose(textrec(f).handle);
  802. end;
  803. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  804. {
  805. Sets up a pair of file variables, which act as a pipe. The first one can
  806. be read from, the second one can be written to.
  807. If the operation was unsuccesful, linuxerror is set.
  808. }
  809. var
  810. f_in,f_out : longint;
  811. begin
  812. if not AssignPipe(f_in,f_out) then
  813. begin
  814. AssignPipe:=false;
  815. exit;
  816. end;
  817. { Set up input }
  818. Assign(Pipe_in,'');
  819. Textrec(Pipe_in).Handle:=f_in;
  820. Textrec(Pipe_in).Mode:=fmInput;
  821. Textrec(Pipe_in).userdata[1]:=P_IN;
  822. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  823. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  824. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  825. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  826. { Set up output }
  827. Assign(Pipe_out,'');
  828. Textrec(Pipe_out).Handle:=f_out;
  829. Textrec(Pipe_out).Mode:=fmOutput;
  830. Textrec(Pipe_out).userdata[1]:=P_OUT;
  831. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  832. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  833. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  834. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  835. AssignPipe:=true;
  836. end;
  837. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  838. {
  839. Sets up a pair of file variables, which act as a pipe. The first one can
  840. be read from, the second one can be written to.
  841. If the operation was unsuccesful, linuxerror is set.
  842. }
  843. var
  844. f_in,f_out : longint;
  845. begin
  846. if not AssignPipe(f_in,f_out) then
  847. begin
  848. AssignPipe:=false;
  849. exit;
  850. end;
  851. { Set up input }
  852. Assign(Pipe_in,'');
  853. Filerec(Pipe_in).Handle:=f_in;
  854. Filerec(Pipe_in).Mode:=fmInput;
  855. Filerec(Pipe_in).recsize:=1;
  856. Filerec(Pipe_in).userdata[1]:=P_IN;
  857. { Set up output }
  858. Assign(Pipe_out,'');
  859. Filerec(Pipe_out).Handle:=f_out;
  860. Filerec(Pipe_out).Mode:=fmoutput;
  861. Filerec(Pipe_out).recsize:=1;
  862. Filerec(Pipe_out).userdata[1]:=P_OUT;
  863. AssignPipe:=true;
  864. end;
  865. Procedure PCloseText(Var F:text);
  866. {
  867. May not use @PClose due overloading
  868. }
  869. begin
  870. PClose(f);
  871. end;
  872. Procedure POpen(var F:text;const Prog:String;rw:char);
  873. {
  874. Starts the program in 'Prog' and makes it's input or out put the
  875. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  876. F, will be read from stdin by the program in 'Prog'. The inverse is true
  877. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  878. read from 'f'.
  879. }
  880. var
  881. pipi,
  882. pipo : text;
  883. pid : longint;
  884. pl : ^longint;
  885. pp : ppchar;
  886. begin
  887. LinuxError:=0;
  888. rw:=upcase(rw);
  889. if not (rw in ['R','W']) then
  890. begin
  891. LinuxError:=ESysEnoent;
  892. exit;
  893. end;
  894. AssignPipe(pipi,pipo);
  895. if Linuxerror<>0 then
  896. exit;
  897. pid:=fpfork;
  898. if linuxerror<>0 then
  899. begin
  900. close(pipi);
  901. close(pipo);
  902. exit;
  903. end;
  904. if pid=0 then
  905. begin
  906. { We're in the child }
  907. if rw='W' then
  908. begin
  909. close(pipo);
  910. fpdup2(pipi,input);
  911. close(pipi);
  912. if linuxerror<>0 then
  913. halt(127);
  914. end
  915. else
  916. begin
  917. close(pipi);
  918. fpdup2(pipo,output);
  919. close(pipo);
  920. if linuxerror<>0 then
  921. halt(127);
  922. end;
  923. pp:=createshellargv(prog);
  924. fpExecve(pp^,pp,envp);
  925. halt(127);
  926. end
  927. else
  928. begin
  929. { We're in the parent }
  930. if rw='W' then
  931. begin
  932. close(pipi);
  933. f:=pipo;
  934. textrec(f).bufptr:=@textrec(f).buffer;
  935. end
  936. else
  937. begin
  938. close(pipo);
  939. f:=pipi;
  940. textrec(f).bufptr:=@textrec(f).buffer;
  941. end;
  942. {Save the process ID - needed when closing }
  943. pl:=@(textrec(f).userdata[2]);
  944. pl^:=pid;
  945. textrec(f).closefunc:=@PCloseText;
  946. end;
  947. end;
  948. Procedure POpen(var F:file;const Prog:String;rw:char);
  949. {
  950. Starts the program in 'Prog' and makes it's input or out put the
  951. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  952. F, will be read from stdin by the program in 'Prog'. The inverse is true
  953. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  954. read from 'f'.
  955. }
  956. var
  957. pipi,
  958. pipo : file;
  959. pid : longint;
  960. pl : ^longint;
  961. p,pp : ppchar;
  962. temp : string[255];
  963. begin
  964. LinuxError:=0;
  965. rw:=upcase(rw);
  966. if not (rw in ['R','W']) then
  967. begin
  968. LinuxError:=ESysEnoent;
  969. exit;
  970. end;
  971. AssignPipe(pipi,pipo);
  972. if Linuxerror<>0 then
  973. exit;
  974. pid:=fpfork;
  975. if linuxerror<>0 then
  976. begin
  977. close(pipi);
  978. close(pipo);
  979. exit;
  980. end;
  981. if pid=0 then
  982. begin
  983. { We're in the child }
  984. if rw='W' then
  985. begin
  986. close(pipo);
  987. fpdup2(filerec(pipi).handle,stdinputhandle);
  988. close(pipi);
  989. if linuxerror<>0 then
  990. halt(127);
  991. end
  992. else
  993. begin
  994. close(pipi);
  995. fpdup2(filerec(pipo).handle,stdoutputhandle);
  996. close(pipo);
  997. if linuxerror<>0 then
  998. halt(127);
  999. end;
  1000. getmem(pp,sizeof(pchar)*4);
  1001. temp:='/bin/sh'#0'-c'#0+prog+#0;
  1002. p:=pp;
  1003. p^:=@temp[1];
  1004. inc(p);
  1005. p^:=@temp[9];
  1006. inc(p);
  1007. p^:=@temp[12];
  1008. inc(p);
  1009. p^:=Nil;
  1010. fpExecve(ansistring('/bin/sh'),pp,envp);
  1011. halt(127);
  1012. end
  1013. else
  1014. begin
  1015. { We're in the parent }
  1016. if rw='W' then
  1017. begin
  1018. close(pipi);
  1019. f:=pipo;
  1020. end
  1021. else
  1022. begin
  1023. close(pipo);
  1024. f:=pipi;
  1025. end;
  1026. {Save the process ID - needed when closing }
  1027. pl:=@(filerec(f).userdata[2]);
  1028. pl^:=pid;
  1029. end;
  1030. end;
  1031. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  1032. {
  1033. Starts the program in 'Prog' and makes its input and output the
  1034. other end of two pipes, which are the stdin and stdout of a program
  1035. specified in 'Prog'.
  1036. streamout can be used to write to the program, streamin can be used to read
  1037. the output of the program. See the following diagram :
  1038. Parent Child
  1039. STreamout --> Input
  1040. Streamin <-- Output
  1041. Return value is the process ID of the process being spawned, or -1 in case of failure.
  1042. }
  1043. var
  1044. pipi,
  1045. pipo : text;
  1046. pid : longint;
  1047. pl : ^Longint;
  1048. begin
  1049. LinuxError:=0;
  1050. AssignStream:=-1;
  1051. AssignPipe(streamin,pipo);
  1052. if Linuxerror<>0 then
  1053. exit;
  1054. AssignPipe(pipi,streamout);
  1055. if Linuxerror<>0 then
  1056. exit;
  1057. pid:=fpfork;
  1058. if linuxerror<>0 then
  1059. begin
  1060. close(pipi);
  1061. close(pipo);
  1062. close (streamin);
  1063. close (streamout);
  1064. exit;
  1065. end;
  1066. if pid=0 then
  1067. begin
  1068. { We're in the child }
  1069. { Close what we don't need }
  1070. close(streamout);
  1071. close(streamin);
  1072. fpdup2(pipi,input);
  1073. if linuxerror<>0 then
  1074. halt(127);
  1075. close(pipi);
  1076. fpdup2(pipo,output);
  1077. if linuxerror<>0 then
  1078. halt (127);
  1079. close(pipo);
  1080. Execl(Prog);
  1081. halt(127);
  1082. end
  1083. else
  1084. begin
  1085. { we're in the parent}
  1086. close(pipo);
  1087. close(pipi);
  1088. {Save the process ID - needed when closing }
  1089. pl:=@(textrec(StreamIn).userdata[2]);
  1090. pl^:=pid;
  1091. textrec(StreamIn).closefunc:=@PCloseText;
  1092. {Save the process ID - needed when closing }
  1093. pl:=@(textrec(StreamOut).userdata[2]);
  1094. pl^:=pid;
  1095. textrec(StreamOut).closefunc:=@PCloseText;
  1096. AssignStream:=Pid;
  1097. end;
  1098. end;
  1099. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  1100. {
  1101. Starts the program in 'prog' and makes its input, output and error output the
  1102. other end of three pipes, which are the stdin, stdout and stderr of a program
  1103. specified in 'prog'.
  1104. StreamOut can be used to write to the program, StreamIn can be used to read
  1105. the output of the program, StreamErr reads the error output of the program.
  1106. See the following diagram :
  1107. Parent Child
  1108. StreamOut --> StdIn (input)
  1109. StreamIn <-- StdOut (output)
  1110. StreamErr <-- StdErr (error output)
  1111. }
  1112. var
  1113. PipeIn, PipeOut, PipeErr: text;
  1114. pid: LongInt;
  1115. pl: ^LongInt;
  1116. begin
  1117. LinuxError := 0;
  1118. AssignStream := -1;
  1119. // Assign pipes
  1120. AssignPipe(StreamIn, PipeOut);
  1121. if LinuxError <> 0 then exit;
  1122. AssignPipe(StreamErr, PipeErr);
  1123. if LinuxError <> 0 then begin
  1124. Close(StreamIn);
  1125. Close(PipeOut);
  1126. exit;
  1127. end;
  1128. AssignPipe(PipeIn, StreamOut);
  1129. if LinuxError <> 0 then begin
  1130. Close(StreamIn);
  1131. Close(PipeOut);
  1132. Close(StreamErr);
  1133. Close(PipeErr);
  1134. exit;
  1135. end;
  1136. // Fork
  1137. pid := fpFork;
  1138. if LinuxError <> 0 then begin
  1139. Close(StreamIn);
  1140. Close(PipeOut);
  1141. Close(StreamErr);
  1142. Close(PipeErr);
  1143. Close(PipeIn);
  1144. Close(StreamOut);
  1145. exit;
  1146. end;
  1147. if pid = 0 then begin
  1148. // *** We are in the child ***
  1149. // Close what we don not need
  1150. Close(StreamOut);
  1151. Close(StreamIn);
  1152. Close(StreamErr);
  1153. // Connect pipes
  1154. fpdup2(PipeIn, Input);
  1155. if LinuxError <> 0 then Halt(127);
  1156. Close(PipeIn);
  1157. fpdup2(PipeOut, Output);
  1158. if LinuxError <> 0 then Halt(127);
  1159. Close(PipeOut);
  1160. fpdup2(PipeErr, StdErr);
  1161. if LinuxError <> 0 then Halt(127);
  1162. Close(PipeErr);
  1163. // Execute program
  1164. Execl(Prog);
  1165. Halt(127);
  1166. end else begin
  1167. // *** We are in the parent ***
  1168. Close(PipeErr);
  1169. Close(PipeOut);
  1170. Close(PipeIn);
  1171. // Save the process ID - needed when closing
  1172. pl := @(TextRec(StreamIn).userdata[2]);
  1173. pl^ := pid;
  1174. TextRec(StreamIn).closefunc := @PCloseText;
  1175. // Save the process ID - needed when closing
  1176. pl := @(TextRec(StreamOut).userdata[2]);
  1177. pl^ := pid;
  1178. TextRec(StreamOut).closefunc := @PCloseText;
  1179. // Save the process ID - needed when closing
  1180. pl := @(TextRec(StreamErr).userdata[2]);
  1181. pl^ := pid;
  1182. TextRec(StreamErr).closefunc := @PCloseText;
  1183. AssignStream := pid;
  1184. end;
  1185. end;
  1186. {******************************************************************************
  1187. General information calls
  1188. ******************************************************************************}
  1189. {$ifndef BSD}
  1190. Function GetDomainName:String; { linux only!}
  1191. // domainname is a glibc extension.
  1192. {
  1193. Get machines domain name. Returns empty string if not set.
  1194. }
  1195. Var
  1196. Sysn : utsname;
  1197. begin
  1198. fpUname(Sysn);
  1199. linuxerror:=fpgeterrno;;
  1200. If linuxerror<>0 then
  1201. getdomainname:=''
  1202. else
  1203. getdomainname:=strpas(@Sysn.domain[0]);
  1204. end;
  1205. {$endif}
  1206. Function GetHostName:String;
  1207. {
  1208. Get machines name. Returns empty string if not set.
  1209. }
  1210. Var
  1211. Sysn : utsname;
  1212. begin
  1213. fpuname(Sysn);
  1214. linuxerror:=fpgeterrno;;
  1215. If linuxerror<>0 then
  1216. gethostname:=''
  1217. else
  1218. gethostname:=strpas(@Sysn.nodename[0]);
  1219. end;
  1220. {******************************************************************************
  1221. Signal handling calls
  1222. ******************************************************************************}
  1223. procedure SigRaise(sig:integer);
  1224. begin
  1225. fpKill(fpGetPid,Sig);
  1226. end;
  1227. {******************************************************************************
  1228. IOCtl and Termios calls
  1229. ******************************************************************************}
  1230. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  1231. begin
  1232. {$ifndef BSD}
  1233. TCGetAttr:=fpIOCtl(fd,TCGETS,@tios)>0;
  1234. {$else}
  1235. TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios)>0;
  1236. {$endif}
  1237. end;
  1238. Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
  1239. var
  1240. nr:longint;
  1241. begin
  1242. {$ifndef BSD}
  1243. case OptAct of
  1244. TCSANOW : nr:=TCSETS;
  1245. TCSADRAIN : nr:=TCSETSW;
  1246. TCSAFLUSH : nr:=TCSETSF;
  1247. {$else}
  1248. case OptAct of
  1249. TCSANOW : nr:=TIOCSETA;
  1250. TCSADRAIN : nr:=TIOCSETAW;
  1251. TCSAFLUSH : nr:=TIOCSETAF;
  1252. {$endif}
  1253. else
  1254. begin
  1255. fpsetErrNo(ESysEINVAL);
  1256. TCSetAttr:=false;
  1257. exit;
  1258. end;
  1259. end;
  1260. TCSetAttr:=fpIOCtl(fd,nr,@Tios)>0;
  1261. end;
  1262. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  1263. begin
  1264. {$ifndef BSD}
  1265. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  1266. {$else}
  1267. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  1268. {$endif}
  1269. end;
  1270. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  1271. begin
  1272. {$ifndef BSD}
  1273. CFSetISpeed(tios,speed);
  1274. {$else}
  1275. tios.c_ospeed:=speed;
  1276. {$endif}
  1277. end;
  1278. Procedure CFMakeRaw(var tios:TermIOS);
  1279. begin
  1280. {$ifndef BSD}
  1281. with tios do
  1282. begin
  1283. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  1284. INLCR or IGNCR or ICRNL or IXON));
  1285. c_oflag:=c_oflag and (not OPOST);
  1286. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  1287. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  1288. end;
  1289. {$else}
  1290. with tios do
  1291. begin
  1292. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  1293. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  1294. IGNPAR));
  1295. c_iflag:=c_iflag OR IGNBRK;
  1296. c_oflag:=c_oflag and (not OPOST);
  1297. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  1298. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  1299. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  1300. c_cc[VMIN]:=1;
  1301. c_cc[VTIME]:=0;
  1302. end;
  1303. {$endif}
  1304. end;
  1305. Function TCSendBreak(fd,duration:longint):boolean;
  1306. begin
  1307. {$ifndef BSD}
  1308. TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(duration))>0;
  1309. {$else}
  1310. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,0)>0;
  1311. {$endif}
  1312. end;
  1313. Function TCSetPGrp(fd,id:longint):boolean;
  1314. begin
  1315. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id))>0;
  1316. end;
  1317. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  1318. begin
  1319. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id)>0;
  1320. end;
  1321. Function TCDrain(fd:longint):boolean;
  1322. begin
  1323. {$ifndef BSD}
  1324. TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1))>0;
  1325. {$else}
  1326. TCDrain:=fpIOCtl(fd,TIOCDRAIN,0)>0; {Should set timeout to 1 first?}
  1327. {$endif}
  1328. end;
  1329. Function TCFlow(fd,act:longint):boolean;
  1330. begin
  1331. {$ifndef BSD}
  1332. TCFlow:=fpIOCtl(fd,TCXONC,pointer(act))>0;
  1333. {$else}
  1334. case act OF
  1335. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,0)>0;
  1336. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,0)>0;
  1337. TCIOFF : {N/I}
  1338. end;
  1339. {$endif}
  1340. end;
  1341. Function TCFlush(fd,qsel:longint):boolean;
  1342. begin
  1343. {$ifndef BSD}
  1344. TCFlush:=fpIOCtl(fd,TCFLSH,pointer(qsel))>0;
  1345. {$else}
  1346. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel))>0;
  1347. {$endif}
  1348. end;
  1349. Function IsATTY(Handle:Longint):Boolean;
  1350. {
  1351. Check if the filehandle described by 'handle' is a TTY (Terminal)
  1352. }
  1353. var
  1354. t : Termios;
  1355. begin
  1356. IsAtty:=TCGetAttr(Handle,t);
  1357. end;
  1358. Function IsATTY(f: text):Boolean;
  1359. {
  1360. Idem as previous, only now for text variables.
  1361. }
  1362. begin
  1363. IsATTY:=IsaTTY(textrec(f).handle);
  1364. end;
  1365. function TTYName(Handle:Longint):string;
  1366. {
  1367. Return the name of the current tty described by handle f.
  1368. returns empty string in case of an error.
  1369. }
  1370. var
  1371. mydev,
  1372. myino : longint;
  1373. st : stat;
  1374. function mysearch(n:string): boolean;
  1375. {searches recursively for the device in the directory given by n,
  1376. returns true if found and sets the name of the device in ttyname}
  1377. var dirstream : pdir;
  1378. d : pdirent;
  1379. name : string;
  1380. st : stat;
  1381. begin
  1382. dirstream:=fpopendir(n);
  1383. if (linuxerror<>0) then
  1384. exit;
  1385. d:=fpReaddir(dirstream^);
  1386. while (d<>nil) do
  1387. begin
  1388. name:=n+'/'+strpas(@(d^.d_name));
  1389. fpstat(name,st);
  1390. if linuxerror=0 then
  1391. begin
  1392. if (fpISDIR(st.st_mode)) and { if it is a directory }
  1393. (strpas(@(d^.d_name))<>'.') and { but not ., .. and fd subdirs }
  1394. (strpas(@(d^.d_name))<>'..') and
  1395. (strpas(@(d^.d_name))<>'') and
  1396. (strpas(@(d^.d_name))<>'fd') then
  1397. begin {we found a directory, search inside it}
  1398. if mysearch(name) then
  1399. begin {the device is here}
  1400. fpclosedir(dirstream^); {then don't continue searching}
  1401. mysearch:=true;
  1402. exit;
  1403. end;
  1404. end
  1405. else if (d^.d_fileno=myino) and (st.st_dev=mydev) then
  1406. begin
  1407. fpclosedir(dirstream^);
  1408. ttyname:=name;
  1409. mysearch:=true;
  1410. exit;
  1411. end;
  1412. end;
  1413. d:=fpReaddir(dirstream^);
  1414. end;
  1415. fpclosedir(dirstream^);
  1416. mysearch:=false;
  1417. end;
  1418. begin
  1419. TTYName:='';
  1420. fpfstat(handle,st);
  1421. if (fpgeterrno<>0) and isatty (handle) then
  1422. exit;
  1423. mydev:=st.st_dev;
  1424. myino:=st.st_ino;
  1425. mysearch('/dev');
  1426. end;
  1427. function TTYName(var F:Text):string;
  1428. {
  1429. Idem as previous, only now for text variables;
  1430. }
  1431. begin
  1432. TTYName:=TTYName(textrec(f).handle);
  1433. end;
  1434. {******************************************************************************
  1435. Utility calls
  1436. ******************************************************************************}
  1437. Function Octal(l:longint):longint;
  1438. {
  1439. Convert an octal specified number to decimal;
  1440. }
  1441. var
  1442. octnr,
  1443. oct : longint;
  1444. begin
  1445. octnr:=0;
  1446. oct:=0;
  1447. while (l>0) do
  1448. begin
  1449. oct:=oct or ((l mod 10) shl octnr);
  1450. l:=l div 10;
  1451. inc(octnr,3);
  1452. end;
  1453. Octal:=oct;
  1454. end;
  1455. Function StringToPPChar(S: PChar):ppchar;
  1456. var
  1457. nr : longint;
  1458. Buf : ^char;
  1459. p : ppchar;
  1460. begin
  1461. buf:=s;
  1462. nr:=0;
  1463. while(buf^<>#0) do
  1464. begin
  1465. while (buf^ in [' ',#9,#10]) do
  1466. inc(buf);
  1467. inc(nr);
  1468. while not (buf^ in [' ',#0,#9,#10]) do
  1469. inc(buf);
  1470. end;
  1471. getmem(p,nr*4);
  1472. StringToPPChar:=p;
  1473. if p=nil then
  1474. begin
  1475. LinuxError:=ESysEnomem;
  1476. exit;
  1477. end;
  1478. buf:=s;
  1479. while (buf^<>#0) do
  1480. begin
  1481. while (buf^ in [' ',#9,#10]) do
  1482. begin
  1483. buf^:=#0;
  1484. inc(buf);
  1485. end;
  1486. p^:=buf;
  1487. inc(p);
  1488. p^:=nil;
  1489. while not (buf^ in [' ',#0,#9,#10]) do
  1490. inc(buf);
  1491. end;
  1492. end;
  1493. {$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
  1494. {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
  1495. {$I fexpand.inc}
  1496. {$UNDEF FPC_FEXPAND_GETENVPCHAR}
  1497. {$UNDEF FPC_FEXPAND_TILDE}
  1498. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  1499. {
  1500. Searches for a file 'path' in the list of direcories in 'dirlist'.
  1501. returns an empty string if not found. Wildcards are NOT allowed.
  1502. If dirlist is empty, it is set to '.'
  1503. }
  1504. Var
  1505. NewDir : PathStr;
  1506. p1 : Longint;
  1507. Info : Stat;
  1508. Begin
  1509. {Replace ':' with ';'}
  1510. for p1:=1to length(dirlist) do
  1511. if dirlist[p1]=':' then
  1512. dirlist[p1]:=';';
  1513. {Check for WildCards}
  1514. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  1515. FSearch:='' {No wildcards allowed in these things.}
  1516. Else
  1517. Begin
  1518. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  1519. Repeat
  1520. p1:=Pos(';',DirList);
  1521. If p1=0 Then
  1522. p1:=255;
  1523. NewDir:=Copy(DirList,1,P1 - 1);
  1524. if NewDir[Length(NewDir)]<>'/' then
  1525. NewDir:=NewDir+'/';
  1526. NewDir:=NewDir+Path;
  1527. Delete(DirList,1,p1);
  1528. if FpStat(NewDir,Info)>=0 then
  1529. Begin
  1530. If Pos('./',NewDir)=1 Then
  1531. Delete(NewDir,1,2);
  1532. {DOS strips off an initial .\}
  1533. End
  1534. Else
  1535. NewDir:='';
  1536. Until (DirList='') or (Length(NewDir) > 0);
  1537. FSearch:=NewDir;
  1538. End;
  1539. End;
  1540. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  1541. Var
  1542. DotPos,SlashPos,i : longint;
  1543. Begin
  1544. SlashPos:=0;
  1545. DotPos:=256;
  1546. i:=Length(Path);
  1547. While (i>0) and (SlashPos=0) Do
  1548. Begin
  1549. If (DotPos=256) and (Path[i]='.') Then
  1550. begin
  1551. DotPos:=i;
  1552. end;
  1553. If (Path[i]='/') Then
  1554. SlashPos:=i;
  1555. Dec(i);
  1556. End;
  1557. Ext:=Copy(Path,DotPos,255);
  1558. Dir:=Copy(Path,1,SlashPos);
  1559. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  1560. End;
  1561. Function Dirname(Const path:pathstr):pathstr;
  1562. {
  1563. This function returns the directory part of a complete path.
  1564. Unless the directory is root '/', The last character is not
  1565. a slash.
  1566. }
  1567. var
  1568. Dir : PathStr;
  1569. Name : NameStr;
  1570. Ext : ExtStr;
  1571. begin
  1572. FSplit(Path,Dir,Name,Ext);
  1573. if length(Dir)>1 then
  1574. Delete(Dir,length(Dir),1);
  1575. DirName:=Dir;
  1576. end;
  1577. Function StringToPPChar(Var S:String):ppchar;
  1578. {
  1579. Create a PPChar to structure of pchars which are the arguments specified
  1580. in the string S. Especially usefull for creating an ArgV for Exec-calls
  1581. Note that the string S is destroyed by this call.
  1582. }
  1583. begin
  1584. S:=S+#0;
  1585. StringToPPChar:=StringToPPChar(@S[1]);
  1586. end;
  1587. Function StringToPPChar(Var S:AnsiString):ppchar;
  1588. {
  1589. Create a PPChar to structure of pchars which are the arguments specified
  1590. in the string S. Especially usefull for creating an ArgV for Exec-calls
  1591. }
  1592. begin
  1593. StringToPPChar:=StringToPPChar(PChar(S));
  1594. end;
  1595. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  1596. {
  1597. This function returns the filename part of a complete path. If suf is
  1598. supplied, it is cut off the filename.
  1599. }
  1600. var
  1601. Dir : PathStr;
  1602. Name : NameStr;
  1603. Ext : ExtStr;
  1604. begin
  1605. FSplit(Path,Dir,Name,Ext);
  1606. if Suf<>Ext then
  1607. Name:=Name+Ext;
  1608. BaseName:=Name;
  1609. end;
  1610. Function FNMatch(const Pattern,Name:string):Boolean;
  1611. Var
  1612. LenPat,LenName : longint;
  1613. Function DoFNMatch(i,j:longint):Boolean;
  1614. Var
  1615. Found : boolean;
  1616. Begin
  1617. Found:=true;
  1618. While Found and (i<=LenPat) Do
  1619. Begin
  1620. Case Pattern[i] of
  1621. '?' : Found:=(j<=LenName);
  1622. '*' : Begin
  1623. {find the next character in pattern, different of ? and *}
  1624. while Found and (i<LenPat) do
  1625. begin
  1626. inc(i);
  1627. case Pattern[i] of
  1628. '*' : ;
  1629. '?' : begin
  1630. inc(j);
  1631. Found:=(j<=LenName);
  1632. end;
  1633. else
  1634. Found:=false;
  1635. end;
  1636. end;
  1637. {Now, find in name the character which i points to, if the * or ?
  1638. wasn't the last character in the pattern, else, use up all the
  1639. chars in name}
  1640. Found:=true;
  1641. if (i<=LenPat) then
  1642. begin
  1643. repeat
  1644. {find a letter (not only first !) which maches pattern[i]}
  1645. while (j<=LenName) and (name[j]<>pattern[i]) do
  1646. inc (j);
  1647. if (j<LenName) then
  1648. begin
  1649. if DoFnMatch(i+1,j+1) then
  1650. begin
  1651. i:=LenPat;
  1652. j:=LenName;{we can stop}
  1653. Found:=true;
  1654. end
  1655. else
  1656. inc(j);{We didn't find one, need to look further}
  1657. end;
  1658. until (j>=LenName);
  1659. end
  1660. else
  1661. j:=LenName;{we can stop}
  1662. end;
  1663. else {not a wildcard character in pattern}
  1664. Found:=(j<=LenName) and (pattern[i]=name[j]);
  1665. end;
  1666. inc(i);
  1667. inc(j);
  1668. end;
  1669. DoFnMatch:=Found and (j>LenName);
  1670. end;
  1671. Begin {start FNMatch}
  1672. LenPat:=Length(Pattern);
  1673. LenName:=Length(Name);
  1674. FNMatch:=DoFNMatch(1,1);
  1675. End;
  1676. Procedure Globfree(var p : pglob);
  1677. {
  1678. Release memory occupied by pglob structure, and names in it.
  1679. sets p to nil.
  1680. }
  1681. var
  1682. temp : pglob;
  1683. begin
  1684. while assigned(p) do
  1685. begin
  1686. temp:=p^.next;
  1687. if assigned(p^.name) then
  1688. freemem(p^.name);
  1689. dispose(p);
  1690. p:=temp;
  1691. end;
  1692. end;
  1693. Function Glob(Const path:pathstr):pglob;
  1694. {
  1695. Fills a tglob structure with entries matching path,
  1696. and returns a pointer to it. Returns nil on error,
  1697. linuxerror is set accordingly.
  1698. }
  1699. var
  1700. temp,
  1701. temp2 : string[255];
  1702. thedir : pdir;
  1703. buffer : pdirent;
  1704. root,
  1705. current : pglob;
  1706. begin
  1707. { Get directory }
  1708. temp:=dirname(path);
  1709. if temp='' then
  1710. temp:='.';
  1711. temp:=temp+#0;
  1712. thedir:=fpopendir(@temp[1]);
  1713. if thedir=nil then
  1714. begin
  1715. glob:=nil;
  1716. linuxerror:=fpgeterrno;;
  1717. exit;
  1718. end;
  1719. temp:=basename(path,''); { get the pattern }
  1720. if thedir^.dd_fd<0 then
  1721. begin
  1722. linuxerror:=fpgeterrno;;
  1723. glob:=nil;
  1724. exit;
  1725. end;
  1726. {get the entries}
  1727. root:=nil;
  1728. current:=nil;
  1729. repeat
  1730. buffer:=fpreaddir(thedir^);
  1731. if buffer=nil then
  1732. break;
  1733. temp2:=strpas(@(buffer^.d_name[0]));
  1734. if fnmatch(temp,temp2) then
  1735. begin
  1736. if root=nil then
  1737. begin
  1738. new(root);
  1739. current:=root;
  1740. end
  1741. else
  1742. begin
  1743. new(current^.next);
  1744. current:=current^.next;
  1745. end;
  1746. if current=nil then
  1747. begin
  1748. linuxerror:=ESysENOMEM;
  1749. globfree(root);
  1750. break;
  1751. end;
  1752. current^.next:=nil;
  1753. getmem(current^.name,length(temp2)+1);
  1754. if current^.name=nil then
  1755. begin
  1756. linuxerror:=ESysENOMEM;
  1757. globfree(root);
  1758. break;
  1759. end;
  1760. move(buffer^.d_name[0],current^.name^,length(temp2)+1);
  1761. end;
  1762. until false;
  1763. fpclosedir(thedir^);
  1764. glob:=root;
  1765. end;
  1766. Function GetFS (var T:Text):longint;
  1767. {
  1768. Get File Descriptor of a text file.
  1769. }
  1770. begin
  1771. if textrec(t).mode=fmclosed then
  1772. exit(-1)
  1773. else
  1774. GETFS:=textrec(t).Handle
  1775. end;
  1776. Function GetFS(Var F:File):longint;
  1777. {
  1778. Get File Descriptor of an unTyped file.
  1779. }
  1780. begin
  1781. { Handle and mode are on the same place in textrec and filerec. }
  1782. if filerec(f).mode=fmclosed then
  1783. exit(-1)
  1784. else
  1785. GETFS:=filerec(f).Handle
  1786. end;
  1787. {--------------------------------
  1788. Stat.Mode Macro's
  1789. --------------------------------}
  1790. Function S_ISLNK(m:word):boolean;
  1791. {
  1792. Check mode field of inode for link.
  1793. }
  1794. begin
  1795. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  1796. end;
  1797. Function S_ISSOCK(m:word):boolean;
  1798. {
  1799. Check mode field of inode for socket.
  1800. }
  1801. begin
  1802. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  1803. end;
  1804. Initialization
  1805. InitLocalTime;
  1806. finalization
  1807. DoneLocalTime;
  1808. End.
  1809. {
  1810. $Log$
  1811. Revision 1.35 2003-09-16 21:46:27 marco
  1812. * small fixes, checking things on linux
  1813. Revision 1.34 2003/09/16 20:52:24 marco
  1814. * small cleanups. Mostly killing of already commented code in unix etc
  1815. Revision 1.33 2003/09/16 16:13:56 marco
  1816. * fdset functions renamed to fp<posix name>
  1817. Revision 1.32 2003/09/15 20:08:49 marco
  1818. * small fixes. FreeBSD now cycles
  1819. Revision 1.31 2003/09/14 20:15:01 marco
  1820. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  1821. Revision 1.30 2003/07/08 21:23:24 peter
  1822. * sparc fixes
  1823. Revision 1.29 2003/05/30 19:58:40 marco
  1824. * Getting NetBSD/i386 to compile.
  1825. Revision 1.28 2003/05/29 19:16:16 marco
  1826. * fixed a small *BSD gotcha
  1827. Revision 1.27 2003/05/24 20:39:54 jonas
  1828. * fixed ExitCode translation in WaitProcess for Linux and Darwin (and
  1829. probably other BSD's as well)
  1830. Revision 1.26 2003/03/11 08:27:59 michael
  1831. * stringtoppchar should use tabs instead of backspace as delimiter
  1832. Revision 1.25 2002/12/18 16:50:39 marco
  1833. * Unix RTL generic parts. Linux working, *BSD will follow shortly
  1834. Revision 1.24 2002/09/07 16:01:28 peter
  1835. * old logs removed and tabs fixed
  1836. Revision 1.23 2002/08/06 13:30:46 sg
  1837. * replaced some Longints with Cardinals, to mach the C headers
  1838. * updated the termios record
  1839. Revision 1.22 2002/03/05 20:04:25 michael
  1840. + Patch from Sebastian for FCNTL call
  1841. Revision 1.21 2002/01/02 12:22:54 marco
  1842. * Removed ifdef arround getepoch.
  1843. }