linux.pp 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574
  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. while (not found) and (ep^<>nil) do
  2016. begin
  2017. if strlcomp(@p[1],(ep^),length(p))=0 then
  2018. found:=true
  2019. else
  2020. ep:=ep+4;
  2021. end;
  2022. if found then
  2023. getenv:=ep^+length(p)
  2024. else
  2025. getenv:=nil;
  2026. end;
  2027. Function GetDomainName:String;
  2028. {
  2029. Get machines domain name. Returns empty string if not set.
  2030. }
  2031. Var
  2032. Sysn : utsname;
  2033. begin
  2034. Uname(Sysn);
  2035. linuxerror:=errno;
  2036. If linuxerror<>0 then
  2037. getdomainname:=''
  2038. else
  2039. getdomainname:=strpas(@Sysn.domainname[0]);
  2040. end;
  2041. Function GetHostName:String;
  2042. {
  2043. Get machines name. Returns empty string if not set.
  2044. }
  2045. Var
  2046. Sysn : utsname;
  2047. begin
  2048. uname(Sysn);
  2049. linuxerror:=errno;
  2050. If linuxerror<>0 then
  2051. gethostname:=''
  2052. else
  2053. gethostname:=strpas(@Sysn.nodename[0]);
  2054. end;
  2055. {******************************************************************************
  2056. Signal handling calls
  2057. ******************************************************************************}
  2058. Function Kill(Pid:longint;Sig:integer):integer;
  2059. {
  2060. Send signal 'sig' to a process, or a group of processes.
  2061. If Pid > 0 then the signal is sent to pid
  2062. pid=-1 to all processes except process 1
  2063. pid < -1 to process group -pid
  2064. Return value is zero, except for case three, where the return value
  2065. is the number of processes to which the signal was sent.
  2066. }
  2067. var
  2068. regs : Syscallregs;
  2069. begin
  2070. regs.reg2:=Pid;
  2071. regs.reg3:=Sig;
  2072. kill:=SysCall(Syscall_nr_kill,regs);
  2073. if kill<0 then
  2074. Kill:=0;
  2075. linuxerror:=errno;
  2076. end;
  2077. Procedure SigAction(Signum:Integer;Var Act,OldAct:PSigActionRec );
  2078. {
  2079. Change action of process upon receipt of a signal.
  2080. Signum specifies the signal (all except SigKill and SigStop).
  2081. If Act is non-nil, it is used to specify the new action.
  2082. If OldAct is non-nil the previous action is saved there.
  2083. }
  2084. Var
  2085. sr : Syscallregs;
  2086. begin
  2087. sr.reg2:=Signum;
  2088. sr.reg3:=Longint(act);
  2089. sr.reg4:=Longint(oldact);
  2090. SysCall(Syscall_nr_sigaction,sr);
  2091. linuxerror:=errno;
  2092. end;
  2093. Procedure SigProcMask(How:Integer;SSet,OldSSet:PSigSet);
  2094. {
  2095. Change the list of currently blocked signals.
  2096. How determines which signals will be blocked :
  2097. SigBlock : Add SSet to the current list of blocked signals
  2098. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  2099. SigSetMask : Set the list of blocked signals to SSet
  2100. if OldSSet is non-null, the old set will be saved there.
  2101. }
  2102. Var
  2103. sr : SyscallRegs;
  2104. begin
  2105. sr.reg2:=how;
  2106. sr.reg3:=longint(SSet);
  2107. sr.reg4:=longint(OldSSet);
  2108. SysCall(Syscall_nr_sigprocmask,sr);
  2109. linuxerror:=errno;
  2110. end;
  2111. Function SigPending:SigSet;
  2112. {
  2113. Allows examination of pending signals. The signal mask of pending
  2114. signals is set in SSet
  2115. }
  2116. Var
  2117. sr : SyscallRegs;
  2118. dummy : Sigset;
  2119. begin
  2120. sr.reg2:=longint(@dummy);
  2121. SysCall(Syscall_nr_sigpending,sr);
  2122. linuxerror:=errno;
  2123. Sigpending:=dummy;
  2124. end;
  2125. Procedure SigSuspend(Mask:Sigset);
  2126. {
  2127. Set the signal mask with Mask, and suspend the program until a signal
  2128. is received.
  2129. }
  2130. Var
  2131. sr : SyscallRegs;
  2132. begin
  2133. sr.reg2:=mask;
  2134. SysCall(Syscall_nr_sigsuspend,sr);
  2135. linuxerror:=errno;
  2136. end;
  2137. Function Signal(Signum:Integer;Handler:SignalHandler):SignalHandler;
  2138. {
  2139. Install a new handler for signal Signum.
  2140. The old signal handler is returned.
  2141. This call does, in fact, the same as SigAction.
  2142. }
  2143. var
  2144. sr : Syscallregs;
  2145. begin
  2146. sr.reg2:=signum;
  2147. sr.reg3:=longint(handler);
  2148. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  2149. If linuxerror=Sig_Err then
  2150. begin
  2151. Signal:=nil;
  2152. Linuxerror:=errno;
  2153. end
  2154. else
  2155. begin
  2156. Signal:=signalhandler(Linuxerror);
  2157. linuxerror:=0;
  2158. end;
  2159. end;
  2160. {******************************************************************************
  2161. IOCtl and Termios calls
  2162. ******************************************************************************}
  2163. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  2164. {
  2165. Interface to Unix ioctl call.
  2166. Performs various operations on the filedescriptor Handle.
  2167. Ndx describes the operation to perform.
  2168. Data points to data needed for the Ndx function. The structure of this
  2169. data is function-dependent.
  2170. }
  2171. var
  2172. sr: SysCallRegs;
  2173. begin
  2174. sr.reg2:=Handle;
  2175. sr.reg3:=Ndx;
  2176. sr.reg4:=Longint(Data);
  2177. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  2178. LinuxError:=Errno;
  2179. end;
  2180. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  2181. begin
  2182. TCGetAttr:=IOCtl(fd,TCGETS,@tios);
  2183. end;
  2184. Function TCSetAttr(fd:longint;OptAct:longint;var tios:TermIOS):boolean;
  2185. var
  2186. nr:longint;
  2187. begin
  2188. case OptAct of
  2189. TCSANOW : nr:=TCSETS;
  2190. TCSADRAIN : nr:=TCSETSW;
  2191. TCSAFLUSH : nr:=TCSETSF;
  2192. else
  2193. begin
  2194. ErrNo:=Sys_EINVAL;
  2195. TCSetAttr:=false;
  2196. exit;
  2197. end;
  2198. end;
  2199. TCSetAttr:=IOCtl(fd,nr,@Tios);
  2200. end;
  2201. Procedure CFSetISpeed(var tios:TermIOS;speed:Longint);
  2202. begin
  2203. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  2204. end;
  2205. Procedure CFSetOSpeed(var tios:TermIOS;speed:Longint);
  2206. begin
  2207. CFSetISpeed(tios,speed);
  2208. end;
  2209. Procedure CFMakeRaw(var tios:TermIOS);
  2210. begin
  2211. with tios do
  2212. begin
  2213. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  2214. INLCR or IGNCR or ICRNL or IXON));
  2215. c_oflag:=c_oflag and (not OPOST);
  2216. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  2217. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  2218. end;
  2219. end;
  2220. Function TCSendBreak(fd,duration:longint):boolean;
  2221. begin
  2222. TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
  2223. end;
  2224. Function TCSetPGrp(fd,id:longint):boolean;
  2225. begin
  2226. TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
  2227. end;
  2228. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  2229. begin
  2230. TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
  2231. end;
  2232. Function TCDrain(fd:longint):boolean;
  2233. begin
  2234. TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
  2235. end;
  2236. Function TCFlow(fd,act:longint):boolean;
  2237. begin
  2238. TCFlow:=IOCtl(fd,TCXONC,pointer(act));
  2239. end;
  2240. Function TCFlush(fd,qsel:longint):boolean;
  2241. begin
  2242. TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
  2243. end;
  2244. Function IsATTY(Handle:Longint):Boolean;
  2245. {
  2246. Check if the filehandle described by 'handle' is a TTY (Terminal)
  2247. }
  2248. var
  2249. t : Termios;
  2250. begin
  2251. IsAtty:=TCGetAttr(Handle,t);
  2252. end;
  2253. Function IsATTY(f: text):Boolean;
  2254. {
  2255. Idem as previous, only now for text variables.
  2256. }
  2257. begin
  2258. IsATTY:=IsaTTY(textrec(f).handle);
  2259. end;
  2260. function TTYName(Handle:Longint):string;
  2261. {
  2262. Return the name of the current tty described by handle f.
  2263. returns empty string in case of an error.
  2264. }
  2265. Const
  2266. dev='/dev';
  2267. var
  2268. name : string;
  2269. st : stat;
  2270. mydev,
  2271. myino : longint;
  2272. dirstream : pdir;
  2273. d : pdirent;
  2274. begin
  2275. TTYName:='';
  2276. fstat(handle,st);
  2277. if (errno<>0) and isatty (handle) then
  2278. exit;
  2279. mydev:=st.dev;
  2280. myino:=st.ino;
  2281. dirstream:=opendir(dev);
  2282. if (linuxerror<>0) then
  2283. exit;
  2284. d:=Readdir(dirstream);
  2285. while (d<>nil) do
  2286. begin
  2287. if (d^.ino=myino) then
  2288. begin
  2289. name:=dev+'/'+strpas(@(d^.name));
  2290. fstat(name,st);
  2291. if (linuxerror=0) and (st.dev=mydev) then
  2292. begin
  2293. closedir(dirstream);
  2294. ttyname:=name;
  2295. exit;
  2296. end;
  2297. end;
  2298. d:=Readdir(dirstream);
  2299. end;
  2300. closedir(dirstream);
  2301. end;
  2302. function TTYName(var F:Text):string;
  2303. {
  2304. Idem as previous, only now for text variables;
  2305. }
  2306. begin
  2307. TTYName:=TTYName(textrec(f).handle);
  2308. end;
  2309. {******************************************************************************
  2310. Utility calls
  2311. ******************************************************************************}
  2312. Function Octal(l:longint):longint;
  2313. {
  2314. Convert an octal specified number to decimal;
  2315. }
  2316. var
  2317. octnr,
  2318. oct : longint;
  2319. begin
  2320. octnr:=0;
  2321. oct:=0;
  2322. while (l>0) do
  2323. begin
  2324. oct:=oct or ((l mod 10) shl octnr);
  2325. l:=l div 10;
  2326. inc(octnr,3);
  2327. end;
  2328. Octal:=oct;
  2329. end;
  2330. Function StringToPPChar(Var S:STring):ppchar;
  2331. {
  2332. Create a PPChar to structure of pchars which are the arguments specified
  2333. in the string S. Especially usefull for creating an ArgV for Exec-calls
  2334. }
  2335. var
  2336. nr : longint;
  2337. Buf : ^char;
  2338. p : ppchar;
  2339. begin
  2340. s:=s+#0;
  2341. buf:=@s[1];
  2342. nr:=0;
  2343. while(buf^<>#0) do
  2344. begin
  2345. while (buf^ in [' ',#8,#10]) do
  2346. buf:=buf+1;
  2347. inc(nr);
  2348. while not (buf^ in [' ',#0,#8,#10]) do
  2349. buf:=buf+1;
  2350. end;
  2351. getmem(p,nr*4);
  2352. StringToPPChar:=p;
  2353. if p=nil then
  2354. begin
  2355. LinuxError:=sys_enomem;
  2356. exit;
  2357. end;
  2358. buf:=@s[1];
  2359. while (buf^<>#0) do
  2360. begin
  2361. while (buf^ in [' ',#8,#10]) do
  2362. begin
  2363. buf^:=#0;
  2364. buf:=buf+1;
  2365. end;
  2366. p^:=buf;
  2367. p:=p+4;
  2368. p^:=nil;
  2369. while not (buf^ in [' ',#0,#8,#10]) do
  2370. buf:=buf+1;
  2371. end;
  2372. end;
  2373. Function FExpand(Const Path:PathStr):PathStr;
  2374. var
  2375. temp : pathstr;
  2376. i,j : longint;
  2377. p : pchar;
  2378. Begin
  2379. {Remove eventual drive - doesn't exist in Linux}
  2380. if path[2]=':' then
  2381. i:=3
  2382. else
  2383. i:=1;
  2384. temp:='';
  2385. {Replace ~/ with $HOME}
  2386. if (path[i]='~') and ((i+1>length(path)) or (path[i+1]='/')) then
  2387. begin
  2388. p:=getenv('HOME');
  2389. if not (p=nil) then
  2390. Insert(StrPas(p),temp,i);
  2391. i:=1;
  2392. temp:=temp+Copy(Path,2,255);
  2393. end;
  2394. {Do we have an absolute path ? No - prefix the current dir}
  2395. if temp='' then
  2396. begin
  2397. if path[i]<>'/' then
  2398. getdir(0,temp)
  2399. else
  2400. inc(i);
  2401. temp:=temp+'/'+copy(path,i,length(path)-i+1)+'/';
  2402. end;
  2403. {First remove all references to '/./'}
  2404. while pos('/./',temp)<>0 do
  2405. delete(temp,pos('/./',temp),2);
  2406. {Now remove also all references to '/../' + of course previous dirs..}
  2407. repeat
  2408. i:=pos('/../',temp);
  2409. {Find the pos of the previous dir}
  2410. if i>1 then
  2411. begin
  2412. j:=i-1;
  2413. while (j>1) and (temp[j]<>'/') do
  2414. dec (j);{temp[1] is always '/'}
  2415. delete(temp,j,i-j+3);
  2416. end
  2417. else
  2418. if i=1 then {i=1, so we have temp='/../something', just delete '/../'}
  2419. delete(temp,1,3);
  2420. until i=0;
  2421. { Remove ending /.. }
  2422. i:=pos('/..',temp);
  2423. if (i<>0) and (i =length(temp)-2) then
  2424. begin
  2425. j:=i-1;
  2426. while (j>1) and (temp[j]<>'/') do
  2427. dec (j);
  2428. delete (temp,j,i-j+3);
  2429. end;
  2430. { if last character is / then remove it - dir is also a file :-) }
  2431. if (length(temp)>0) and (temp[length(temp)]='/') then
  2432. dec(byte(temp[0]));
  2433. fexpand:=temp;
  2434. End;
  2435. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  2436. {
  2437. Searches for a file 'path' in the list of direcories in 'dirlist'.
  2438. returns an empty string if not found. Wildcards are NOT allowed.
  2439. If dirlist is empty, it is set to '.'
  2440. }
  2441. Var
  2442. NewDir : PathStr;
  2443. p1 : Longint;
  2444. Info : Stat;
  2445. Begin
  2446. {Replace ':' with ';'}
  2447. for p1:=1to length(dirlist) do
  2448. if dirlist[p1]=':' then
  2449. dirlist[p1]:=';';
  2450. {Check for WildCards}
  2451. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  2452. FSearch:='' {No wildcards allowed in these things.}
  2453. Else
  2454. Begin
  2455. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  2456. Repeat
  2457. p1:=Pos(';',DirList);
  2458. If p1=0 Then
  2459. p1:=255;
  2460. NewDir:=Copy(DirList,1,P1 - 1);
  2461. if NewDir[Length(NewDir)]<>'/' then
  2462. NewDir:=NewDir+'/';
  2463. NewDir:=NewDir+Path;
  2464. Delete(DirList,1,p1);
  2465. if FStat(NewDir,Info) then
  2466. Begin
  2467. If Pos('./',NewDir)=1 Then
  2468. Delete(NewDir,1,2);
  2469. {DOS strips off an initial .\}
  2470. End
  2471. Else
  2472. NewDir:='';
  2473. Until (DirList='') or (Length(NewDir) > 0);
  2474. FSearch:=NewDir;
  2475. End;
  2476. End;
  2477. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  2478. Var
  2479. DotPos,SlashPos,i : longint;
  2480. Begin
  2481. SlashPos:=0;
  2482. DotPos:=256;
  2483. i:=Length(Path);
  2484. While (i>0) and (SlashPos=0) Do
  2485. Begin
  2486. If (DotPos=256) and (Path[i]='.') Then
  2487. DotPos:=i;
  2488. If (Path[i]='/') Then
  2489. SlashPos:=i;
  2490. Dec(i);
  2491. End;
  2492. Ext:=Copy(Path,DotPos,255);
  2493. Dir:=Copy(Path,1,SlashPos);
  2494. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  2495. End;
  2496. Function Dirname(Const path:pathstr):pathstr;
  2497. {
  2498. This function returns the directory part of a complete path.
  2499. Unless the directory is root '/', The last character is not
  2500. a slash.
  2501. }
  2502. var
  2503. Dir,Name,Ext : string;
  2504. begin
  2505. FSplit(Path,Dir,Name,Ext);
  2506. if length(Dir)>1 then
  2507. Delete(Dir,length(Dir),1);
  2508. DirName:=Dir;
  2509. end;
  2510. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  2511. {
  2512. This function returns the filename part of a complete path. If suf is
  2513. supplied, it is cut off the filename.
  2514. }
  2515. var
  2516. Dir,Name,Ext : string;
  2517. begin
  2518. FSplit(Path,Dir,Name,Ext);
  2519. if Suf<>Ext then
  2520. Name:=Name+Ext;
  2521. BaseName:=Name;
  2522. end;
  2523. Function FNMatch(const Pattern,Name:string):Boolean;
  2524. Var
  2525. LenPat,LenName : longint;
  2526. Function DoFNMatch(i,j:longint):Boolean;
  2527. Var
  2528. Found : boolean;
  2529. Begin
  2530. Found:=true;
  2531. While Found and (i<=LenPat) Do
  2532. Begin
  2533. Case Pattern[i] of
  2534. '?' : Found:=(j<=LenName);
  2535. '*' : Begin
  2536. {find the next character in pattern, different of ? and *}
  2537. while Found and (i<LenPat) do
  2538. begin
  2539. inc(i);
  2540. case Pattern[i] of
  2541. '*' : ;
  2542. '?' : begin
  2543. inc(j);
  2544. Found:=(j<=LenName);
  2545. end;
  2546. else
  2547. Found:=false;
  2548. end;
  2549. end;
  2550. {Now, find in name the character which i points to, if the * or ?
  2551. wasn't the last character in the pattern, else, use up all the
  2552. chars in name}
  2553. Found:=true;
  2554. if (i<=LenPat) then
  2555. begin
  2556. repeat
  2557. {find a letter (not only first !) which maches pattern[i]}
  2558. while (j<=LenName) and (name[j]<>pattern[i]) do
  2559. inc (j);
  2560. if (j<LenName) then
  2561. begin
  2562. if DoFnMatch(i+1,j+1) then
  2563. begin
  2564. i:=LenPat;
  2565. j:=LenName;{we can stop}
  2566. Found:=true;
  2567. end
  2568. else
  2569. inc(j);{We didn't find one, need to look further}
  2570. end;
  2571. until (j>=LenName);
  2572. end
  2573. else
  2574. j:=LenName;{we can stop}
  2575. end;
  2576. else {not a wildcard character in pattern}
  2577. Found:=(j<=LenName) and (pattern[i]=name[j]);
  2578. end;
  2579. inc(i);
  2580. inc(j);
  2581. end;
  2582. DoFnMatch:=Found and (j>LenName);
  2583. end;
  2584. Begin {start FNMatch}
  2585. LenPat:=Length(Pattern);
  2586. LenName:=Length(Name);
  2587. FNMatch:=DoFNMatch(1,1);
  2588. End;
  2589. Procedure Globfree(var p : pglob);
  2590. {
  2591. Release memory occupied by pglob structure, and names in it.
  2592. sets p to nil.
  2593. }
  2594. var
  2595. temp : pglob;
  2596. begin
  2597. while p<>nil do
  2598. begin
  2599. temp:=p^.next;
  2600. if p^.name<>nil then
  2601. freemem(p^.name,strlen(p^.name));
  2602. dispose(p);
  2603. p:=temp;
  2604. end;
  2605. end;
  2606. Function Glob(Const path:pathstr):pglob;
  2607. {
  2608. Fills a tglob structure with entries matching path,
  2609. and returns a pointer to it. Returns nil on error,
  2610. linuxerror is set accordingly.
  2611. }
  2612. var
  2613. temp : string[255];
  2614. thedir : pdir;
  2615. buffer : pdirent;
  2616. root,run : pglob;
  2617. begin
  2618. { Get directory }
  2619. if dirname(path)='' then
  2620. temp:='.'
  2621. else
  2622. temp:=dirname(path);
  2623. temp:=temp+#0;
  2624. thedir:=opendir(@temp[1]);
  2625. if thedir=nil then
  2626. begin
  2627. glob:=nil;
  2628. linuxerror:=errno;
  2629. exit;
  2630. end;
  2631. temp:=basename(path,'');{ get the pattern }
  2632. if thedir^.fd<0 then
  2633. begin
  2634. linuxerror:=errno;
  2635. glob:=nil;
  2636. exit;
  2637. end;
  2638. {get the entries}
  2639. new(root);
  2640. run:=root;
  2641. repeat
  2642. buffer:=Sys_readdir(thedir);
  2643. if buffer<>nil then
  2644. begin
  2645. if fnmatch(temp,strpas(@(buffer^.name[0]))) then
  2646. begin
  2647. { get memory for pglob }
  2648. new(run^.next);
  2649. if run^.next=nil then
  2650. begin
  2651. linuxerror:=Sys_ENOMEM;
  2652. globfree(root);
  2653. glob:=nil;
  2654. exit;
  2655. end
  2656. else
  2657. begin
  2658. run:=run^.next;
  2659. run^.next:=nil;
  2660. end;
  2661. { Get memory for name }
  2662. getmem(run^.name,strlen(@(buffer^.name[0]))+1);
  2663. if run^.name=nil then
  2664. begin
  2665. linuxerror:=Sys_ENOMEM;
  2666. globfree(root);
  2667. glob:=nil;
  2668. exit;
  2669. end;
  2670. move(buffer^.name[0],run^.name^,strlen(@(buffer^.name[0]))+1);
  2671. end;{ if fnmatch }
  2672. end { buffer <> nil }
  2673. else
  2674. begin
  2675. run:=root;
  2676. if root^.next<>nil then
  2677. root:=root^.next;{ put root on first entry}
  2678. if run<>nil then
  2679. begin
  2680. run^.next:=nil;
  2681. globfree(run);
  2682. end;
  2683. end;
  2684. until buffer=nil;
  2685. if root^.name=nil then
  2686. begin
  2687. dispose(root);
  2688. linuxerror:=0;
  2689. glob:=nil;
  2690. end
  2691. else
  2692. glob:=root;
  2693. end;
  2694. {--------------------------------
  2695. FiledescriptorSets
  2696. --------------------------------}
  2697. Procedure FD_Zero(var fds:fdSet);
  2698. {
  2699. Clear the set of filedescriptors
  2700. }
  2701. begin
  2702. FillChar(fds,sizeof(fdSet),0);
  2703. end;
  2704. Procedure FD_Clr(fd:longint;var fds:fdSet);
  2705. {
  2706. Remove fd from the set of filedescriptors
  2707. }
  2708. begin
  2709. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  2710. end;
  2711. Procedure FD_Set(fd:longint;var fds:fdSet);
  2712. {
  2713. Add fd to the set of filedescriptors
  2714. }
  2715. begin
  2716. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  2717. end;
  2718. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  2719. {
  2720. Test if fd is part of the set of filedescriptors
  2721. }
  2722. begin
  2723. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  2724. end;
  2725. Function GetFS (var T:Text):longint;
  2726. {
  2727. Get File Descriptor of a text file.
  2728. }
  2729. begin
  2730. if textrec(t).mode=fmclosed then
  2731. exit(-1)
  2732. else
  2733. GETFS:=textrec(t).Handle
  2734. end;
  2735. Function GetFS(Var F:File):longint;
  2736. {
  2737. Get File Descriptor of an unTyped file.
  2738. }
  2739. begin
  2740. { Handle and mode are on the same place in textrec and filerec. }
  2741. if filerec(f).mode=fmclosed then
  2742. exit(-1)
  2743. else
  2744. GETFS:=filerec(f).Handle
  2745. end;
  2746. {--------------------------------
  2747. Stat.Mode Macro's
  2748. --------------------------------}
  2749. Function S_ISLNK(m:integer):boolean;
  2750. {
  2751. Check mode field of inode for link.
  2752. }
  2753. begin
  2754. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  2755. end;
  2756. Function S_ISREG(m:integer):boolean;
  2757. {
  2758. Check mode field of inode for regular file.
  2759. }
  2760. begin
  2761. S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
  2762. end;
  2763. Function S_ISDIR(m:integer):boolean;
  2764. {
  2765. Check mode field of inode for directory.
  2766. }
  2767. begin
  2768. S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
  2769. end;
  2770. Function S_ISCHR(m:integer):boolean;
  2771. {
  2772. Check mode field of inode for character device.
  2773. }
  2774. begin
  2775. S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
  2776. end;
  2777. Function S_ISBLK(m:integer):boolean;
  2778. {
  2779. Check mode field of inode for block device.
  2780. }
  2781. begin
  2782. S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
  2783. end;
  2784. Function S_ISFIFO(m:integer):boolean;
  2785. {
  2786. Check mode field of inode for named pipe (FIFO).
  2787. }
  2788. begin
  2789. S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
  2790. end;
  2791. Function S_ISSOCK(m:integer):boolean;
  2792. {
  2793. Check mode field of inode for socket.
  2794. }
  2795. begin
  2796. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  2797. end;
  2798. {--------------------------------
  2799. Port IO functions
  2800. --------------------------------}
  2801. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  2802. {
  2803. Set permissions on NUM ports starting with port FROM to VALUE
  2804. this works ONLY as root.
  2805. }
  2806. Var
  2807. Sr : Syscallregs;
  2808. begin
  2809. Sr.Reg2:=From;
  2810. Sr.Reg3:=Num;
  2811. Sr.Reg4:=Value;
  2812. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  2813. LinuxError:=Errno;
  2814. end;
  2815. {$IFDEF I386}
  2816. Procedure WritePort (Port : Longint; Value : Byte);
  2817. {
  2818. Writes 'Value' to port 'Port'
  2819. }
  2820. begin
  2821. asm
  2822. movl 8(%ebp),%edx
  2823. movb 12(%ebp),%al
  2824. outb %al,%dx
  2825. end;
  2826. end;
  2827. Procedure WritePort (Port : Longint; Value : Word);
  2828. {
  2829. Writes 'Value' to port 'Port'
  2830. }
  2831. begin
  2832. asm
  2833. movl 8(%ebp),%edx
  2834. movw 12(%ebp),%ax
  2835. outw %ax,%dx
  2836. end ['EAX','EBX'];
  2837. end;
  2838. Procedure WritePort (Port : Longint; Value : Longint);
  2839. {
  2840. Writes 'Value' to port 'Port'
  2841. }
  2842. begin
  2843. asm
  2844. movl 8(%ebp),%edx
  2845. movl 12(%ebp),%eax
  2846. outl %eax,%dx
  2847. end ['EAX','EBX'];
  2848. end;
  2849. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  2850. {
  2851. Writes 'Count' longints from 'Buf' to Port
  2852. }
  2853. begin
  2854. asm
  2855. movl 16(%ebp),%ecx
  2856. movl 12(%ebp),%esi
  2857. movl 8(%ebp),%edx
  2858. cld
  2859. rep
  2860. outsl
  2861. end ['ECX','ESI','EDX'];
  2862. end;
  2863. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  2864. {
  2865. Writes 'Count' words from 'Buf' to Port
  2866. }
  2867. begin
  2868. asm
  2869. movl 16(%ebp),%ecx
  2870. movl 12(%ebp),%esi
  2871. movl 8(%ebp),%edx
  2872. cld
  2873. rep
  2874. outsw
  2875. end ['ECX','ESI','EDX'];
  2876. end;
  2877. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  2878. {
  2879. Writes 'Count' bytes from 'Buf' to Port
  2880. }
  2881. begin
  2882. asm
  2883. movl 16(%ebp),%ecx
  2884. movl 12(%ebp),%esi
  2885. movl 8(%ebp),%edx
  2886. cld
  2887. rep
  2888. outsb
  2889. end ['ECX','ESI','EDX'];
  2890. end;
  2891. Procedure ReadPort (Port : Longint; Var Value : Byte);
  2892. {
  2893. Reads 'Value' from port 'Port'
  2894. }
  2895. begin
  2896. asm
  2897. movl 8(%ebp),%edx
  2898. inb %dx,%al
  2899. andl $255,%eax
  2900. movl %eax,12(%ebp)
  2901. end ['EAX','EBX'];
  2902. end;
  2903. Procedure ReadPort (Port : Longint; Var Value : Word);
  2904. {
  2905. Reads 'Value' from port 'Port'
  2906. }
  2907. begin
  2908. asm
  2909. movl 8(%ebp),%edx
  2910. inw %dx,%ax
  2911. andl $65535,%eax
  2912. movl %eax,12(%ebp)
  2913. end ['EAX','EBX'];
  2914. end;
  2915. Procedure ReadPort (Port : Longint; Var Value : Longint);
  2916. {
  2917. Reads 'Value' from port 'Port'
  2918. }
  2919. begin
  2920. asm
  2921. movl 8(%ebp),%edx
  2922. inl %dx,%eax
  2923. movl %eax,12(%ebp)
  2924. end ['EAX','EBX'];
  2925. end;
  2926. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  2927. {
  2928. Reads 'Count' longints from port 'Port' to 'Buf'.
  2929. }
  2930. begin
  2931. asm
  2932. movl 16(%ebp),%ecx
  2933. movl 12(%ebp),%edi
  2934. movl 8(%ebp),%edx
  2935. cld
  2936. rep
  2937. insl
  2938. end ['ECX','ESI','EDX'];
  2939. end;
  2940. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  2941. {
  2942. Reads 'Count' words from port 'Port' to 'Buf'.
  2943. }
  2944. begin
  2945. asm
  2946. movl 16(%ebp),%ecx
  2947. movl 12(%ebp),%edi
  2948. movl 8(%ebp),%edx
  2949. cld
  2950. rep
  2951. insw
  2952. end ['ECX','ESI','EDX'];
  2953. end;
  2954. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  2955. {
  2956. Reads 'Count' bytes from port 'Port' to 'Buf'.
  2957. }
  2958. begin
  2959. asm
  2960. movl 16(%ebp),%ecx
  2961. movl 12(%ebp),%edi
  2962. movl 8(%ebp),%edx
  2963. cld
  2964. rep
  2965. insb
  2966. end ['ECX','ESI','EDX'];
  2967. end;
  2968. {$ENDIF}
  2969. Begin
  2970. InitEpochToLocal;
  2971. End.
  2972. {
  2973. $Log$
  2974. Revision 1.21 1998-10-15 08:31:11 peter
  2975. * type aliases using delphi typenaming
  2976. Revision 1.20 1998/10/11 12:23:11 michael
  2977. + Implemented Rename
  2978. Revision 1.19 1998/09/18 09:56:33 peter
  2979. * merged
  2980. Revision 1.18.2.1 1998/09/18 09:53:46 peter
  2981. * fixed winsize record
  2982. Revision 1.18 1998/09/08 13:01:51 michael
  2983. + Signal call now correctly implemented
  2984. Revision 1.17 1998/08/19 00:50:31 peter
  2985. * 'i<>0 and ' needs brackets
  2986. Revision 1.16 1998/08/16 10:23:28 michael
  2987. fixed typos
  2988. Revision 1.15 1998/08/16 09:12:14 michael
  2989. Corrected fexpand behaviour.
  2990. Revision 1.14 1998/08/14 12:01:04 carl
  2991. * ifdef i386 for ports access
  2992. Revision 1.13 1998/08/12 11:10:25 michael
  2993. Added settimeofday function
  2994. Revision 1.12 1998/07/28 09:27:06 michael
  2995. restored previous version. A bug in the compiler prevents compilation.
  2996. Revision 1.10 1998/06/16 08:21:58 michael
  2997. * PClose didn't flush textfiles before closing. Now it does
  2998. Revision 1.9 1998/06/03 11:55:33 michael
  2999. + Added IO port calls
  3000. Revision 1.8 1998/05/06 18:45:32 peter
  3001. * fixed the shell() bug (the correct code was also in Popen) moved the
  3002. argv generation to CreateShellArgv
  3003. + Execve with pchar instead of string
  3004. Revision 1.7 1998/05/06 12:35:26 michael
  3005. + Removed log from before restored version.
  3006. Revision 1.6 1998/04/15 11:23:53 michael
  3007. + Added some calls to make common API more efficient
  3008. Revision 1.5 1998/04/10 15:23:03 michael
  3009. + Pclose now returns exit status of process
  3010. Revision 1.4 1998/04/07 13:08:29 michael
  3011. + Added flock for file locking
  3012. Revision 1.3 1998/04/07 12:27:41 peter
  3013. * fixed fexpand('..')
  3014. Revision 1.2 1998/04/04 17:07:17 michael
  3015. + Fixed AssignStream, it completely refused to work
  3016. }