linux.pp 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY;without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit Linux;
  13. Interface
  14. { Get Types and Constants }
  15. {$i sysconst.inc}
  16. {$i systypes.inc}
  17. { Get System call numbers and error-numbers}
  18. {$i sysnr.inc}
  19. {$i errno.inc}
  20. var
  21. ErrNo,
  22. LinuxError : Longint;
  23. {********************
  24. Process
  25. ********************}
  26. Const
  27. { For getting/setting priority }
  28. Prio_Process = 0;
  29. Prio_PGrp = 1;
  30. Prio_User = 2;
  31. {********************
  32. File
  33. ********************}
  34. Const
  35. P_IN = 1;
  36. P_OUT = 2;
  37. Const
  38. LOCK_SH = 1;
  39. LOCK_EX = 2;
  40. LOCK_UN = 8;
  41. LOCK_NB = 4;
  42. Type
  43. Tpipe = array[1..2] of longint;
  44. pglob = ^tglob;
  45. tglob = record
  46. name : pchar;
  47. next : pglob;
  48. end;
  49. ComStr = String[255];
  50. PathStr = String[255];
  51. DirStr = String[255];
  52. NameStr = String[255];
  53. ExtStr = String[255];
  54. const
  55. { For testing access rights }
  56. R_OK = 4;
  57. W_OK = 2;
  58. X_OK = 1;
  59. F_OK = 0;
  60. { For File control mechanism }
  61. F_GetFd = 1;
  62. F_SetFd = 2;
  63. F_GetFl = 3;
  64. F_SetFl = 4;
  65. F_GetLk = 5;
  66. F_SetLk = 6;
  67. F_SetLkW = 7;
  68. F_GetOwn = 8;
  69. F_SetOwn = 9;
  70. {********************
  71. Signal
  72. ********************}
  73. Const
  74. { For sending a signal }
  75. SA_NOCLDSTOP = 1;
  76. SA_SHIRQ = $04000000;
  77. SA_STACK = $08000000;
  78. SA_RESTART = $10000000;
  79. SA_INTERRUPT = $20000000;
  80. SA_NOMASK = $40000000;
  81. SA_ONESHOT = $80000000;
  82. SIG_BLOCK = 0;
  83. SIG_UNBLOCK = 1;
  84. SIG_SETMASK = 2;
  85. SIG_DFL = 0 ;
  86. SIG_IGN = 1 ;
  87. SIG_ERR = -1 ;
  88. SIGHUP = 1;
  89. SIGINT = 2;
  90. SIGQUIT = 3;
  91. SIGILL = 4;
  92. SIGTRAP = 5;
  93. SIGABRT = 6;
  94. SIGIOT = 6;
  95. SIGBUS = 7;
  96. SIGFPE = 8;
  97. SIGKILL = 9;
  98. SIGUSR1 = 10;
  99. SIGSEGV = 11;
  100. SIGUSR2 = 12;
  101. SIGPIPE = 13;
  102. SIGALRM = 14;
  103. SIGTerm = 15;
  104. SIGSTKFLT = 16;
  105. SIGCHLD = 17;
  106. SIGCONT = 18;
  107. SIGSTOP = 19;
  108. SIGTSTP = 20;
  109. SIGTTIN = 21;
  110. SIGTTOU = 22;
  111. SIGURG = 23;
  112. SIGXCPU = 24;
  113. SIGXFSZ = 25;
  114. SIGVTALRM = 26;
  115. SIGPROF = 27;
  116. SIGWINCH = 28;
  117. SIGIO = 29;
  118. SIGPOLL = SIGIO;
  119. SIGPWR = 30;
  120. SIGUNUSED = 31;
  121. Type
  122. SignalHandler = Procedure(Sig : LongInt);cdecl;
  123. PSignalHandler = ^SignalHandler;
  124. SignalRestorer = Procedure;cdecl;
  125. PSignalRestorer = ^SignalRestorer;
  126. SigSet = Integer;
  127. PSigSet = ^SigSet;
  128. SigActionRec = packed record
  129. Sa_Handler : SignalHandler;
  130. Sa_Mask : longint;
  131. Sa_Flags : Integer;
  132. Sa_restorer : SignalRestorer;{ Obsolete - Don't use }
  133. end;
  134. PSigActionRec = ^SigActionRec;
  135. {********************
  136. IOCtl(TermIOS)
  137. ********************}
  138. Const
  139. { Amount of Control Chars }
  140. NCCS = 19;
  141. NCC = 8;
  142. { For Terminal handling }
  143. TCGETS = $5401;
  144. TCSETS = $5402;
  145. TCSETSW = $5403;
  146. TCSETSF = $5404;
  147. TCGETA = $5405;
  148. TCSETA = $5406;
  149. TCSETAW = $5407;
  150. TCSETAF = $5408;
  151. TCSBRK = $5409;
  152. TCXONC = $540A;
  153. TCFLSH = $540B;
  154. TIOCEXCL = $540C;
  155. TIOCNXCL = $540D;
  156. TIOCSCTTY = $540E;
  157. TIOCGPGRP = $540F;
  158. TIOCSPGRP = $5410;
  159. TIOCOUTQ = $5411;
  160. TIOCSTI = $5412;
  161. TIOCGWINSZ = $5413;
  162. TIOCSWINSZ = $5414;
  163. TIOCMGET = $5415;
  164. TIOCMBIS = $5416;
  165. TIOCMBIC = $5417;
  166. TIOCMSET = $5418;
  167. TIOCGSOFTCAR = $5419;
  168. TIOCSSOFTCAR = $541A;
  169. FIONREAD = $541B;
  170. TIOCINQ = FIONREAD;
  171. TIOCLINUX = $541C;
  172. TIOCCONS = $541D;
  173. TIOCGSERIAL = $541E;
  174. TIOCSSERIAL = $541F;
  175. TIOCPKT = $5420;
  176. FIONBIO = $5421;
  177. TIOCNOTTY = $5422;
  178. TIOCSETD = $5423;
  179. TIOCGETD = $5424;
  180. TCSBRKP = $5425;
  181. TIOCTTYGSTRUCT = $5426;
  182. FIONCLEX = $5450;
  183. FIOCLEX = $5451;
  184. FIOASYNC = $5452;
  185. TIOCSERCONFIG = $5453;
  186. TIOCSERGWILD = $5454;
  187. TIOCSERSWILD = $5455;
  188. TIOCGLCKTRMIOS = $5456;
  189. TIOCSLCKTRMIOS = $5457;
  190. TIOCSERGSTRUCT = $5458;
  191. TIOCSERGETLSR = $5459;
  192. TIOCSERGETMULTI = $545A;
  193. TIOCSERSETMULTI = $545B;
  194. TIOCMIWAIT = $545C;
  195. TIOCGICOUNT = $545D;
  196. TIOCPKT_DATA = 0;
  197. TIOCPKT_FLUSHREAD = 1;
  198. TIOCPKT_FLUSHWRITE = 2;
  199. TIOCPKT_STOP = 4;
  200. TIOCPKT_START = 8;
  201. TIOCPKT_NOSTOP = 16;
  202. TIOCPKT_DOSTOP = 32;
  203. Type
  204. winsize = packed record
  205. ws_row,
  206. ws_col,
  207. ws_xpixel,
  208. ws_ypixel : word;
  209. end;
  210. TWinSize=winsize;
  211. Termio = packed record
  212. c_iflag, { input mode flags }
  213. c_oflag, { output mode flags }
  214. c_cflag, { control mode flags }
  215. c_lflag : Word; { local mode flags }
  216. c_line : Word; { line discipline - careful, only High byte in use}
  217. c_cc : array [0..NCC-1] of char;{ control characters }
  218. end;
  219. TTermio=Termio;
  220. Termios = packed record
  221. c_iflag,
  222. c_oflag,
  223. c_cflag,
  224. c_lflag : longint;
  225. c_line : char;
  226. c_cc : array[0..NCCS-1] of byte;
  227. end;
  228. TTermios=Termios;
  229. const
  230. InitCC:array[0..NCCS-1] of byte=(3,34,177,25,4,0,1,0,21,23,32,0,22,17,27,26,0,0,0);
  231. const
  232. {c_cc characters}
  233. VINTR = 0;
  234. VQUIT = 1;
  235. VERASE = 2;
  236. VKILL = 3;
  237. VEOF = 4;
  238. VTIME = 5;
  239. VMIN = 6;
  240. VSWTC = 7;
  241. VSTART = 8;
  242. VSTOP = 9;
  243. VSUSP = 10;
  244. VEOL = 11;
  245. VREPRINT = 12;
  246. VDISCARD = 13;
  247. VWERASE = 14;
  248. VLNEXT = 15;
  249. VEOL2 = 16;
  250. {c_iflag bits}
  251. IGNBRK = $0000001;
  252. BRKINT = $0000002;
  253. IGNPAR = $0000004;
  254. PARMRK = $0000008;
  255. INPCK = $0000010;
  256. ISTRIP = $0000020;
  257. INLCR = $0000040;
  258. IGNCR = $0000080;
  259. ICRNL = $0000100;
  260. IUCLC = $0000200;
  261. IXON = $0000400;
  262. IXANY = $0000800;
  263. IXOFF = $0001000;
  264. IMAXBEL = $0002000;
  265. {c_oflag bits}
  266. OPOST = $0000001;
  267. OLCUC = $0000002;
  268. ONLCR = $0000004;
  269. OCRNL = $0000008;
  270. ONOCR = $0000010;
  271. ONLRET = $0000020;
  272. OFILL = $0000040;
  273. OFDEL = $0000080;
  274. NLDLY = $0000100;
  275. NL0 = $0000000;
  276. NL1 = $0000100;
  277. CRDLY = $0000600;
  278. CR0 = $0000000;
  279. CR1 = $0000200;
  280. CR2 = $0000400;
  281. CR3 = $0000600;
  282. TABDLY = $0001800;
  283. TAB0 = $0000000;
  284. TAB1 = $0000800;
  285. TAB2 = $0001000;
  286. TAB3 = $0001800;
  287. XTABS = $0001800;
  288. BSDLY = $0002000;
  289. BS0 = $0000000;
  290. BS1 = $0002000;
  291. VTDLY = $0004000;
  292. VT0 = $0000000;
  293. VT1 = $0004000;
  294. FFDLY = $0008000;
  295. FF0 = $0000000;
  296. FF1 = $0008000;
  297. {c_cflag bits}
  298. CBAUD = $000100F;
  299. B0 = $0000000;
  300. B50 = $0000001;
  301. B75 = $0000002;
  302. B110 = $0000003;
  303. B134 = $0000004;
  304. B150 = $0000005;
  305. B200 = $0000006;
  306. B300 = $0000007;
  307. B600 = $0000008;
  308. B1200 = $0000009;
  309. B1800 = $000000A;
  310. B2400 = $000000B;
  311. B4800 = $000000C;
  312. B9600 = $000000D;
  313. B19200 = $000000E;
  314. B38400 = $000000F;
  315. EXTA = B19200;
  316. EXTB = B38400;
  317. CSIZE = $0000030;
  318. CS5 = $0000000;
  319. CS6 = $0000010;
  320. CS7 = $0000020;
  321. CS8 = $0000030;
  322. CSTOPB = $0000040;
  323. CREAD = $0000080;
  324. PARENB = $0000100;
  325. PARODD = $0000200;
  326. HUPCL = $0000400;
  327. CLOCAL = $0000800;
  328. CBAUDEX = $0001000;
  329. B57600 = $0001001;
  330. B115200 = $0001002;
  331. B230400 = $0001003;
  332. B460800 = $0001004;
  333. CIBAUD = $100F0000;
  334. CMSPAR = $40000000;
  335. CRTSCTS = $80000000;
  336. {c_lflag bits}
  337. ISIG = $0000001;
  338. ICANON = $0000002;
  339. XCASE = $0000004;
  340. ECHO = $0000008;
  341. ECHOE = $0000010;
  342. ECHOK = $0000020;
  343. ECHONL = $0000040;
  344. NOFLSH = $0000080;
  345. TOSTOP = $0000100;
  346. ECHOCTL = $0000200;
  347. ECHOPRT = $0000400;
  348. ECHOKE = $0000800;
  349. FLUSHO = $0001000;
  350. PENDIN = $0004000;
  351. IEXTEN = $0008000;
  352. {c_line bits}
  353. TIOCM_LE = $001;
  354. TIOCM_DTR = $002;
  355. TIOCM_RTS = $004;
  356. TIOCM_ST = $008;
  357. TIOCM_SR = $010;
  358. TIOCM_CTS = $020;
  359. TIOCM_CAR = $040;
  360. TIOCM_RNG = $080;
  361. TIOCM_DSR = $100;
  362. TIOCM_CD = TIOCM_CAR;
  363. TIOCM_RI = TIOCM_RNG;
  364. TIOCM_OUT1 = $2000;
  365. TIOCM_OUT2 = $4000;
  366. {TCSetAttr}
  367. TCSANOW = 0;
  368. TCSADRAIN = 1;
  369. TCSAFLUSH = 2;
  370. {TCFlow}
  371. TCOOFF = 0;
  372. TCOON = 1;
  373. TCIOFF = 2;
  374. TCION = 3;
  375. {TCFlush}
  376. TCIFLUSH = 0;
  377. TCOFLUSH = 1;
  378. TCIOFLUSH = 2;
  379. {********************
  380. Info
  381. ********************}
  382. Type
  383. UTimBuf = packed record
  384. actime,modtime : Longint;
  385. end;
  386. UTimeBuf=UTimBuf;
  387. TUTimeBuf=UTimeBuf;
  388. PUTimeBuf=^UTimeBuf;
  389. TSysinfo = packed record
  390. uptime : longint;
  391. loads : array[1..3] of longint;
  392. totalram,
  393. freeram,
  394. sharedram,
  395. bufferram,
  396. totalswap,
  397. freeswap : longint;
  398. procs : integer;
  399. s : string[18];
  400. end;
  401. PSysInfo = ^TSysInfo;
  402. {******************************************************************************
  403. Procedure/Functions
  404. ******************************************************************************}
  405. Function SysCall(callnr:longint;var regs:SysCallregs):longint;
  406. {**************************
  407. Time/Date Handling
  408. ***************************}
  409. Function GetEpochTime:longint;
  410. Procedure GetTimeOfDay(var tv:timeval;var tz:timezone);
  411. Procedure SetTimeOfDay(Const tv:timeval;const tz:timezone);
  412. Function GetTimeOfDay: longint;
  413. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  414. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  415. Procedure GetTime(Var Hour,Minute,Second:Word);
  416. Procedure GetDate(Var Year,Month,Day:Word);
  417. { For compatibility with earlier versions }
  418. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Integer);
  419. Function LocalToEpoch(year,month,day,hour,minute,second:Integer):Longint;
  420. Procedure GetTime(Var Hour,Minute,Second:Integer);
  421. Procedure GetDate(Var Year,Month,Day:Integer);
  422. {**************************
  423. Process Handling
  424. ***************************}
  425. function CreateShellArgV(const prog:string):ppchar;
  426. Procedure Execve(Path:pathstr;args:ppchar;ep:ppchar);
  427. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  428. Procedure Execv(const path:pathstr;args:ppchar);
  429. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  430. Procedure Execl(const Todo:string);
  431. Procedure Execle(Todo:string;Ep:ppchar);
  432. Procedure Execlp(Todo:string;Ep:ppchar);
  433. Function Shell(const Command:String):Longint;
  434. Function Fork:longint;
  435. Function WaitPid(Pid:longint;Status:pointer;Options:Integer):Longint;
  436. Procedure Nice(N:integer);
  437. Function GetPriority(Which,Who:Integer):integer;
  438. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  439. Function GetPid:LongInt;
  440. Function GetPPid:LongInt;
  441. Function GetUid:Longint;
  442. Function GetEUid:Longint;
  443. Function GetGid:Longint;
  444. Function GetEGid:Longint;
  445. {**************************
  446. File Handling
  447. ***************************}
  448. Function fdOpen(pathname:string;flags:longint):longint;
  449. Function fdOpen(pathname:string;flags,mode:longint):longint;
  450. Function fdOpen(pathname:pchar;flags:longint):longint;
  451. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  452. Function fdClose(fd:longint):boolean;
  453. Function fdRead(fd:longint;var buf;size:longint):longint;
  454. Function fdWrite(fd:longint;var buf;size:longint):longint;
  455. Function fdTruncate(fd,size:longint):boolean;
  456. Function fdSeek (fd,pos,seektype :longint): longint;
  457. Function fdFlush (fd : Longint) : Boolean;
  458. Function Link(OldPath,NewPath:pathstr):boolean;
  459. Function SymLink(OldPath,NewPath:pathstr):boolean;
  460. Function UnLink(Path:pathstr):boolean;
  461. Function UnLink(Path:pchar):Boolean;
  462. Function FReName (OldName,NewName : Pchar) : Boolean;
  463. Function FReName (OldName,NewName : String) : Boolean;
  464. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  465. Function Chmod(path:pathstr;Newmode:longint):boolean;
  466. Function Utime(path:pathstr;utim:utimebuf):boolean;
  467. Function Access(Path:Pathstr ;mode:integer):boolean;
  468. Function Umask(Mask:Integer):integer;
  469. Function Flock (fd,mode : longint) : boolean;
  470. Function Flock (var T : text;mode : longint) : boolean;
  471. Function Flock (var F : File;mode : longint) : boolean;
  472. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  473. Function FStat(Fd:longint;Var Info:stat):Boolean;
  474. Function FStat(var F:Text;Var Info:stat):Boolean;
  475. Function FStat(var F:File;Var Info:stat):Boolean;
  476. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  477. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  478. Function FSStat(Fd: Longint;Var Info:statfs):Boolean;
  479. Function Fcntl(Fd:Text;Cmd:Integer):integer;
  480. Procedure Fcntl(Fd:Text;Cmd:Integer;Arg:Longint);
  481. Function Dup(oldfile,newfile:longint):Boolean;
  482. Function Dup(var oldfile,newfile:text):Boolean;
  483. Function Dup(var oldfile,newfile:file):Boolean;
  484. Function Dup2(oldfile,newfile:longint):Boolean;
  485. Function Dup2(var oldfile,newfile:text):Boolean;
  486. Function Dup2(var oldfile,newfile:file):Boolean;
  487. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  488. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  489. Function SelectText(var T:Text;TimeOut :PTimeVal):Longint;
  490. {**************************
  491. Directory Handling
  492. ***************************}
  493. Function OpenDir(f:pchar):pdir;
  494. Function OpenDir(f: String):pdir;
  495. function CloseDir(p:pdir):integer;
  496. Function ReadDir(p:pdir):pdirent;
  497. procedure SeekDir(p:pdir;off:longint);
  498. function TellDir(p:pdir):longint;
  499. {**************************
  500. Pipe/Fifo/Stream
  501. ***************************}
  502. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  503. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  504. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  505. Function PClose(Var F:text) : longint;
  506. Function PClose(Var F:file) : longint;
  507. Procedure POpen(var F:text;const Prog:String;rw:char);
  508. Procedure POpen(var F:file;const Prog:String;rw:char);
  509. Function mkFifo(pathname:string;mode:longint):boolean;
  510. Procedure AssignStream(Var StreamIn,Streamout:text;Const Prog:String);
  511. {**************************
  512. General information
  513. ***************************}
  514. Function GetDomainName:String;
  515. Function GetHostName:String;
  516. Function GetEnv(P:string):Pchar;
  517. Function Sysinfo(var Info:TSysinfo):Boolean;
  518. Function Uname(var unamerec:utsname):Boolean;
  519. {**************************
  520. Signal
  521. ***************************}
  522. Procedure SigAction(Signum:Integer;Var Act,OldAct:PSigActionRec );
  523. Procedure SigProcMask (How:Integer;SSet,OldSSet:PSigSet);
  524. Function SigPending:SigSet;
  525. Procedure SigSuspend(Mask:Sigset);
  526. Function Signal(Signum:Integer;Handler:SignalHandler):SignalHandler;
  527. Function Kill(Pid:longint;Sig:integer):integer;
  528. {**************************
  529. IOCtl/Termios Functions
  530. ***************************}
  531. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  532. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  533. Function TCSetAttr(fd:longint;OptAct:longint;var tios:TermIOS):boolean;
  534. Procedure CFSetISpeed(var tios:TermIOS;speed:Longint);
  535. Procedure CFSetOSpeed(var tios:TermIOS;speed:Longint);
  536. Procedure CFMakeRaw(var tios:TermIOS);
  537. Function TCSendBreak(fd,duration:longint):boolean;
  538. Function TCSetPGrp(fd,id:longint):boolean;
  539. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  540. Function TCFlush(fd,qsel:longint):boolean;
  541. Function TCDrain(fd:longint):boolean;
  542. Function TCFlow(fd,act:longint):boolean;
  543. Function IsATTY(Handle:Longint):Boolean;
  544. Function IsATTY(f:text):Boolean;
  545. function TTYname(Handle:Longint):string;
  546. function TTYname(var F:Text):string;
  547. {**************************
  548. Port IO functions
  549. ***************************}
  550. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  551. {$IFDEF I386}
  552. Procedure WritePort (Port : Longint; Value : Byte);
  553. Procedure WritePort (Port : Longint; Value : Word);
  554. Procedure WritePort (Port : Longint; Value : Longint);
  555. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  556. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  557. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  558. Procedure ReadPort (Port : Longint; Var Value : Byte);
  559. Procedure ReadPort (Port : Longint; Var Value : Word);
  560. Procedure ReadPort (Port : Longint; Var Value : Longint);
  561. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  562. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  563. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  564. {$ENDIF}
  565. {**************************
  566. Utility functions
  567. ***************************}
  568. Function Octal(l:longint):longint;
  569. Function FExpand(Const Path: PathStr):PathStr;
  570. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  571. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  572. Function Dirname(Const path:pathstr):pathstr;
  573. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  574. Function FNMatch(const Pattern,Name:string):Boolean;
  575. Function Glob(Const path:pathstr):pglob;
  576. Procedure Globfree(var p:pglob);
  577. Function StringToPPChar(Var S:STring):ppchar;
  578. Function GetFS(var T:Text):longint;
  579. Function GetFS(Var F:File):longint;
  580. {Filedescriptorsets}
  581. Procedure FD_Zero(var fds:fdSet);
  582. Procedure FD_Clr(fd:longint;var fds:fdSet);
  583. Procedure FD_Set(fd:longint;var fds:fdSet);
  584. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  585. {Stat.Mode Types}
  586. Function S_ISLNK(m:integer):boolean;
  587. Function S_ISREG(m:integer):boolean;
  588. Function S_ISDIR(m:integer):boolean;
  589. Function S_ISCHR(m:integer):boolean;
  590. Function S_ISBLK(m:integer):boolean;
  591. Function S_ISFIFO(m:integer):boolean;
  592. Function S_ISSOCK(m:integer):boolean;
  593. {******************************************************************************
  594. Implementation
  595. ******************************************************************************}
  596. Implementation
  597. Uses Strings;
  598. var
  599. LocalTZ:TimeZone;
  600. { Get the definitions of textrec and filerec }
  601. {$i textrec.inc}
  602. {$i filerec.inc}
  603. { Raw System calls are in Syscalls.inc}
  604. {$i syscalls.inc}
  605. {******************************************************************************
  606. Process related calls
  607. ******************************************************************************}
  608. function CreateShellArgV(const prog:string):ppchar;
  609. {
  610. Create an argv which executes a command in a shell using /bin/sh -c
  611. }
  612. var
  613. pp,p : ppchar;
  614. temp : string;
  615. begin
  616. getmem(pp,4*4);
  617. temp:='/bin/sh'#0'-c'#0+prog+#0;
  618. pp^:=@temp[1];
  619. p:=pp+4;
  620. p^:=@temp[9];
  621. p:=p+4;
  622. p^:=@temp[12];
  623. p:=p+4;
  624. p^:=Nil;
  625. CreateShellArgV:=pp;
  626. end;
  627. Function Fork:longint;
  628. {
  629. This function issues the 'fork' System call. the program is duplicated in memory
  630. and Execution continues in parent and child process.
  631. In the parent process, fork returns the PID of the child. In the child process,
  632. zero is returned.
  633. A negative value indicates that an error has occurred, the error is returned in
  634. LinuxError.
  635. }
  636. var
  637. regs:SysCallregs;
  638. begin
  639. Fork:=SysCall(SysCall_nr_fork,regs);
  640. LinuxError:=Errno;
  641. End;
  642. Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
  643. {
  644. Replaces the current program by the program specified in path,
  645. arguments in args are passed to Execve.
  646. environment specified in ep is passed on.
  647. }
  648. var
  649. regs:SysCallregs;
  650. begin
  651. path:=path+#0;
  652. regs.reg2:=longint(@path[1]);
  653. regs.reg3:=longint(args);
  654. regs.reg4:=longint(ep);
  655. SysCall(SysCall_nr_Execve,regs);
  656. { This only gets set when the call fails, otherwise we don't get here ! }
  657. Linuxerror:=errno;
  658. end;
  659. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  660. {
  661. Replaces the current program by the program specified in path,
  662. arguments in args are passed to Execve.
  663. environment specified in ep is passed on.
  664. }
  665. var
  666. regs:SysCallregs;
  667. begin
  668. regs.reg2:=longint(path);
  669. regs.reg3:=longint(args);
  670. regs.reg4:=longint(ep);
  671. SysCall(SysCall_nr_Execve,regs);
  672. { This only gets set when the call fails, otherwise we don't get here ! }
  673. Linuxerror:=errno;
  674. end;
  675. Procedure Execv(const path:pathstr;args:ppchar);
  676. {
  677. Replaces the current program by the program specified in path,
  678. arguments in args are passed to Execve.
  679. the current environment is passed on.
  680. }
  681. begin
  682. Execve(path,args,envp); {On error linuxerror will get set there}
  683. end;
  684. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  685. {
  686. This does the same as Execve, only it searches the PATH environment
  687. for the place of the Executable, except when Path starts with a slash.
  688. if the PATH environment variable is unavailable, the path is set to '.'
  689. }
  690. var
  691. thepath : string;
  692. begin
  693. if path[1]<>'/' then
  694. begin
  695. Thepath:=strpas(getenv('PATH'));
  696. if thepath='' then
  697. thepath:='.';
  698. Path:=FSearch(path,thepath)
  699. end
  700. else
  701. Path:='';
  702. if Path='' then
  703. linuxerror:=Sys_enoent
  704. else
  705. Execve(Path,args,ep);{On error linuxerror will get set there}
  706. end;
  707. Procedure Execle(Todo:string;Ep:ppchar);
  708. {
  709. This procedure takes the string 'Todo', parses it for command and
  710. command options, and Executes the command with the given options.
  711. The string 'Todo' shoud be of the form 'command options', options
  712. separated by commas.
  713. the PATH environment is not searched for 'command'.
  714. The specified environment(in 'ep') is passed on to command
  715. }
  716. var
  717. p : ppchar;
  718. begin
  719. p:=StringToPPChar(ToDo);
  720. if (p=nil) or (p^=nil) then
  721. exit;
  722. ExecVE(p^,p,EP);
  723. end;
  724. Procedure Execl(const Todo:string);
  725. {
  726. This procedure takes the string 'Todo', parses it for command and
  727. command options, and Executes the command with the given options.
  728. The string 'Todo' shoud be of the form 'command options', options
  729. separated by commas.
  730. the PATH environment is not searched for 'command'.
  731. The current environment is passed on to command
  732. }
  733. begin
  734. ExecLE(ToDo,EnvP);
  735. end;
  736. Procedure Execlp(Todo:string;Ep:ppchar);
  737. {
  738. This procedure takes the string 'Todo', parses it for command and
  739. command options, and Executes the command with the given options.
  740. The string 'Todo' shoud be of the form 'command options', options
  741. separated by commas.
  742. the PATH environment is searched for 'command'.
  743. The specified environment (in 'ep') is passed on to command
  744. }
  745. var
  746. p : ppchar;
  747. begin
  748. p:=StringToPPchar(todo);
  749. if (p=nil) or (p^=nil) then
  750. exit;
  751. ExecVP(StrPas(p^),p,EP);
  752. end;
  753. Function WaitPid(Pid:longint;Status:pointer;Options:Integer):Longint;
  754. {
  755. Waits until a child with PID Pid exits, or returns if it is exited already.
  756. Any resources used by the child are freed.
  757. The exit status is reported in the adress referred to by Status. It should
  758. be a longint.
  759. }
  760. var
  761. regs : SysCallregs;
  762. begin
  763. regs.reg2:=pid;
  764. regs.reg3:=longint(status);
  765. regs.reg4:=options;
  766. WaitPid:=SysCall(SysCall_nr_waitpid,regs);
  767. LinuxError:=errno;
  768. end;
  769. Function Shell(const Command:String):Longint;
  770. {
  771. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  772. The current environment is passed to the shell.
  773. It waits for the shell to exit, and returns its exit status.
  774. If the Exec call failed exit status 127 is reported.
  775. }
  776. var
  777. p : ppchar;
  778. temp,pid : longint;
  779. begin
  780. pid:=fork;
  781. if pid=-1 then
  782. exit; {Linuxerror already set in Fork}
  783. if pid=0 then
  784. begin
  785. {This is the child.}
  786. p:=CreateShellArgv(command);
  787. Execve(p^,p,envp);
  788. exit(127);
  789. end;
  790. temp:=0;
  791. WaitPid(pid,@temp,0);{Linuxerror is set there}
  792. Shell:=temp;{ Return exit status }
  793. end;
  794. Function GetPriority(Which,Who:Integer):integer;
  795. {
  796. Get Priority of process, process group, or user.
  797. Which : selects what kind of priority is used.
  798. can be one of the following predefined Constants :
  799. Prio_User.
  800. Prio_PGrp.
  801. Prio_Process.
  802. Who : depending on which, this is , respectively :
  803. Uid
  804. Pid
  805. Process Group id
  806. Errors are reported in linuxerror _only_. (priority can be negative)
  807. }
  808. var
  809. sr : Syscallregs;
  810. begin
  811. errno:=0;
  812. if (which<prio_process) or (which>prio_user) then
  813. begin
  814. { We can save an interrupt here }
  815. getpriority:=0;
  816. linuxerror:=Sys_einval;
  817. end
  818. else
  819. begin
  820. sr.reg2:=which;
  821. sr.reg3:=who;
  822. getpriority:=SysCall(Syscall_nr_getpriority,sr);
  823. linuxerror:=errno;
  824. end;
  825. end;
  826. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  827. {
  828. Set Priority of process, process group, or user.
  829. Which : selects what kind of priority is used.
  830. can be one of the following predefined Constants :
  831. Prio_User.
  832. Prio_PGrp.
  833. Prio_Process.
  834. Who : depending on value of which, this is, respectively :
  835. Uid
  836. Pid
  837. Process Group id
  838. what : A number between -20 and 20. -20 is most favorable, 20 least.
  839. 0 is the default.
  840. }
  841. var
  842. sr : Syscallregs;
  843. begin
  844. errno:=0;
  845. if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
  846. linuxerror:=Sys_einval { We can save an interrupt here }
  847. else
  848. begin
  849. sr.reg2:=which;
  850. sr.reg3:=who;
  851. sr.reg4:=what;
  852. SysCall(Syscall_nr_setpriority,sr);
  853. linuxerror:=errno;
  854. end;
  855. end;
  856. Procedure Nice(N:integer);
  857. {
  858. Set process priority. A positive N means a lower priority.
  859. A negative N decreases priority.
  860. }
  861. var
  862. sr : Syscallregs;
  863. begin
  864. sr.reg2:=n;
  865. SysCall(Syscall_nr_nice,sr);
  866. linuxerror:=errno;
  867. end;
  868. Function GetPid:LongInt;
  869. {
  870. Get Process ID.
  871. }
  872. var
  873. regs : SysCallregs;
  874. begin
  875. GetPid:=SysCall(SysCall_nr_getpid,regs);
  876. linuxerror:=errno;
  877. end;
  878. Function GetPPid:LongInt;
  879. {
  880. Get Process ID of parent process.
  881. }
  882. var
  883. regs : SysCallregs;
  884. begin
  885. GetPpid:=SysCall(SysCall_nr_getppid,regs);
  886. linuxerror:=errno;
  887. end;
  888. Function GetUid:Longint;
  889. {
  890. Get User ID.
  891. }
  892. var
  893. regs : SysCallregs;
  894. begin
  895. GetUid:=SysCall(SysCall_nr_getuid,regs);
  896. Linuxerror:=errno;
  897. end;
  898. Function GetEUid:Longint;
  899. {
  900. Get _effective_ User ID.
  901. }
  902. var
  903. regs : SysCallregs;
  904. begin
  905. GetEuid:=SysCall(SysCall_nr_geteuid,regs);
  906. Linuxerror:=errno;
  907. end;
  908. Function GetGid:Longint;
  909. {
  910. Get Group ID.
  911. }
  912. var
  913. regs : SysCallregs;
  914. begin
  915. Getgid:=SysCall(SysCall_nr_getgid,regs);
  916. Linuxerror:=errno;
  917. end;
  918. Function GetEGid:Longint;
  919. {
  920. Get _effective_ Group ID.
  921. }
  922. var
  923. regs : SysCallregs;
  924. begin
  925. GetEgid:=SysCall(SysCall_nr_getegid,regs);
  926. Linuxerror:=errno;
  927. end;
  928. {******************************************************************************
  929. Date and Time related calls
  930. ******************************************************************************}
  931. Const
  932. {Date Translation}
  933. C1970=2440588;
  934. D0 = 1461;
  935. D1 = 146097;
  936. D2 =1721119;
  937. Function GregorianToJulian(Year,Month,Day:Longint):LongInt;
  938. Var
  939. Century,XYear: LongInt;
  940. Begin
  941. If Month<=2 Then
  942. Begin
  943. Dec(Year);
  944. Inc(Month,12);
  945. End;
  946. Dec(Month,3);
  947. Century:=(longint(Year Div 100)*D1) shr 2;
  948. XYear:=(longint(Year Mod 100)*D0) shr 2;
  949. GregorianToJulian:=((((Month*153)+2) div 5)+Day)+D2+XYear+Century;
  950. End;
  951. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  952. Var
  953. YYear,XYear,Temp,TempMonth : LongInt;
  954. Begin
  955. Temp:=((JulianDN-D2) shl 2)-1;
  956. JulianDN:=Temp Div D1;
  957. XYear:=(Temp Mod D1) or 3;
  958. YYear:=(XYear Div D0);
  959. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  960. Day:=((Temp Mod 153)+5) Div 5;
  961. TempMonth:=Temp Div 153;
  962. If TempMonth>=10 Then
  963. Begin
  964. inc(YYear);
  965. dec(TempMonth,12);
  966. End;
  967. inc(TempMonth,3);
  968. Month := TempMonth;
  969. Year:=YYear+(JulianDN*100);
  970. end;
  971. Procedure GetTimeOfDay(var tv:timeval;var tz:timezone);
  972. {
  973. Get the time of day and timezone.
  974. }
  975. var
  976. regs : SysCallregs;
  977. begin
  978. regs.reg2:=longint(@tv);
  979. regs.reg3:=longint(@tz);
  980. SysCall(SysCall_nr_gettimeofday,regs);
  981. LinuxError:=Errno;
  982. end;
  983. Procedure SetTimeOfDay(Const tv:timeval;Const tz:timezone);
  984. {
  985. Get the time of day and timezone.
  986. }
  987. var
  988. regs : SysCallregs;
  989. begin
  990. regs.reg2:=longint(@tv);
  991. regs.reg3:=longint(@tz);
  992. SysCall(SysCall_nr_settimeofday,regs);
  993. LinuxError:=Errno;
  994. end;
  995. Function GetTimeOfDay: longint;
  996. {
  997. Get the number of seconds since 00:00, January 1 1970, GMT
  998. the time NOT corrected any way
  999. }
  1000. var
  1001. t : timeval ;
  1002. tz : timezone ;
  1003. begin
  1004. gettimeofday(t,tz);{Sets LinuxError also}
  1005. GetTimeOfDay:=t.sec;
  1006. end;
  1007. Function GetEpochTime:longint;
  1008. {
  1009. Get the number of seconds since 00:00, January 1 1970, GMT
  1010. the time is corrected according to the time zone, but NOT
  1011. DST corrected.
  1012. }
  1013. var
  1014. t : timeval ;
  1015. tz : timezone ;
  1016. begin
  1017. gettimeofday(t,tz);{Sets LinuxError also}
  1018. Getepochtime:=t.sec-tz.minuteswest*60;
  1019. end;
  1020. Procedure InitEpochToLocal;
  1021. var
  1022. tv:TimeVal;
  1023. begin
  1024. GetTimeOfDay(tv,LocalTZ);
  1025. end;
  1026. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  1027. {
  1028. Transforms Epoch time(seconds since 00:00, january 1 1970, corrected for
  1029. local time zone) into local time (hour, minute,seconds)
  1030. }
  1031. Var
  1032. DateNum: LongInt;
  1033. Begin { Beginning of Localtime }
  1034. dec(Epoch,LocalTZ.minuteswest*60);
  1035. Datenum:=(Epoch Div 86400) + c1970;
  1036. JulianToGregorian(DateNum,Year,Month,day);
  1037. Epoch:=Epoch Mod 86400;
  1038. Hour:=Epoch Div 3600;
  1039. Epoch:=Epoch Mod 3600;
  1040. Minute:=Epoch Div 60;
  1041. Second:=Epoch Mod 60;
  1042. End;
  1043. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  1044. {
  1045. Transforms local time (year,month,day,hour,minutes,second) to Epoch time
  1046. (seconds since 00:00, january 1 1970, corrected for local time zone)
  1047. }
  1048. Begin
  1049. LocalToEpoch:=((GregorianToJulian(Year,Month,Day)-c1970)*86400)+
  1050. (LongInt(Hour)*3600)+(Minute*60)+Second+(LocalTZ.minuteswest*60);
  1051. End;
  1052. Procedure GetTime(Var Hour,Minute,Second:Word);
  1053. {
  1054. Gets the current time, adjusted to local time, but not DST,
  1055. in hours, minutes and seconds.
  1056. }
  1057. var
  1058. year,day,month:Word;
  1059. Begin
  1060. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  1061. End;
  1062. Procedure GetDate(Var Year,Month,Day:Word);
  1063. {
  1064. Gets the current date, adjusted to local time, but not DST,
  1065. in year,month,day.
  1066. }
  1067. var
  1068. hour,minute,second : Word;
  1069. Begin
  1070. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  1071. End;
  1072. { The now following are for compatibility with earlier versions
  1073. of the linux unit... }
  1074. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Integer);
  1075. begin
  1076. EpochToLocal(epoch,word(year),word(month),word(day),word(hour),word(minute),word(second));
  1077. end;
  1078. Function LocalToEpoch(year,month,day,hour,minute,second:Integer):Longint;
  1079. begin
  1080. LocalToEpoch:=LocalToEpoch(word(year),word(month),word(day),word(hour),word(minute),word(second));
  1081. end;
  1082. Procedure GetTime(Var Hour,Minute,Second:Integer);
  1083. begin
  1084. GetTime(Word(Hour),Word(Minute),Word(Second));
  1085. end;
  1086. Procedure GetDate(Var Year,Month,Day:Integer);
  1087. begin
  1088. GetDate(Word(Year),Word(Month),Word(Day));
  1089. end;
  1090. {******************************************************************************
  1091. FileSystem calls
  1092. ******************************************************************************}
  1093. Function fdOpen(pathname:string;flags:longint):longint;
  1094. begin
  1095. pathname:=pathname+#0;
  1096. fdOpen:=Sys_Open(@pathname[1],flags,438);
  1097. LinuxError:=Errno;
  1098. end;
  1099. Function fdOpen(pathname:string;flags,mode:longint):longint;
  1100. begin
  1101. pathname:=pathname+#0;
  1102. fdOpen:=Sys_Open(@pathname[1],flags,mode);
  1103. LinuxError:=Errno;
  1104. end;
  1105. Function fdOpen(pathname:pchar;flags:longint):longint;
  1106. begin
  1107. fdOpen:=Sys_Open(pathname,flags,0);
  1108. LinuxError:=Errno;
  1109. end;
  1110. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  1111. begin
  1112. fdOpen:=Sys_Open(pathname,flags,mode);
  1113. LinuxError:=Errno;
  1114. end;
  1115. Function fdClose(fd:longint):boolean;
  1116. begin
  1117. fdClose:=(Sys_Close(fd)=0);
  1118. LinuxError:=Errno;
  1119. end;
  1120. Function fdRead(fd:longint;var buf;size:longint):longint;
  1121. begin
  1122. fdRead:=Sys_Read(fd,pchar(@buf),size);
  1123. LinuxError:=Errno;
  1124. end;
  1125. Function fdWrite(fd:longint;var buf;size:longint):longint;
  1126. begin
  1127. fdWrite:=Sys_Write(fd,pchar(@buf),size);
  1128. LinuxError:=Errno;
  1129. end;
  1130. Function fdTruncate(fd,size:longint):boolean;
  1131. var
  1132. Regs : SysCallRegs;
  1133. begin
  1134. Regs.reg2:=fd;
  1135. Regs.reg3:=size;
  1136. fdTruncate:=(SysCall(Syscall_nr_ftruncate,regs)=0);
  1137. LinuxError:=Errno;
  1138. end;
  1139. Function fdSeek (fd,pos,seektype :longint): longint;
  1140. {
  1141. Do a Seek on a file descriptor fd to position pos, starting from seektype
  1142. }
  1143. begin
  1144. fdseek:=Sys_LSeek (fd,pos,seektype);
  1145. LinuxError:=Errno;
  1146. end;
  1147. Function fdFlush (fd : Longint) : Boolean;
  1148. var
  1149. SR: SysCallRegs;
  1150. begin
  1151. SR.reg2 := fd;
  1152. fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
  1153. LinuxError:=Errno;
  1154. end;
  1155. Function Fcntl(Fd:Text;Cmd:integer):integer;
  1156. {
  1157. Read or manipulate a file.(See also fcntl (2) )
  1158. Possible values for Cmd are :
  1159. F_GetFd,F_GetFl,F_GetOwn
  1160. Errors are reported in Linuxerror;
  1161. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  1162. }
  1163. var
  1164. sr : Syscallregs;
  1165. begin
  1166. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  1167. begin
  1168. sr.reg2:=textrec(fd).handle;
  1169. sr.reg3:=cmd;
  1170. Linuxerror:=SysCall(Syscall_nr_fcntl,sr);
  1171. if linuxerror=-1 then
  1172. begin
  1173. linuxerror:=errno;
  1174. fcntl:=0;
  1175. end
  1176. else
  1177. begin
  1178. fcntl:=linuxerror;
  1179. linuxerror:=0;
  1180. end;
  1181. end
  1182. else
  1183. begin
  1184. linuxerror:=Sys_einval;
  1185. Fcntl:=0;
  1186. end;
  1187. end;
  1188. Procedure Fcntl(Fd:Text;Cmd:Integer;Arg:Longint);
  1189. {
  1190. Read or manipulate a file. (See also fcntl (2) )
  1191. Possible values for Cmd are :
  1192. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  1193. Errors are reported in Linuxerror;
  1194. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  1195. F_DupFD is not allowed, due to the structure of Files in Pascal.
  1196. }
  1197. var
  1198. sr : Syscallregs;
  1199. begin
  1200. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  1201. begin
  1202. sr.reg2:=textrec(fd).handle;
  1203. sr.reg3:=cmd;
  1204. sr.reg4:=arg;
  1205. SysCall(Syscall_nr_fcntl,sr);
  1206. linuxerror:=errno;
  1207. end
  1208. else
  1209. linuxerror:=Sys_einval;
  1210. end;
  1211. Function Chmod(path:pathstr;Newmode:longint):Boolean;
  1212. {
  1213. Changes the permissions of a file.
  1214. }
  1215. var
  1216. sr : Syscallregs;
  1217. begin
  1218. path:=path+#0;
  1219. sr.reg2:=longint(@(path[1]));
  1220. sr.reg3:=newmode;
  1221. Chmod:=(SysCall(Syscall_nr_chmod,sr)=0);
  1222. linuxerror:=errno;
  1223. end;
  1224. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  1225. {
  1226. Change the owner and group of a file.
  1227. A user can only change the group to a group of which he is a member.
  1228. The super-user can change uid and gid of any file.
  1229. }
  1230. var
  1231. sr : Syscallregs;
  1232. begin
  1233. path:=path+#0;
  1234. sr.reg2:=longint(@(path[1]));
  1235. sr.reg3:=newuid;
  1236. sr.reg4:=newgid;
  1237. ChOwn:=(Syscall(Syscall_nr_chown,sr)=0);
  1238. linuxerror:=errno;
  1239. end;
  1240. Function Utime(path:pathstr;utim:utimebuf):boolean;
  1241. var
  1242. sr : Syscallregs;
  1243. begin
  1244. path:=path+#0;
  1245. sr.reg2:=longint(@(path[1]));
  1246. sr.reg3:=longint(@utim);
  1247. Utime:=SysCall(Syscall_nr_utime,sr)=0;
  1248. linuxerror:=errno;
  1249. end;
  1250. Function Flock (fd,mode : longint) : boolean;
  1251. var
  1252. sr : Syscallregs;
  1253. begin
  1254. sr.reg2:=fd;
  1255. sr.reg3:=mode;
  1256. flock:=Syscall(Syscall_nr_flock,sr)=0;
  1257. LinuxError:=errno;
  1258. end;
  1259. Function Flock (var T : text;mode : longint) : boolean;
  1260. begin
  1261. Flock:=Flock(TextRec(T).Handle,mode);
  1262. end;
  1263. Function Flock (var F : File;mode : longint) : boolean;
  1264. begin
  1265. Flock:=Flock(FileRec(F).Handle,mode);
  1266. end;
  1267. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  1268. {
  1269. Get all information on a file, and return it in Info.
  1270. }
  1271. begin
  1272. path:=path+#0;
  1273. FStat:=(Sys_stat(@(path[1]),Info)=0);
  1274. LinuxError:=errno;
  1275. end;
  1276. Function Fstat(Fd:Longint;var Info:stat):Boolean;
  1277. {
  1278. Get all information on a file descriptor, and return it in info.
  1279. }
  1280. var
  1281. regs : SysCallregs;
  1282. begin
  1283. regs.reg2:=Fd;
  1284. regs.reg3:=longint(@Info);
  1285. FStat:=(SysCall(SysCall_nr_fstat,regs)=0);
  1286. LinuxError:=Errno;
  1287. end;
  1288. Function FStat(var F:Text;Var Info:stat):Boolean;
  1289. {
  1290. Get all information on a text file, and return it in info.
  1291. }
  1292. begin
  1293. FStat:=Fstat(TextRec(F).Handle,INfo);
  1294. end;
  1295. Function FStat(var F:File;Var Info:stat):Boolean;
  1296. {
  1297. Get all information on a untyped file, and return it in info.
  1298. }
  1299. begin
  1300. FStat:=Fstat(FileRec(F).Handle,Info);
  1301. end;
  1302. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  1303. {
  1304. Get all information on a link (the link itself), and return it in info.
  1305. }
  1306. var
  1307. regs : SysCallregs;
  1308. begin
  1309. FileName:=FileName+#0;
  1310. regs.reg2:=longint(@filename[1]);
  1311. regs.reg3:=longint(@Info);
  1312. LStat:=(SysCall(SysCall_nr_lstat,regs)=0);
  1313. LinuxError:=Errno;
  1314. end;
  1315. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  1316. {
  1317. Get all information on a fileSystem, and return it in Info.
  1318. Path is the name of a file/directory on the fileSystem you wish to
  1319. investigate.
  1320. }
  1321. var
  1322. regs : SysCallregs;
  1323. begin
  1324. path:=path+#0;
  1325. regs.reg2:=longint(@path[1]);
  1326. regs.reg3:=longint(@Info);
  1327. FSStat:=(SysCall(SysCall_nr_statfs,regs)=0);
  1328. LinuxError:=errno;
  1329. end;
  1330. Function FSStat(Fd:Longint;Var Info:statfs):Boolean;
  1331. {
  1332. Get all information on a fileSystem, and return it in Info.
  1333. Fd is the file descriptor of a file/directory on the fileSystem
  1334. you wish to investigate.
  1335. }
  1336. var
  1337. regs : SysCallregs;
  1338. begin
  1339. regs.reg2:=Fd;
  1340. regs.reg3:=longint(@Info);
  1341. FSStat:=(SysCall(SysCall_nr_fstatfs,regs)=0);
  1342. LinuxError:=errno;
  1343. end;
  1344. Function Link(OldPath,NewPath:pathstr):boolean;
  1345. {
  1346. Proceduces a hard link from new to old.
  1347. In effect, new will be the same file as old.
  1348. }
  1349. var
  1350. regs : SysCallregs;
  1351. begin
  1352. oldpath:=oldpath+#0;
  1353. newpath:=newpath+#0;
  1354. regs.reg2:=longint(@oldpath[1]);
  1355. regs.reg3:=longint(@newpath[1]);
  1356. Link:=SysCall(SysCall_nr_link,regs)=0;
  1357. linuxerror:=errno;
  1358. end;
  1359. Function SymLink(OldPath,newPath:pathstr):boolean;
  1360. {
  1361. Proceduces a soft link from new to old.
  1362. }
  1363. begin
  1364. oldpath:=oldpath+#0;
  1365. newpath:=newpath+#0;
  1366. Symlink:=Sys_symlink(pchar(@(oldpath[1])),pchar(@(newpath[1])))=0;
  1367. linuxerror:=errno;
  1368. end;
  1369. Function UnLink(Path:pathstr):boolean;
  1370. {
  1371. Removes the file in 'Path' (that is, it decreases the link count with one.
  1372. if the link count is zero, the file is removed from the disk.
  1373. }
  1374. begin
  1375. path:=path+#0;
  1376. Unlink:=Sys_unlink(pchar(@(path[1])))=0;
  1377. linuxerror:=errno;
  1378. end;
  1379. Function UnLink(Path:pchar):Boolean;
  1380. {
  1381. Removes the file in 'Path' (that is, it decreases the link count with one.
  1382. if the link count is zero, the file is removed from the disk.
  1383. }
  1384. begin
  1385. Unlink:=(Sys_unlink(path)=0);
  1386. linuxerror:=errno;
  1387. end;
  1388. Function FRename (OldName,NewName : Pchar) : Boolean;
  1389. begin
  1390. FRename:=Sys_rename(OldName,NewName)=0;
  1391. LinuxError:=Errno;
  1392. end;
  1393. Function FRename (OldName,NewName : String) : Boolean;
  1394. begin
  1395. OldName:=OldName+#0;
  1396. NewName:=NewName+#0;
  1397. FRename:=FRename (@OldName[1],@NewName[1]);
  1398. end;
  1399. Function Umask(Mask:Integer):integer;
  1400. {
  1401. Sets file creation mask to (Mask and 0777 (octal) ), and returns the
  1402. previous value.
  1403. }
  1404. var
  1405. sr : Syscallregs;
  1406. begin
  1407. sr.reg2:=mask;
  1408. Umask:=SysCall(Syscall_nr_umask,sr);
  1409. linuxerror:=0;
  1410. end;
  1411. Function Access(Path:Pathstr ;mode:integer):boolean;
  1412. {
  1413. Test users access rights on the specified file.
  1414. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  1415. R,W,X stand for read,write and Execute access, simultaneously.
  1416. F_OK checks whether the test would be allowed on the file.
  1417. i.e. It checks the search permissions in all directory components
  1418. of the path.
  1419. The test is done with the real user-ID, instead of the effective.
  1420. If access is denied, or an error occurred, false is returned.
  1421. If access is granted, true is returned.
  1422. Errors other than no access,are reported in linuxerror.
  1423. }
  1424. var
  1425. sr : Syscallregs;
  1426. begin
  1427. path:=path+#0;
  1428. sr.reg2:=longint(@(path[1]));
  1429. sr.reg3:=mode;
  1430. access:=(SysCall(Syscall_nr_access,sr)=0);
  1431. linuxerror:=errno;
  1432. end;
  1433. Function Dup(oldfile,newfile:longint):Boolean;
  1434. {
  1435. Copies the filedescriptor oldfile to newfile
  1436. }
  1437. var
  1438. sr : Syscallregs;
  1439. begin
  1440. sr.reg2:=oldfile;
  1441. newfile:=Syscall(Syscall_nr_dup,sr);
  1442. linuxerror:=errno;
  1443. Dup:=(LinuxError=0);
  1444. end;
  1445. Function Dup(var oldfile,newfile:text):Boolean;
  1446. {
  1447. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  1448. oldfile.
  1449. After which the two textfiles are, in effect, the same, except
  1450. that they don't share the same buffer, and don't share the same
  1451. close_on_exit flag.
  1452. }
  1453. begin
  1454. flush(oldfile);{ We cannot share buffers, so we flush them. }
  1455. textrec(newfile):=textrec(oldfile);
  1456. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  1457. Dup:=Dup(textrec(oldfile).handle,textrec(newfile).handle);
  1458. end;
  1459. Function Dup(var oldfile,newfile:file):Boolean;
  1460. {
  1461. Copies the filedescriptor oldfile to newfile
  1462. }
  1463. begin
  1464. filerec(newfile):=filerec(oldfile);
  1465. Dup:=Dup(filerec(oldfile).handle,filerec(newfile).handle);
  1466. end;
  1467. Function Dup2(oldfile,newfile:longint):Boolean;
  1468. {
  1469. Copies the filedescriptor oldfile to newfile
  1470. }
  1471. var
  1472. sr : Syscallregs;
  1473. begin
  1474. sr.reg2:=oldfile;
  1475. sr.reg3:=newfile;
  1476. SysCall(Syscall_nr_dup2,sr);
  1477. linuxerror:=errno;
  1478. Dup2:=(LinuxError=0);
  1479. end;
  1480. Function Dup2(var oldfile,newfile:text):Boolean;
  1481. {
  1482. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  1483. oldfile. It closes newfile if it was still open.
  1484. After which the two textfiles are, in effect, the same, except
  1485. that they don't share the same buffer, and don't share the same
  1486. close_on_exit flag.
  1487. }
  1488. var
  1489. tmphandle : word;
  1490. begin
  1491. flush(oldfile);{ We cannot share buffers, so we flush them. }
  1492. flush(newfile);
  1493. tmphandle:=textrec(newfile).handle;
  1494. textrec(newfile):=textrec(oldfile);
  1495. textrec(newfile).handle:=tmphandle;
  1496. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  1497. Dup2:=Dup2(textrec(oldfile).handle,textrec(newfile).handle);
  1498. end;
  1499. Function Dup2(var oldfile,newfile:file):Boolean;
  1500. {
  1501. Copies the filedescriptor oldfile to newfile
  1502. }
  1503. begin
  1504. filerec(newfile):=filerec(oldfile);
  1505. Dup2:=Dup2(filerec(oldfile).handle,filerec(newfile).handle);
  1506. end;
  1507. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  1508. {
  1509. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  1510. have changed.
  1511. }
  1512. Var
  1513. SelectArray : Array[1..5] of longint;
  1514. Sr : Syscallregs;
  1515. begin
  1516. SelectArray[1]:=n;
  1517. SelectArray[2]:=longint(Readfds);
  1518. Selectarray[3]:=longint(Writefds);
  1519. selectarray[4]:=longint(exceptfds);
  1520. Selectarray[5]:=longint(TimeOut);
  1521. sr.reg2:=longint(@selectarray);
  1522. Select:=SysCall(Syscall_nr_select,sr);
  1523. LinuxError:=Errno;
  1524. end;
  1525. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  1526. {
  1527. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  1528. have changed.
  1529. This function allows specification of a timeout as a longint.
  1530. }
  1531. var
  1532. p : PTimeVal;
  1533. tv : TimeVal;
  1534. begin
  1535. if TimeOut=-1 then
  1536. p:=nil
  1537. else
  1538. begin
  1539. tv.Sec:=Timeout div 1000;
  1540. tv.Usec:=(Timeout mod 1000)*1000;
  1541. p:=@tv;
  1542. end;
  1543. Select:=Select(N,Readfds,WriteFds,ExceptFds,p);
  1544. end;
  1545. Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
  1546. Var
  1547. F:FDSet;
  1548. begin
  1549. if textrec(t).mode=fmclosed then
  1550. begin
  1551. LinuxError:=Sys_EBADF;
  1552. exit(-1);
  1553. end;
  1554. FD_Zero(f);
  1555. FD_Set(textrec(T).handle,f);
  1556. if textrec(T).mode=fminput then
  1557. SelectText:=select(textrec(T).handle+1,@f,nil,nil,TimeOut)
  1558. else
  1559. SelectText:=select(textrec(T).handle+1,nil,@f,nil,TimeOut);
  1560. end;
  1561. {******************************************************************************
  1562. Directory
  1563. ******************************************************************************}
  1564. Function OpenDir(F:String):PDir;
  1565. begin
  1566. F:=F+#0;
  1567. OpenDir:=OpenDir(@F[1]);
  1568. end;
  1569. procedure SeekDir(p:pdir;off:longint);
  1570. begin
  1571. if p=nil then
  1572. begin
  1573. errno:=Sys_EBADF;
  1574. exit;
  1575. end;
  1576. p^.nextoff:=Sys_lseek(p^.fd,off,seek_set);
  1577. p^.size:=0;
  1578. p^.loc:=0;
  1579. end;
  1580. function TellDir(p:pdir):longint;
  1581. begin
  1582. if p=nil then
  1583. begin
  1584. errno:=Sys_EBADF;
  1585. telldir:=-1;
  1586. exit;
  1587. end;
  1588. telldir:=Sys_lseek(p^.fd,0,seek_cur)
  1589. { We could try to use the nextoff field here, but on my 1.2.13
  1590. kernel, this gives nothing... This may have to do with
  1591. the readdir implementation of libc... I also didn't find any trace of
  1592. the field in the kernel code itself, So I suspect it is an artifact of libc.
  1593. Michael. }
  1594. end;
  1595. Function ReadDir(P:pdir):pdirent;
  1596. begin
  1597. ReadDir:=Sys_ReadDir(p);
  1598. LinuxError:=Errno;
  1599. end;
  1600. {******************************************************************************
  1601. Pipes/Fifo
  1602. ******************************************************************************}
  1603. Procedure OpenPipe(var F:Text);
  1604. begin
  1605. case textrec(f).mode of
  1606. fmoutput : if textrec(f).userdata[1]<>P_OUT then
  1607. textrec(f).mode:=fmclosed;
  1608. fminput : if textrec(f).userdata[1]<>P_IN then
  1609. textrec(f).mode:=fmclosed;
  1610. else
  1611. textrec(f).mode:=fmclosed;
  1612. end;
  1613. end;
  1614. Procedure IOPipe(var F:text);
  1615. begin
  1616. case textrec(f).mode of
  1617. fmoutput : begin
  1618. { first check if we need something to write, else we may
  1619. get a SigPipe when Close() is called (PFV) }
  1620. if textrec(f).bufpos>0 then
  1621. Sys_write(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  1622. end;
  1623. fminput : textrec(f).bufend:=Sys_read(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  1624. end;
  1625. textrec(f).bufpos:=0;
  1626. end;
  1627. Procedure FlushPipe(var F:Text);
  1628. begin
  1629. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  1630. IOPipe(f);
  1631. textrec(f).bufpos:=0;
  1632. end;
  1633. Procedure ClosePipe(var F:text);
  1634. begin
  1635. textrec(f).mode:=fmclosed;
  1636. Sys_close(textrec(f).handle);
  1637. end;
  1638. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  1639. {
  1640. Sets up a pair of file variables, which act as a pipe. The first one can
  1641. be read from, the second one can be written to.
  1642. If the operation was unsuccesful, linuxerror is set.
  1643. }
  1644. var
  1645. pip : tpipe;
  1646. regs : SysCallregs;
  1647. begin
  1648. regs.reg2:=longint(@pip);
  1649. SysCall(SysCall_nr_pipe,regs);
  1650. pipe_in:=pip[1];
  1651. pipe_out:=pip[2];
  1652. linuxerror:=errno;
  1653. AssignPipe:=(LinuxError=0);
  1654. end;
  1655. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  1656. {
  1657. Sets up a pair of file variables, which act as a pipe. The first one can
  1658. be read from, the second one can be written to.
  1659. If the operation was unsuccesful, linuxerror is set.
  1660. }
  1661. var
  1662. f_in,f_out : longint;
  1663. begin
  1664. if not AssignPipe(f_in,f_out) then
  1665. begin
  1666. AssignPipe:=false;
  1667. exit;
  1668. end;
  1669. { Set up input }
  1670. Assign(Pipe_in,'');
  1671. Textrec(Pipe_in).Handle:=f_in;
  1672. Textrec(Pipe_in).Mode:=fmInput;
  1673. Textrec(Pipe_in).userdata[1]:=P_IN;
  1674. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  1675. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  1676. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  1677. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  1678. { Set up output }
  1679. Assign(Pipe_out,'');
  1680. Textrec(Pipe_out).Handle:=f_out;
  1681. Textrec(Pipe_out).Mode:=fmOutput;
  1682. Textrec(Pipe_out).userdata[1]:=P_OUT;
  1683. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  1684. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  1685. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  1686. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  1687. AssignPipe:=true;
  1688. end;
  1689. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  1690. {
  1691. Sets up a pair of file variables, which act as a pipe. The first one can
  1692. be read from, the second one can be written to.
  1693. If the operation was unsuccesful, linuxerror is set.
  1694. }
  1695. var
  1696. f_in,f_out : longint;
  1697. begin
  1698. if not AssignPipe(f_in,f_out) then
  1699. begin
  1700. AssignPipe:=false;
  1701. exit;
  1702. end;
  1703. { Set up input }
  1704. Assign(Pipe_in,'');
  1705. Filerec(Pipe_in).Handle:=f_in;
  1706. Filerec(Pipe_in).Mode:=fmInput;
  1707. Filerec(Pipe_in).recsize:=1;
  1708. Filerec(Pipe_in).userdata[1]:=P_IN;
  1709. { Set up output }
  1710. Assign(Pipe_out,'');
  1711. Filerec(Pipe_out).Handle:=f_out;
  1712. Filerec(Pipe_out).Mode:=fmoutput;
  1713. Filerec(Pipe_out).recsize:=1;
  1714. Filerec(Pipe_out).userdata[1]:=P_OUT;
  1715. AssignPipe:=true;
  1716. end;
  1717. Function PClose(Var F:text) :longint;
  1718. var
  1719. sr : syscallregs;
  1720. pl : ^longint;
  1721. res : longint;
  1722. begin
  1723. sr.reg2:=Textrec(F).Handle;
  1724. SysCall (syscall_nr_close,sr);
  1725. { closed our side, Now wait for the other - this appears to be needed ?? }
  1726. pl:=@(textrec(f).userdata[2]);
  1727. waitpid(pl^,@res,0);
  1728. pclose:=res shr 8;
  1729. end;
  1730. Function PClose(Var F:file) : longint;
  1731. var
  1732. sr : syscallregs;
  1733. pl : ^longint;
  1734. res : longint;
  1735. begin
  1736. sr.reg2:=FileRec(F).Handle;
  1737. SysCall (Syscall_nr_close,sr);
  1738. { closed our side, Now wait for the other - this appears to be needed ?? }
  1739. pl:=@(filerec(f).userdata[2]);
  1740. waitpid(pl^,@res,0);
  1741. pclose:=res shr 8;
  1742. end;
  1743. Procedure PCloseText(Var F:text);
  1744. {
  1745. May not use @PClose due overloading
  1746. }
  1747. begin
  1748. PClose(f);
  1749. end;
  1750. Procedure POpen(var F:text;const Prog:String;rw:char);
  1751. {
  1752. Starts the program in 'Prog' and makes it's input or out put the
  1753. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  1754. F, will be read from stdin by the program in 'Prog'. The inverse is true
  1755. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  1756. read from 'f'.
  1757. }
  1758. var
  1759. pipi,
  1760. pipo : text;
  1761. pid : longint;
  1762. pl : ^longint;
  1763. pp : ppchar;
  1764. begin
  1765. LinuxError:=0;
  1766. rw:=upcase(rw);
  1767. if not (rw in ['R','W']) then
  1768. begin
  1769. LinuxError:=Sys_enoent;
  1770. exit;
  1771. end;
  1772. AssignPipe(pipi,pipo);
  1773. if Linuxerror<>0 then
  1774. exit;
  1775. pid:=fork;
  1776. if linuxerror<>0 then
  1777. begin
  1778. close(pipi);
  1779. close(pipo);
  1780. exit;
  1781. end;
  1782. if pid=0 then
  1783. begin
  1784. { We're in the child }
  1785. if rw='W' then
  1786. begin
  1787. close(pipo);
  1788. dup2(pipi,input);
  1789. close(pipi);
  1790. if linuxerror<>0 then
  1791. halt(127);
  1792. end
  1793. else
  1794. begin
  1795. close(pipi);
  1796. dup2(pipo,output);
  1797. close(pipo);
  1798. if linuxerror<>0 then
  1799. halt(127);
  1800. end;
  1801. pp:=createshellargv(prog);
  1802. Execve(pp^,pp,envp);
  1803. halt(127);
  1804. end
  1805. else
  1806. begin
  1807. { We're in the parent }
  1808. if rw='W' then
  1809. begin
  1810. close(pipi);
  1811. f:=pipo;
  1812. textrec(f).bufptr:=@textrec(f).buffer;
  1813. end
  1814. else
  1815. begin
  1816. close(pipo);
  1817. f:=pipi;
  1818. textrec(f).bufptr:=@textrec(f).buffer;
  1819. end;
  1820. {Save the process ID - needed when closing }
  1821. pl:=@(textrec(f).userdata[2]);
  1822. pl^:=pid;
  1823. textrec(f).closefunc:=@PCloseText;
  1824. end;
  1825. end;
  1826. Procedure POpen(var F:file;const Prog:String;rw:char);
  1827. {
  1828. Starts the program in 'Prog' and makes it's input or out put the
  1829. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  1830. F, will be read from stdin by the program in 'Prog'. The inverse is true
  1831. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  1832. read from 'f'.
  1833. }
  1834. var
  1835. pipi,
  1836. pipo : file;
  1837. pid : longint;
  1838. pl : ^longint;
  1839. p,pp : ppchar;
  1840. temp : string[255];
  1841. begin
  1842. LinuxError:=0;
  1843. rw:=upcase(rw);
  1844. if not (rw in ['R','W']) then
  1845. begin
  1846. LinuxError:=Sys_enoent;
  1847. exit;
  1848. end;
  1849. AssignPipe(pipi,pipo);
  1850. if Linuxerror<>0 then
  1851. exit;
  1852. pid:=fork;
  1853. if linuxerror<>0 then
  1854. begin
  1855. close(pipi);
  1856. close(pipo);
  1857. exit;
  1858. end;
  1859. if pid=0 then
  1860. begin
  1861. { We're in the child }
  1862. if rw='W' then
  1863. begin
  1864. close(pipo);
  1865. dup2(filerec(pipi).handle,stdinputhandle);
  1866. close(pipi);
  1867. if linuxerror<>0 then
  1868. halt(127);
  1869. end
  1870. else
  1871. begin
  1872. close(pipi);
  1873. dup2(filerec(pipo).handle,stdoutputhandle);
  1874. close(pipo);
  1875. if linuxerror<>0 then
  1876. halt(127);
  1877. end;
  1878. getmem(pp,sizeof(pchar)*4);
  1879. temp:='/bin/sh'#0'-c'#0+prog+#0;
  1880. pp^:=@temp[1];
  1881. p:=pp+sizeof(pchar);
  1882. p^:=@temp[9];
  1883. p:=p+sizeof(pchar);
  1884. p^:=@temp[12];
  1885. p:=p+sizeof(pchar);
  1886. p^:=Nil;
  1887. Execve('/bin/sh',pp,envp);
  1888. halt(127);
  1889. end
  1890. else
  1891. begin
  1892. { We're in the parent }
  1893. if rw='W' then
  1894. begin
  1895. close(pipi);
  1896. f:=pipo;
  1897. end
  1898. else
  1899. begin
  1900. close(pipo);
  1901. f:=pipi;
  1902. end;
  1903. {Save the process ID - needed when closing }
  1904. pl:=@(filerec(f).userdata[2]);
  1905. pl^:=pid;
  1906. end;
  1907. end;
  1908. Function mkFifo(pathname:string;mode:longint):boolean;
  1909. var
  1910. regs : SysCallRegs;
  1911. begin
  1912. pathname:=pathname+#0;
  1913. regs.reg2:=longint(@pathname[1]);
  1914. regs.reg3:=mode or STAT_IFIFO;
  1915. regs.reg4:=0;
  1916. mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
  1917. end;
  1918. Procedure AssignStream(Var StreamIn,Streamout:text;Const Prog:String);
  1919. {
  1920. Starts the program in 'Prog' and makes its input and output the
  1921. other end of two pipes, which are the stdin and stdout of a program
  1922. specified in 'Prog'.
  1923. streamout can be used to write to the program, streamin can be used to read
  1924. the output of the program. See the following diagram :
  1925. Parent Child
  1926. STreamout --> Input
  1927. Streamin <-- Output
  1928. }
  1929. var
  1930. pipi,
  1931. pipo : text;
  1932. pid : longint;
  1933. pl : ^Longint;
  1934. begin
  1935. LinuxError:=0;
  1936. AssignPipe(streamin,pipo);
  1937. if Linuxerror<>0 then
  1938. exit;
  1939. AssignPipe(pipi,streamout);
  1940. if Linuxerror<>0 then
  1941. exit;
  1942. pid:=fork;
  1943. if linuxerror<>0 then
  1944. begin
  1945. close(pipi);
  1946. close(pipo);
  1947. close (streamin);
  1948. close (streamout);
  1949. exit;
  1950. end;
  1951. if pid=0 then
  1952. begin
  1953. { We're in the child }
  1954. { Close what we don't need }
  1955. close(streamout);
  1956. close(streamin);
  1957. dup2(pipi,input);
  1958. if linuxerror<>0 then
  1959. halt(127);
  1960. close(pipi);
  1961. dup2(pipo,output);
  1962. if linuxerror<>0 then
  1963. halt (127);
  1964. close(pipo);
  1965. Execl(Prog);
  1966. halt(127);
  1967. end
  1968. else
  1969. begin
  1970. { we're in the parent}
  1971. close(pipo);
  1972. close(pipi);
  1973. {Save the process ID - needed when closing }
  1974. pl:=@(textrec(StreamIn).userdata[2]);
  1975. pl^:=pid;
  1976. textrec(StreamIn).closefunc:=@PCloseText;
  1977. {Save the process ID - needed when closing }
  1978. pl:=@(textrec(StreamOut).userdata[2]);
  1979. pl^:=pid;
  1980. textrec(StreamOut).closefunc:=@PCloseText;
  1981. end;
  1982. end;
  1983. {******************************************************************************
  1984. General information calls
  1985. ******************************************************************************}
  1986. Function Sysinfo(var Info:TSysinfo):Boolean;
  1987. {
  1988. Get system info
  1989. }
  1990. var
  1991. regs : SysCallregs;
  1992. Begin
  1993. regs.reg2:=longint(@info);
  1994. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
  1995. End;
  1996. Function Uname(var unamerec:utsname):Boolean;
  1997. {
  1998. Get machine's names
  1999. }
  2000. var
  2001. regs : SysCallregs;
  2002. Begin
  2003. regs.reg2:=longint(@unamerec);
  2004. Uname:=SysCall(SysCall_nr_uname,regs)=0;
  2005. LinuxError:=Errno;
  2006. End;
  2007. Function GetEnv(P:string):Pchar;
  2008. {
  2009. Searches the environment for a string with name p and
  2010. returns a pchar to it's value.
  2011. A pchar is used to accomodate for strings of length > 255
  2012. }
  2013. var
  2014. ep : ppchar;
  2015. found : boolean;
  2016. Begin
  2017. p:=p+'='; {Else HOST will also find HOSTNAME, etc}
  2018. ep:=envp;
  2019. found:=false;
  2020. if ep<>nil then
  2021. begin
  2022. while (not found) and (ep^<>nil) do
  2023. begin
  2024. if strlcomp(@p[1],(ep^),length(p))=0 then
  2025. found:=true
  2026. else
  2027. ep:=ep+4;
  2028. end;
  2029. end;
  2030. if found then
  2031. getenv:=ep^+length(p)
  2032. else
  2033. getenv:=nil;
  2034. end;
  2035. Function GetDomainName:String;
  2036. {
  2037. Get machines domain name. Returns empty string if not set.
  2038. }
  2039. Var
  2040. Sysn : utsname;
  2041. begin
  2042. Uname(Sysn);
  2043. linuxerror:=errno;
  2044. If linuxerror<>0 then
  2045. getdomainname:=''
  2046. else
  2047. getdomainname:=strpas(@Sysn.domainname[0]);
  2048. end;
  2049. Function GetHostName:String;
  2050. {
  2051. Get machines name. Returns empty string if not set.
  2052. }
  2053. Var
  2054. Sysn : utsname;
  2055. begin
  2056. uname(Sysn);
  2057. linuxerror:=errno;
  2058. If linuxerror<>0 then
  2059. gethostname:=''
  2060. else
  2061. gethostname:=strpas(@Sysn.nodename[0]);
  2062. end;
  2063. {******************************************************************************
  2064. Signal handling calls
  2065. ******************************************************************************}
  2066. Function Kill(Pid:longint;Sig:integer):integer;
  2067. {
  2068. Send signal 'sig' to a process, or a group of processes.
  2069. If Pid > 0 then the signal is sent to pid
  2070. pid=-1 to all processes except process 1
  2071. pid < -1 to process group -pid
  2072. Return value is zero, except for case three, where the return value
  2073. is the number of processes to which the signal was sent.
  2074. }
  2075. var
  2076. regs : Syscallregs;
  2077. begin
  2078. regs.reg2:=Pid;
  2079. regs.reg3:=Sig;
  2080. kill:=SysCall(Syscall_nr_kill,regs);
  2081. if kill<0 then
  2082. Kill:=0;
  2083. linuxerror:=errno;
  2084. end;
  2085. Procedure SigAction(Signum:Integer;Var Act,OldAct:PSigActionRec );
  2086. {
  2087. Change action of process upon receipt of a signal.
  2088. Signum specifies the signal (all except SigKill and SigStop).
  2089. If Act is non-nil, it is used to specify the new action.
  2090. If OldAct is non-nil the previous action is saved there.
  2091. }
  2092. Var
  2093. sr : Syscallregs;
  2094. begin
  2095. sr.reg2:=Signum;
  2096. sr.reg3:=Longint(act);
  2097. sr.reg4:=Longint(oldact);
  2098. SysCall(Syscall_nr_sigaction,sr);
  2099. linuxerror:=errno;
  2100. end;
  2101. Procedure SigProcMask(How:Integer;SSet,OldSSet:PSigSet);
  2102. {
  2103. Change the list of currently blocked signals.
  2104. How determines which signals will be blocked :
  2105. SigBlock : Add SSet to the current list of blocked signals
  2106. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  2107. SigSetMask : Set the list of blocked signals to SSet
  2108. if OldSSet is non-null, the old set will be saved there.
  2109. }
  2110. Var
  2111. sr : SyscallRegs;
  2112. begin
  2113. sr.reg2:=how;
  2114. sr.reg3:=longint(SSet);
  2115. sr.reg4:=longint(OldSSet);
  2116. SysCall(Syscall_nr_sigprocmask,sr);
  2117. linuxerror:=errno;
  2118. end;
  2119. Function SigPending:SigSet;
  2120. {
  2121. Allows examination of pending signals. The signal mask of pending
  2122. signals is set in SSet
  2123. }
  2124. Var
  2125. sr : SyscallRegs;
  2126. dummy : Sigset;
  2127. begin
  2128. sr.reg2:=longint(@dummy);
  2129. SysCall(Syscall_nr_sigpending,sr);
  2130. linuxerror:=errno;
  2131. Sigpending:=dummy;
  2132. end;
  2133. Procedure SigSuspend(Mask:Sigset);
  2134. {
  2135. Set the signal mask with Mask, and suspend the program until a signal
  2136. is received.
  2137. }
  2138. Var
  2139. sr : SyscallRegs;
  2140. begin
  2141. sr.reg2:=mask;
  2142. SysCall(Syscall_nr_sigsuspend,sr);
  2143. linuxerror:=errno;
  2144. end;
  2145. Function Signal(Signum:Integer;Handler:SignalHandler):SignalHandler;
  2146. {
  2147. Install a new handler for signal Signum.
  2148. The old signal handler is returned.
  2149. This call does, in fact, the same as SigAction.
  2150. }
  2151. var
  2152. sr : Syscallregs;
  2153. begin
  2154. sr.reg2:=signum;
  2155. sr.reg3:=longint(handler);
  2156. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  2157. If linuxerror=Sig_Err then
  2158. begin
  2159. Signal:=nil;
  2160. Linuxerror:=errno;
  2161. end
  2162. else
  2163. begin
  2164. Signal:=signalhandler(Linuxerror);
  2165. linuxerror:=0;
  2166. end;
  2167. end;
  2168. {******************************************************************************
  2169. IOCtl and Termios calls
  2170. ******************************************************************************}
  2171. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  2172. {
  2173. Interface to Unix ioctl call.
  2174. Performs various operations on the filedescriptor Handle.
  2175. Ndx describes the operation to perform.
  2176. Data points to data needed for the Ndx function. The structure of this
  2177. data is function-dependent.
  2178. }
  2179. var
  2180. sr: SysCallRegs;
  2181. begin
  2182. sr.reg2:=Handle;
  2183. sr.reg3:=Ndx;
  2184. sr.reg4:=Longint(Data);
  2185. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  2186. LinuxError:=Errno;
  2187. end;
  2188. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  2189. begin
  2190. TCGetAttr:=IOCtl(fd,TCGETS,@tios);
  2191. end;
  2192. Function TCSetAttr(fd:longint;OptAct:longint;var tios:TermIOS):boolean;
  2193. var
  2194. nr:longint;
  2195. begin
  2196. case OptAct of
  2197. TCSANOW : nr:=TCSETS;
  2198. TCSADRAIN : nr:=TCSETSW;
  2199. TCSAFLUSH : nr:=TCSETSF;
  2200. else
  2201. begin
  2202. ErrNo:=Sys_EINVAL;
  2203. TCSetAttr:=false;
  2204. exit;
  2205. end;
  2206. end;
  2207. TCSetAttr:=IOCtl(fd,nr,@Tios);
  2208. end;
  2209. Procedure CFSetISpeed(var tios:TermIOS;speed:Longint);
  2210. begin
  2211. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  2212. end;
  2213. Procedure CFSetOSpeed(var tios:TermIOS;speed:Longint);
  2214. begin
  2215. CFSetISpeed(tios,speed);
  2216. end;
  2217. Procedure CFMakeRaw(var tios:TermIOS);
  2218. begin
  2219. with tios do
  2220. begin
  2221. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  2222. INLCR or IGNCR or ICRNL or IXON));
  2223. c_oflag:=c_oflag and (not OPOST);
  2224. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  2225. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  2226. end;
  2227. end;
  2228. Function TCSendBreak(fd,duration:longint):boolean;
  2229. begin
  2230. TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
  2231. end;
  2232. Function TCSetPGrp(fd,id:longint):boolean;
  2233. begin
  2234. TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
  2235. end;
  2236. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  2237. begin
  2238. TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
  2239. end;
  2240. Function TCDrain(fd:longint):boolean;
  2241. begin
  2242. TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
  2243. end;
  2244. Function TCFlow(fd,act:longint):boolean;
  2245. begin
  2246. TCFlow:=IOCtl(fd,TCXONC,pointer(act));
  2247. end;
  2248. Function TCFlush(fd,qsel:longint):boolean;
  2249. begin
  2250. TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
  2251. end;
  2252. Function IsATTY(Handle:Longint):Boolean;
  2253. {
  2254. Check if the filehandle described by 'handle' is a TTY (Terminal)
  2255. }
  2256. var
  2257. t : Termios;
  2258. begin
  2259. IsAtty:=TCGetAttr(Handle,t);
  2260. end;
  2261. Function IsATTY(f: text):Boolean;
  2262. {
  2263. Idem as previous, only now for text variables.
  2264. }
  2265. begin
  2266. IsATTY:=IsaTTY(textrec(f).handle);
  2267. end;
  2268. function TTYName(Handle:Longint):string;
  2269. {
  2270. Return the name of the current tty described by handle f.
  2271. returns empty string in case of an error.
  2272. }
  2273. Const
  2274. dev='/dev';
  2275. var
  2276. name : string;
  2277. st : stat;
  2278. mydev,
  2279. myino : longint;
  2280. dirstream : pdir;
  2281. d : pdirent;
  2282. begin
  2283. TTYName:='';
  2284. fstat(handle,st);
  2285. if (errno<>0) and isatty (handle) then
  2286. exit;
  2287. mydev:=st.dev;
  2288. myino:=st.ino;
  2289. dirstream:=opendir(dev);
  2290. if (linuxerror<>0) then
  2291. exit;
  2292. d:=Readdir(dirstream);
  2293. while (d<>nil) do
  2294. begin
  2295. if (d^.ino=myino) then
  2296. begin
  2297. name:=dev+'/'+strpas(@(d^.name));
  2298. fstat(name,st);
  2299. if (linuxerror=0) and (st.dev=mydev) then
  2300. begin
  2301. closedir(dirstream);
  2302. ttyname:=name;
  2303. exit;
  2304. end;
  2305. end;
  2306. d:=Readdir(dirstream);
  2307. end;
  2308. closedir(dirstream);
  2309. end;
  2310. function TTYName(var F:Text):string;
  2311. {
  2312. Idem as previous, only now for text variables;
  2313. }
  2314. begin
  2315. TTYName:=TTYName(textrec(f).handle);
  2316. end;
  2317. {******************************************************************************
  2318. Utility calls
  2319. ******************************************************************************}
  2320. Function Octal(l:longint):longint;
  2321. {
  2322. Convert an octal specified number to decimal;
  2323. }
  2324. var
  2325. octnr,
  2326. oct : longint;
  2327. begin
  2328. octnr:=0;
  2329. oct:=0;
  2330. while (l>0) do
  2331. begin
  2332. oct:=oct or ((l mod 10) shl octnr);
  2333. l:=l div 10;
  2334. inc(octnr,3);
  2335. end;
  2336. Octal:=oct;
  2337. end;
  2338. Function StringToPPChar(Var S:STring):ppchar;
  2339. {
  2340. Create a PPChar to structure of pchars which are the arguments specified
  2341. in the string S. Especially usefull for creating an ArgV for Exec-calls
  2342. }
  2343. var
  2344. nr : longint;
  2345. Buf : ^char;
  2346. p : ppchar;
  2347. begin
  2348. s:=s+#0;
  2349. buf:=@s[1];
  2350. nr:=0;
  2351. while(buf^<>#0) do
  2352. begin
  2353. while (buf^ in [' ',#8,#10]) do
  2354. buf:=buf+1;
  2355. inc(nr);
  2356. while not (buf^ in [' ',#0,#8,#10]) do
  2357. buf:=buf+1;
  2358. end;
  2359. getmem(p,nr*4);
  2360. StringToPPChar:=p;
  2361. if p=nil then
  2362. begin
  2363. LinuxError:=sys_enomem;
  2364. exit;
  2365. end;
  2366. buf:=@s[1];
  2367. while (buf^<>#0) do
  2368. begin
  2369. while (buf^ in [' ',#8,#10]) do
  2370. begin
  2371. buf^:=#0;
  2372. buf:=buf+1;
  2373. end;
  2374. p^:=buf;
  2375. p:=p+4;
  2376. p^:=nil;
  2377. while not (buf^ in [' ',#0,#8,#10]) do
  2378. buf:=buf+1;
  2379. end;
  2380. end;
  2381. Function FExpand(Const Path:PathStr):PathStr;
  2382. var
  2383. temp : pathstr;
  2384. i,j : longint;
  2385. p : pchar;
  2386. Begin
  2387. {Remove eventual drive - doesn't exist in Linux}
  2388. if path[2]=':' then
  2389. i:=3
  2390. else
  2391. i:=1;
  2392. temp:='';
  2393. {Replace ~/ with $HOME}
  2394. if (path[i]='~') and ((i+1>length(path)) or (path[i+1]='/')) then
  2395. begin
  2396. p:=getenv('HOME');
  2397. if not (p=nil) then
  2398. Insert(StrPas(p),temp,i);
  2399. i:=1;
  2400. temp:=temp+Copy(Path,2,255);
  2401. end;
  2402. {Do we have an absolute path ? No - prefix the current dir}
  2403. if temp='' then
  2404. begin
  2405. if path[i]<>'/' then
  2406. getdir(0,temp)
  2407. else
  2408. inc(i);
  2409. temp:=temp+'/'+copy(path,i,length(path)-i+1)+'/';
  2410. end;
  2411. {First remove all references to '/./'}
  2412. while pos('/./',temp)<>0 do
  2413. delete(temp,pos('/./',temp),2);
  2414. {Now remove also all references to '/../' + of course previous dirs..}
  2415. repeat
  2416. i:=pos('/../',temp);
  2417. {Find the pos of the previous dir}
  2418. if i>1 then
  2419. begin
  2420. j:=i-1;
  2421. while (j>1) and (temp[j]<>'/') do
  2422. dec (j);{temp[1] is always '/'}
  2423. delete(temp,j,i-j+3);
  2424. end
  2425. else
  2426. if i=1 then {i=1, so we have temp='/../something', just delete '/../'}
  2427. delete(temp,1,3);
  2428. until i=0;
  2429. { Remove ending /.. }
  2430. i:=pos('/..',temp);
  2431. if (i<>0) and (i =length(temp)-2) then
  2432. begin
  2433. j:=i-1;
  2434. while (j>1) and (temp[j]<>'/') do
  2435. dec (j);
  2436. delete (temp,j,i-j+3);
  2437. end;
  2438. { if last character is / then remove it - dir is also a file :-) }
  2439. if (length(temp)>0) and (temp[length(temp)]='/') then
  2440. dec(byte(temp[0]));
  2441. fexpand:=temp;
  2442. End;
  2443. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  2444. {
  2445. Searches for a file 'path' in the list of direcories in 'dirlist'.
  2446. returns an empty string if not found. Wildcards are NOT allowed.
  2447. If dirlist is empty, it is set to '.'
  2448. }
  2449. Var
  2450. NewDir : PathStr;
  2451. p1 : Longint;
  2452. Info : Stat;
  2453. Begin
  2454. {Replace ':' with ';'}
  2455. for p1:=1to length(dirlist) do
  2456. if dirlist[p1]=':' then
  2457. dirlist[p1]:=';';
  2458. {Check for WildCards}
  2459. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  2460. FSearch:='' {No wildcards allowed in these things.}
  2461. Else
  2462. Begin
  2463. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  2464. Repeat
  2465. p1:=Pos(';',DirList);
  2466. If p1=0 Then
  2467. p1:=255;
  2468. NewDir:=Copy(DirList,1,P1 - 1);
  2469. if NewDir[Length(NewDir)]<>'/' then
  2470. NewDir:=NewDir+'/';
  2471. NewDir:=NewDir+Path;
  2472. Delete(DirList,1,p1);
  2473. if FStat(NewDir,Info) then
  2474. Begin
  2475. If Pos('./',NewDir)=1 Then
  2476. Delete(NewDir,1,2);
  2477. {DOS strips off an initial .\}
  2478. End
  2479. Else
  2480. NewDir:='';
  2481. Until (DirList='') or (Length(NewDir) > 0);
  2482. FSearch:=NewDir;
  2483. End;
  2484. End;
  2485. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  2486. Var
  2487. DotPos,SlashPos,i : longint;
  2488. Begin
  2489. SlashPos:=0;
  2490. DotPos:=256;
  2491. i:=Length(Path);
  2492. While (i>0) and (SlashPos=0) Do
  2493. Begin
  2494. If (DotPos=256) and (Path[i]='.') Then
  2495. DotPos:=i;
  2496. If (Path[i]='/') Then
  2497. SlashPos:=i;
  2498. Dec(i);
  2499. End;
  2500. Ext:=Copy(Path,DotPos,255);
  2501. Dir:=Copy(Path,1,SlashPos);
  2502. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  2503. End;
  2504. Function Dirname(Const path:pathstr):pathstr;
  2505. {
  2506. This function returns the directory part of a complete path.
  2507. Unless the directory is root '/', The last character is not
  2508. a slash.
  2509. }
  2510. var
  2511. Dir : PathStr;
  2512. Name : NameStr;
  2513. Ext : ExtStr;
  2514. begin
  2515. FSplit(Path,Dir,Name,Ext);
  2516. if length(Dir)>1 then
  2517. Delete(Dir,length(Dir),1);
  2518. DirName:=Dir;
  2519. end;
  2520. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  2521. {
  2522. This function returns the filename part of a complete path. If suf is
  2523. supplied, it is cut off the filename.
  2524. }
  2525. var
  2526. Dir : PathStr;
  2527. Name : NameStr;
  2528. Ext : ExtStr;
  2529. begin
  2530. FSplit(Path,Dir,Name,Ext);
  2531. if Suf<>Ext then
  2532. Name:=Name+Ext;
  2533. BaseName:=Name;
  2534. end;
  2535. Function FNMatch(const Pattern,Name:string):Boolean;
  2536. Var
  2537. LenPat,LenName : longint;
  2538. Function DoFNMatch(i,j:longint):Boolean;
  2539. Var
  2540. Found : boolean;
  2541. Begin
  2542. Found:=true;
  2543. While Found and (i<=LenPat) Do
  2544. Begin
  2545. Case Pattern[i] of
  2546. '?' : Found:=(j<=LenName);
  2547. '*' : Begin
  2548. {find the next character in pattern, different of ? and *}
  2549. while Found and (i<LenPat) do
  2550. begin
  2551. inc(i);
  2552. case Pattern[i] of
  2553. '*' : ;
  2554. '?' : begin
  2555. inc(j);
  2556. Found:=(j<=LenName);
  2557. end;
  2558. else
  2559. Found:=false;
  2560. end;
  2561. end;
  2562. {Now, find in name the character which i points to, if the * or ?
  2563. wasn't the last character in the pattern, else, use up all the
  2564. chars in name}
  2565. Found:=true;
  2566. if (i<=LenPat) then
  2567. begin
  2568. repeat
  2569. {find a letter (not only first !) which maches pattern[i]}
  2570. while (j<=LenName) and (name[j]<>pattern[i]) do
  2571. inc (j);
  2572. if (j<LenName) then
  2573. begin
  2574. if DoFnMatch(i+1,j+1) then
  2575. begin
  2576. i:=LenPat;
  2577. j:=LenName;{we can stop}
  2578. Found:=true;
  2579. end
  2580. else
  2581. inc(j);{We didn't find one, need to look further}
  2582. end;
  2583. until (j>=LenName);
  2584. end
  2585. else
  2586. j:=LenName;{we can stop}
  2587. end;
  2588. else {not a wildcard character in pattern}
  2589. Found:=(j<=LenName) and (pattern[i]=name[j]);
  2590. end;
  2591. inc(i);
  2592. inc(j);
  2593. end;
  2594. DoFnMatch:=Found and (j>LenName);
  2595. end;
  2596. Begin {start FNMatch}
  2597. LenPat:=Length(Pattern);
  2598. LenName:=Length(Name);
  2599. FNMatch:=DoFNMatch(1,1);
  2600. End;
  2601. Procedure Globfree(var p : pglob);
  2602. {
  2603. Release memory occupied by pglob structure, and names in it.
  2604. sets p to nil.
  2605. }
  2606. var
  2607. temp : pglob;
  2608. begin
  2609. while p<>nil do
  2610. begin
  2611. temp:=p^.next;
  2612. if p^.name<>nil then
  2613. freemem(p^.name,strlen(p^.name));
  2614. dispose(p);
  2615. p:=temp;
  2616. end;
  2617. end;
  2618. Function Glob(Const path:pathstr):pglob;
  2619. {
  2620. Fills a tglob structure with entries matching path,
  2621. and returns a pointer to it. Returns nil on error,
  2622. linuxerror is set accordingly.
  2623. }
  2624. var
  2625. temp : string[255];
  2626. thedir : pdir;
  2627. buffer : pdirent;
  2628. root,run : pglob;
  2629. begin
  2630. { Get directory }
  2631. if dirname(path)='' then
  2632. temp:='.'
  2633. else
  2634. temp:=dirname(path);
  2635. temp:=temp+#0;
  2636. thedir:=opendir(@temp[1]);
  2637. if thedir=nil then
  2638. begin
  2639. glob:=nil;
  2640. linuxerror:=errno;
  2641. exit;
  2642. end;
  2643. temp:=basename(path,'');{ get the pattern }
  2644. if thedir^.fd<0 then
  2645. begin
  2646. linuxerror:=errno;
  2647. glob:=nil;
  2648. exit;
  2649. end;
  2650. {get the entries}
  2651. new(root);
  2652. root^.next:=nil;
  2653. root^.name:=nil;
  2654. run:=root;
  2655. repeat
  2656. buffer:=Sys_readdir(thedir);
  2657. if buffer<>nil then
  2658. begin
  2659. if fnmatch(temp,strpas(@(buffer^.name[0]))) then
  2660. begin
  2661. { get memory for pglob }
  2662. new(run^.next);
  2663. if run^.next=nil then
  2664. begin
  2665. linuxerror:=Sys_ENOMEM;
  2666. globfree(root);
  2667. glob:=nil;
  2668. exit;
  2669. end
  2670. else
  2671. begin
  2672. run:=run^.next;
  2673. run^.next:=nil;
  2674. end;
  2675. { Get memory for name }
  2676. getmem(run^.name,strlen(@(buffer^.name[0]))+1);
  2677. if run^.name=nil then
  2678. begin
  2679. linuxerror:=Sys_ENOMEM;
  2680. globfree(root);
  2681. glob:=nil;
  2682. exit;
  2683. end;
  2684. move(buffer^.name[0],run^.name^,strlen(@(buffer^.name[0]))+1);
  2685. end;{ if fnmatch }
  2686. end { buffer <> nil }
  2687. else
  2688. begin
  2689. run:=root;
  2690. if root^.next<>nil then
  2691. root:=root^.next;{ put root on first entry}
  2692. if run<>nil then
  2693. begin
  2694. run^.next:=nil;
  2695. globfree(run);
  2696. end;
  2697. end;
  2698. until buffer=nil;
  2699. if root^.name=nil then
  2700. begin
  2701. dispose(root);
  2702. linuxerror:=0;
  2703. glob:=nil;
  2704. end
  2705. else
  2706. glob:=root;
  2707. end;
  2708. {--------------------------------
  2709. FiledescriptorSets
  2710. --------------------------------}
  2711. Procedure FD_Zero(var fds:fdSet);
  2712. {
  2713. Clear the set of filedescriptors
  2714. }
  2715. begin
  2716. FillChar(fds,sizeof(fdSet),0);
  2717. end;
  2718. Procedure FD_Clr(fd:longint;var fds:fdSet);
  2719. {
  2720. Remove fd from the set of filedescriptors
  2721. }
  2722. begin
  2723. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  2724. end;
  2725. Procedure FD_Set(fd:longint;var fds:fdSet);
  2726. {
  2727. Add fd to the set of filedescriptors
  2728. }
  2729. begin
  2730. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  2731. end;
  2732. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  2733. {
  2734. Test if fd is part of the set of filedescriptors
  2735. }
  2736. begin
  2737. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  2738. end;
  2739. Function GetFS (var T:Text):longint;
  2740. {
  2741. Get File Descriptor of a text file.
  2742. }
  2743. begin
  2744. if textrec(t).mode=fmclosed then
  2745. exit(-1)
  2746. else
  2747. GETFS:=textrec(t).Handle
  2748. end;
  2749. Function GetFS(Var F:File):longint;
  2750. {
  2751. Get File Descriptor of an unTyped file.
  2752. }
  2753. begin
  2754. { Handle and mode are on the same place in textrec and filerec. }
  2755. if filerec(f).mode=fmclosed then
  2756. exit(-1)
  2757. else
  2758. GETFS:=filerec(f).Handle
  2759. end;
  2760. {--------------------------------
  2761. Stat.Mode Macro's
  2762. --------------------------------}
  2763. Function S_ISLNK(m:integer):boolean;
  2764. {
  2765. Check mode field of inode for link.
  2766. }
  2767. begin
  2768. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  2769. end;
  2770. Function S_ISREG(m:integer):boolean;
  2771. {
  2772. Check mode field of inode for regular file.
  2773. }
  2774. begin
  2775. S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
  2776. end;
  2777. Function S_ISDIR(m:integer):boolean;
  2778. {
  2779. Check mode field of inode for directory.
  2780. }
  2781. begin
  2782. S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
  2783. end;
  2784. Function S_ISCHR(m:integer):boolean;
  2785. {
  2786. Check mode field of inode for character device.
  2787. }
  2788. begin
  2789. S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
  2790. end;
  2791. Function S_ISBLK(m:integer):boolean;
  2792. {
  2793. Check mode field of inode for block device.
  2794. }
  2795. begin
  2796. S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
  2797. end;
  2798. Function S_ISFIFO(m:integer):boolean;
  2799. {
  2800. Check mode field of inode for named pipe (FIFO).
  2801. }
  2802. begin
  2803. S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
  2804. end;
  2805. Function S_ISSOCK(m:integer):boolean;
  2806. {
  2807. Check mode field of inode for socket.
  2808. }
  2809. begin
  2810. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  2811. end;
  2812. {--------------------------------
  2813. Port IO functions
  2814. --------------------------------}
  2815. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  2816. {
  2817. Set permissions on NUM ports starting with port FROM to VALUE
  2818. this works ONLY as root.
  2819. }
  2820. Var
  2821. Sr : Syscallregs;
  2822. begin
  2823. Sr.Reg2:=From;
  2824. Sr.Reg3:=Num;
  2825. Sr.Reg4:=Value;
  2826. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  2827. LinuxError:=Errno;
  2828. end;
  2829. {$IFDEF I386}
  2830. Procedure WritePort (Port : Longint; Value : Byte);
  2831. {
  2832. Writes 'Value' to port 'Port'
  2833. }
  2834. begin
  2835. asm
  2836. movl 8(%ebp),%edx
  2837. movb 12(%ebp),%al
  2838. outb %al,%dx
  2839. end;
  2840. end;
  2841. Procedure WritePort (Port : Longint; Value : Word);
  2842. {
  2843. Writes 'Value' to port 'Port'
  2844. }
  2845. begin
  2846. asm
  2847. movl 8(%ebp),%edx
  2848. movw 12(%ebp),%ax
  2849. outw %ax,%dx
  2850. end ['EAX','EBX'];
  2851. end;
  2852. Procedure WritePort (Port : Longint; Value : Longint);
  2853. {
  2854. Writes 'Value' to port 'Port'
  2855. }
  2856. begin
  2857. asm
  2858. movl 8(%ebp),%edx
  2859. movl 12(%ebp),%eax
  2860. outl %eax,%dx
  2861. end ['EAX','EBX'];
  2862. end;
  2863. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  2864. {
  2865. Writes 'Count' longints from 'Buf' to Port
  2866. }
  2867. begin
  2868. asm
  2869. movl 16(%ebp),%ecx
  2870. movl 12(%ebp),%esi
  2871. movl 8(%ebp),%edx
  2872. cld
  2873. rep
  2874. outsl
  2875. end ['ECX','ESI','EDX'];
  2876. end;
  2877. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  2878. {
  2879. Writes 'Count' words from 'Buf' to Port
  2880. }
  2881. begin
  2882. asm
  2883. movl 16(%ebp),%ecx
  2884. movl 12(%ebp),%esi
  2885. movl 8(%ebp),%edx
  2886. cld
  2887. rep
  2888. outsw
  2889. end ['ECX','ESI','EDX'];
  2890. end;
  2891. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  2892. {
  2893. Writes 'Count' bytes from 'Buf' to Port
  2894. }
  2895. begin
  2896. asm
  2897. movl 16(%ebp),%ecx
  2898. movl 12(%ebp),%esi
  2899. movl 8(%ebp),%edx
  2900. cld
  2901. rep
  2902. outsb
  2903. end ['ECX','ESI','EDX'];
  2904. end;
  2905. Procedure ReadPort (Port : Longint; Var Value : Byte);
  2906. {
  2907. Reads 'Value' from port 'Port'
  2908. }
  2909. begin
  2910. asm
  2911. movl 8(%ebp),%edx
  2912. inb %dx,%al
  2913. andl $255,%eax
  2914. movl %eax,12(%ebp)
  2915. end ['EAX','EBX'];
  2916. end;
  2917. Procedure ReadPort (Port : Longint; Var Value : Word);
  2918. {
  2919. Reads 'Value' from port 'Port'
  2920. }
  2921. begin
  2922. asm
  2923. movl 8(%ebp),%edx
  2924. inw %dx,%ax
  2925. andl $65535,%eax
  2926. movl %eax,12(%ebp)
  2927. end ['EAX','EBX'];
  2928. end;
  2929. Procedure ReadPort (Port : Longint; Var Value : Longint);
  2930. {
  2931. Reads 'Value' from port 'Port'
  2932. }
  2933. begin
  2934. asm
  2935. movl 8(%ebp),%edx
  2936. inl %dx,%eax
  2937. movl %eax,12(%ebp)
  2938. end ['EAX','EBX'];
  2939. end;
  2940. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  2941. {
  2942. Reads 'Count' longints from port 'Port' to 'Buf'.
  2943. }
  2944. begin
  2945. asm
  2946. movl 16(%ebp),%ecx
  2947. movl 12(%ebp),%edi
  2948. movl 8(%ebp),%edx
  2949. cld
  2950. rep
  2951. insl
  2952. end ['ECX','ESI','EDX'];
  2953. end;
  2954. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  2955. {
  2956. Reads 'Count' words from port 'Port' to 'Buf'.
  2957. }
  2958. begin
  2959. asm
  2960. movl 16(%ebp),%ecx
  2961. movl 12(%ebp),%edi
  2962. movl 8(%ebp),%edx
  2963. cld
  2964. rep
  2965. insw
  2966. end ['ECX','ESI','EDX'];
  2967. end;
  2968. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  2969. {
  2970. Reads 'Count' bytes from port 'Port' to 'Buf'.
  2971. }
  2972. begin
  2973. asm
  2974. movl 16(%ebp),%ecx
  2975. movl 12(%ebp),%edi
  2976. movl 8(%ebp),%edx
  2977. cld
  2978. rep
  2979. insb
  2980. end ['ECX','ESI','EDX'];
  2981. end;
  2982. {$ENDIF}
  2983. Begin
  2984. InitEpochToLocal;
  2985. End.
  2986. {
  2987. $Log$
  2988. Revision 1.31 1999-02-22 11:47:42 peter
  2989. * fixed juliantogregorian (mailinglist)
  2990. Revision 1.29 1999/02/02 21:19:54 michael
  2991. Corrected wrong mode error in fdopen
  2992. Revision 1.28 1999/01/20 13:29:09 peter
  2993. * utimbuf alias added
  2994. Revision 1.27 1998/12/11 18:08:57 peter
  2995. * fixed assignstream
  2996. Revision 1.26 1998/11/24 15:30:12 michael
  2997. * Bugfix in assignstream. . Now wait is performed upon close
  2998. Revision 1.25 1998/11/16 10:21:28 peter
  2999. * fixes for H+
  3000. Revision 1.24 1998/11/10 14:57:53 peter
  3001. * renamed rename -> FRename
  3002. Revision 1.23 1998/10/30 15:47:11 peter
  3003. * fixed glob, which did not reset the root
  3004. Revision 1.22 1998/10/23 00:05:32 peter
  3005. * getenv with envp=nil check
  3006. Revision 1.21 1998/10/15 08:31:11 peter
  3007. * type aliases using delphi typenaming
  3008. Revision 1.20 1998/10/11 12:23:11 michael
  3009. + Implemented Rename
  3010. Revision 1.19 1998/09/18 09:56:33 peter
  3011. * merged
  3012. Revision 1.18.2.1 1998/09/18 09:53:46 peter
  3013. * fixed winsize record
  3014. Revision 1.18 1998/09/08 13:01:51 michael
  3015. + Signal call now correctly implemented
  3016. Revision 1.17 1998/08/19 00:50:31 peter
  3017. * 'i<>0 and ' needs brackets
  3018. Revision 1.16 1998/08/16 10:23:28 michael
  3019. fixed typos
  3020. Revision 1.15 1998/08/16 09:12:14 michael
  3021. Corrected fexpand behaviour.
  3022. Revision 1.14 1998/08/14 12:01:04 carl
  3023. * ifdef i386 for ports access
  3024. Revision 1.13 1998/08/12 11:10:25 michael
  3025. Added settimeofday function
  3026. Revision 1.12 1998/07/28 09:27:06 michael
  3027. restored previous version. A bug in the compiler prevents compilation.
  3028. Revision 1.10 1998/06/16 08:21:58 michael
  3029. * PClose didn't flush textfiles before closing. Now it does
  3030. Revision 1.9 1998/06/03 11:55:33 michael
  3031. + Added IO port calls
  3032. Revision 1.8 1998/05/06 18:45:32 peter
  3033. * fixed the shell() bug (the correct code was also in Popen) moved the
  3034. argv generation to CreateShellArgv
  3035. + Execve with pchar instead of string
  3036. Revision 1.7 1998/05/06 12:35:26 michael
  3037. + Removed log from before restored version.
  3038. Revision 1.6 1998/04/15 11:23:53 michael
  3039. + Added some calls to make common API more efficient
  3040. Revision 1.5 1998/04/10 15:23:03 michael
  3041. + Pclose now returns exit status of process
  3042. Revision 1.4 1998/04/07 13:08:29 michael
  3043. + Added flock for file locking
  3044. Revision 1.3 1998/04/07 12:27:41 peter
  3045. * fixed fexpand('..')
  3046. Revision 1.2 1998/04/04 17:07:17 michael
  3047. + Fixed AssignStream, it completely refused to work
  3048. }