linux.pp 77 KB

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