linux.pp 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601
  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 FReName (OldName,NewName : Pchar) : Boolean;
  462. Function FReName (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 FRename (OldName,NewName : Pchar) : Boolean;
  1387. begin
  1388. FRename:=Sys_rename(OldName,NewName)=0;
  1389. LinuxError:=Errno;
  1390. end;
  1391. Function FRename (OldName,NewName : String) : Boolean;
  1392. begin
  1393. OldName:=OldName+#0;
  1394. NewName:=NewName+#0;
  1395. FRename:=FRename (@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 : begin
  1616. { first check if we need something to write, else we may
  1617. get a SigPipe when Close() is called (PFV) }
  1618. if textrec(f).bufpos>0 then
  1619. Sys_write(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  1620. end;
  1621. fminput : textrec(f).bufend:=Sys_read(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  1622. end;
  1623. textrec(f).bufpos:=0;
  1624. end;
  1625. Procedure FlushPipe(var F:Text);
  1626. begin
  1627. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  1628. IOPipe(f);
  1629. textrec(f).bufpos:=0;
  1630. end;
  1631. Procedure ClosePipe(var F:text);
  1632. begin
  1633. textrec(f).mode:=fmclosed;
  1634. Sys_close(textrec(f).handle);
  1635. end;
  1636. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  1637. {
  1638. Sets up a pair of file variables, which act as a pipe. The first one can
  1639. be read from, the second one can be written to.
  1640. If the operation was unsuccesful, linuxerror is set.
  1641. }
  1642. var
  1643. pip : tpipe;
  1644. regs : SysCallregs;
  1645. begin
  1646. regs.reg2:=longint(@pip);
  1647. SysCall(SysCall_nr_pipe,regs);
  1648. pipe_in:=pip[1];
  1649. pipe_out:=pip[2];
  1650. linuxerror:=errno;
  1651. AssignPipe:=(LinuxError=0);
  1652. end;
  1653. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  1654. {
  1655. Sets up a pair of file variables, which act as a pipe. The first one can
  1656. be read from, the second one can be written to.
  1657. If the operation was unsuccesful, linuxerror is set.
  1658. }
  1659. var
  1660. f_in,f_out : longint;
  1661. begin
  1662. if not AssignPipe(f_in,f_out) then
  1663. begin
  1664. AssignPipe:=false;
  1665. exit;
  1666. end;
  1667. { Set up input }
  1668. Assign(Pipe_in,'');
  1669. Textrec(Pipe_in).Handle:=f_in;
  1670. Textrec(Pipe_in).Mode:=fmInput;
  1671. Textrec(Pipe_in).userdata[1]:=P_IN;
  1672. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  1673. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  1674. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  1675. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  1676. { Set up output }
  1677. Assign(Pipe_out,'');
  1678. Textrec(Pipe_out).Handle:=f_out;
  1679. Textrec(Pipe_out).Mode:=fmOutput;
  1680. Textrec(Pipe_out).userdata[1]:=P_OUT;
  1681. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  1682. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  1683. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  1684. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  1685. AssignPipe:=true;
  1686. end;
  1687. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  1688. {
  1689. Sets up a pair of file variables, which act as a pipe. The first one can
  1690. be read from, the second one can be written to.
  1691. If the operation was unsuccesful, linuxerror is set.
  1692. }
  1693. var
  1694. f_in,f_out : longint;
  1695. begin
  1696. if not AssignPipe(f_in,f_out) then
  1697. begin
  1698. AssignPipe:=false;
  1699. exit;
  1700. end;
  1701. { Set up input }
  1702. Assign(Pipe_in,'');
  1703. Filerec(Pipe_in).Handle:=f_in;
  1704. Filerec(Pipe_in).Mode:=fmInput;
  1705. Filerec(Pipe_in).recsize:=1;
  1706. Filerec(Pipe_in).userdata[1]:=P_IN;
  1707. { Set up output }
  1708. Assign(Pipe_out,'');
  1709. Filerec(Pipe_out).Handle:=f_out;
  1710. Filerec(Pipe_out).Mode:=fmoutput;
  1711. Filerec(Pipe_out).recsize:=1;
  1712. Filerec(Pipe_out).userdata[1]:=P_OUT;
  1713. AssignPipe:=true;
  1714. end;
  1715. Function PClose(Var F:text) :longint;
  1716. var
  1717. sr : syscallregs;
  1718. pl : ^longint;
  1719. res : longint;
  1720. begin
  1721. sr.reg2:=Textrec(F).Handle;
  1722. SysCall (syscall_nr_close,sr);
  1723. { closed our side, Now wait for the other - this appears to be needed ?? }
  1724. pl:=@(textrec(f).userdata[2]);
  1725. waitpid(pl^,@res,0);
  1726. pclose:=res shr 8;
  1727. end;
  1728. Function PClose(Var F:file) : longint;
  1729. var
  1730. sr : syscallregs;
  1731. pl : ^longint;
  1732. res : longint;
  1733. begin
  1734. sr.reg2:=FileRec(F).Handle;
  1735. SysCall (Syscall_nr_close,sr);
  1736. { closed our side, Now wait for the other - this appears to be needed ?? }
  1737. pl:=@(filerec(f).userdata[2]);
  1738. waitpid(pl^,@res,0);
  1739. pclose:=res shr 8;
  1740. end;
  1741. Procedure PCloseText(Var F:text);
  1742. {
  1743. May not use @PClose due overloading
  1744. }
  1745. begin
  1746. PClose(f);
  1747. end;
  1748. Procedure POpen(var F:text;const Prog:String;rw:char);
  1749. {
  1750. Starts the program in 'Prog' and makes it's input or out put the
  1751. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  1752. F, will be read from stdin by the program in 'Prog'. The inverse is true
  1753. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  1754. read from 'f'.
  1755. }
  1756. var
  1757. pipi,
  1758. pipo : text;
  1759. pid : longint;
  1760. pl : ^longint;
  1761. pp : ppchar;
  1762. begin
  1763. LinuxError:=0;
  1764. rw:=upcase(rw);
  1765. if not (rw in ['R','W']) then
  1766. begin
  1767. LinuxError:=Sys_enoent;
  1768. exit;
  1769. end;
  1770. AssignPipe(pipi,pipo);
  1771. if Linuxerror<>0 then
  1772. exit;
  1773. pid:=fork;
  1774. if linuxerror<>0 then
  1775. begin
  1776. close(pipi);
  1777. close(pipo);
  1778. exit;
  1779. end;
  1780. if pid=0 then
  1781. begin
  1782. { We're in the child }
  1783. if rw='W' then
  1784. begin
  1785. close(pipo);
  1786. dup2(pipi,input);
  1787. close(pipi);
  1788. if linuxerror<>0 then
  1789. halt(127);
  1790. end
  1791. else
  1792. begin
  1793. close(pipi);
  1794. dup2(pipo,output);
  1795. close(pipo);
  1796. if linuxerror<>0 then
  1797. halt(127);
  1798. end;
  1799. pp:=createshellargv(prog);
  1800. Execve(pp^,pp,envp);
  1801. halt(127);
  1802. end
  1803. else
  1804. begin
  1805. { We're in the parent }
  1806. if rw='W' then
  1807. begin
  1808. close(pipi);
  1809. f:=pipo;
  1810. textrec(f).bufptr:=@textrec(f).buffer;
  1811. end
  1812. else
  1813. begin
  1814. close(pipo);
  1815. f:=pipi;
  1816. textrec(f).bufptr:=@textrec(f).buffer;
  1817. end;
  1818. {Save the process ID - needed when closing }
  1819. pl:=@(textrec(f).userdata[2]);
  1820. pl^:=pid;
  1821. textrec(f).closefunc:=@PCloseText;
  1822. end;
  1823. end;
  1824. Procedure POpen(var F:file;const Prog:String;rw:char);
  1825. {
  1826. Starts the program in 'Prog' and makes it's input or out put the
  1827. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  1828. F, will be read from stdin by the program in 'Prog'. The inverse is true
  1829. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  1830. read from 'f'.
  1831. }
  1832. var
  1833. pipi,
  1834. pipo : file;
  1835. pid : longint;
  1836. pl : ^longint;
  1837. p,pp : ppchar;
  1838. temp : string[255];
  1839. begin
  1840. LinuxError:=0;
  1841. rw:=upcase(rw);
  1842. if not (rw in ['R','W']) then
  1843. begin
  1844. LinuxError:=Sys_enoent;
  1845. exit;
  1846. end;
  1847. AssignPipe(pipi,pipo);
  1848. if Linuxerror<>0 then
  1849. exit;
  1850. pid:=fork;
  1851. if linuxerror<>0 then
  1852. begin
  1853. close(pipi);
  1854. close(pipo);
  1855. exit;
  1856. end;
  1857. if pid=0 then
  1858. begin
  1859. { We're in the child }
  1860. if rw='W' then
  1861. begin
  1862. close(pipo);
  1863. dup2(filerec(pipi).handle,stdinputhandle);
  1864. close(pipi);
  1865. if linuxerror<>0 then
  1866. halt(127);
  1867. end
  1868. else
  1869. begin
  1870. close(pipi);
  1871. dup2(filerec(pipo).handle,stdoutputhandle);
  1872. close(pipo);
  1873. if linuxerror<>0 then
  1874. halt(127);
  1875. end;
  1876. getmem(pp,sizeof(pchar)*4);
  1877. temp:='/bin/sh'#0'-c'#0+prog+#0;
  1878. pp^:=@temp[1];
  1879. p:=pp+sizeof(pchar);
  1880. p^:=@temp[9];
  1881. p:=p+sizeof(pchar);
  1882. p^:=@temp[12];
  1883. p:=p+sizeof(pchar);
  1884. p^:=Nil;
  1885. Execve('/bin/sh',pp,envp);
  1886. halt(127);
  1887. end
  1888. else
  1889. begin
  1890. { We're in the parent }
  1891. if rw='W' then
  1892. begin
  1893. close(pipi);
  1894. f:=pipo;
  1895. end
  1896. else
  1897. begin
  1898. close(pipo);
  1899. f:=pipi;
  1900. end;
  1901. {Save the process ID - needed when closing }
  1902. pl:=@(filerec(f).userdata[2]);
  1903. pl^:=pid;
  1904. end;
  1905. end;
  1906. Function mkFifo(pathname:string;mode:longint):boolean;
  1907. var
  1908. regs : SysCallRegs;
  1909. begin
  1910. pathname:=pathname+#0;
  1911. regs.reg2:=longint(@pathname[1]);
  1912. regs.reg3:=mode or STAT_IFIFO;
  1913. regs.reg4:=0;
  1914. mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
  1915. end;
  1916. Procedure AssignStream(Var StreamIn,Streamout:text;Const Prog:String);
  1917. {
  1918. Starts the program in 'Prog' and makes its input and output the
  1919. other end of two pipes, which are the stdin and stdout of a program
  1920. specified in 'Prog'.
  1921. streamout can be used to write to the program, streamin can be used to read
  1922. the output of the program. See the following diagram :
  1923. Parent Child
  1924. STreamout --> Input
  1925. Streamin <-- Output
  1926. }
  1927. var
  1928. pipi,
  1929. pipo : text;
  1930. pid : longint;
  1931. pl : ^Longint;
  1932. begin
  1933. LinuxError:=0;
  1934. AssignPipe(streamin,pipo);
  1935. if Linuxerror<>0 then
  1936. exit;
  1937. AssignPipe(pipi,streamout);
  1938. if Linuxerror<>0 then
  1939. exit;
  1940. pid:=fork;
  1941. if linuxerror<>0 then
  1942. begin
  1943. close(pipi);
  1944. close(pipo);
  1945. close (streamin);
  1946. close (streamout);
  1947. exit;
  1948. end;
  1949. if pid=0 then
  1950. begin
  1951. { We're in the child }
  1952. { Close what we don't need }
  1953. close(streamout);
  1954. close(streamin);
  1955. dup2(pipi,input);
  1956. if linuxerror<>0 then
  1957. halt(127);
  1958. close(pipi);
  1959. dup2(pipo,output);
  1960. if linuxerror<>0 then
  1961. halt (127);
  1962. close(pipo);
  1963. Execl(Prog);
  1964. halt(127);
  1965. end
  1966. else
  1967. begin
  1968. { we're in the parent}
  1969. close(pipo);
  1970. close(pipi);
  1971. {Save the process ID - needed when closing }
  1972. pl:=@(textrec(StreamIn).userdata[2]);
  1973. pl^:=pid;
  1974. textrec(StreamIn).closefunc:=@PCloseText;
  1975. {Save the process ID - needed when closing }
  1976. pl:=@(textrec(StreamOut).userdata[2]);
  1977. pl^:=pid;
  1978. textrec(StreamOut).closefunc:=@PCloseText;
  1979. end;
  1980. end;
  1981. {******************************************************************************
  1982. General information calls
  1983. ******************************************************************************}
  1984. Function Sysinfo(var Info:TSysinfo):Boolean;
  1985. {
  1986. Get system info
  1987. }
  1988. var
  1989. regs : SysCallregs;
  1990. Begin
  1991. regs.reg2:=longint(@info);
  1992. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
  1993. End;
  1994. Function Uname(var unamerec:utsname):Boolean;
  1995. {
  1996. Get machine's names
  1997. }
  1998. var
  1999. regs : SysCallregs;
  2000. Begin
  2001. regs.reg2:=longint(@unamerec);
  2002. Uname:=SysCall(SysCall_nr_uname,regs)=0;
  2003. LinuxError:=Errno;
  2004. End;
  2005. Function GetEnv(P:string):Pchar;
  2006. {
  2007. Searches the environment for a string with name p and
  2008. returns a pchar to it's value.
  2009. A pchar is used to accomodate for strings of length > 255
  2010. }
  2011. var
  2012. ep : ppchar;
  2013. found : boolean;
  2014. Begin
  2015. p:=p+'='; {Else HOST will also find HOSTNAME, etc}
  2016. ep:=envp;
  2017. found:=false;
  2018. if ep<>nil then
  2019. begin
  2020. while (not found) and (ep^<>nil) do
  2021. begin
  2022. if strlcomp(@p[1],(ep^),length(p))=0 then
  2023. found:=true
  2024. else
  2025. ep:=ep+4;
  2026. end;
  2027. end;
  2028. if found then
  2029. getenv:=ep^+length(p)
  2030. else
  2031. getenv:=nil;
  2032. end;
  2033. Function GetDomainName:String;
  2034. {
  2035. Get machines domain name. Returns empty string if not set.
  2036. }
  2037. Var
  2038. Sysn : utsname;
  2039. begin
  2040. Uname(Sysn);
  2041. linuxerror:=errno;
  2042. If linuxerror<>0 then
  2043. getdomainname:=''
  2044. else
  2045. getdomainname:=strpas(@Sysn.domainname[0]);
  2046. end;
  2047. Function GetHostName:String;
  2048. {
  2049. Get machines name. Returns empty string if not set.
  2050. }
  2051. Var
  2052. Sysn : utsname;
  2053. begin
  2054. uname(Sysn);
  2055. linuxerror:=errno;
  2056. If linuxerror<>0 then
  2057. gethostname:=''
  2058. else
  2059. gethostname:=strpas(@Sysn.nodename[0]);
  2060. end;
  2061. {******************************************************************************
  2062. Signal handling calls
  2063. ******************************************************************************}
  2064. Function Kill(Pid:longint;Sig:integer):integer;
  2065. {
  2066. Send signal 'sig' to a process, or a group of processes.
  2067. If Pid > 0 then the signal is sent to pid
  2068. pid=-1 to all processes except process 1
  2069. pid < -1 to process group -pid
  2070. Return value is zero, except for case three, where the return value
  2071. is the number of processes to which the signal was sent.
  2072. }
  2073. var
  2074. regs : Syscallregs;
  2075. begin
  2076. regs.reg2:=Pid;
  2077. regs.reg3:=Sig;
  2078. kill:=SysCall(Syscall_nr_kill,regs);
  2079. if kill<0 then
  2080. Kill:=0;
  2081. linuxerror:=errno;
  2082. end;
  2083. Procedure SigAction(Signum:Integer;Var Act,OldAct:PSigActionRec );
  2084. {
  2085. Change action of process upon receipt of a signal.
  2086. Signum specifies the signal (all except SigKill and SigStop).
  2087. If Act is non-nil, it is used to specify the new action.
  2088. If OldAct is non-nil the previous action is saved there.
  2089. }
  2090. Var
  2091. sr : Syscallregs;
  2092. begin
  2093. sr.reg2:=Signum;
  2094. sr.reg3:=Longint(act);
  2095. sr.reg4:=Longint(oldact);
  2096. SysCall(Syscall_nr_sigaction,sr);
  2097. linuxerror:=errno;
  2098. end;
  2099. Procedure SigProcMask(How:Integer;SSet,OldSSet:PSigSet);
  2100. {
  2101. Change the list of currently blocked signals.
  2102. How determines which signals will be blocked :
  2103. SigBlock : Add SSet to the current list of blocked signals
  2104. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  2105. SigSetMask : Set the list of blocked signals to SSet
  2106. if OldSSet is non-null, the old set will be saved there.
  2107. }
  2108. Var
  2109. sr : SyscallRegs;
  2110. begin
  2111. sr.reg2:=how;
  2112. sr.reg3:=longint(SSet);
  2113. sr.reg4:=longint(OldSSet);
  2114. SysCall(Syscall_nr_sigprocmask,sr);
  2115. linuxerror:=errno;
  2116. end;
  2117. Function SigPending:SigSet;
  2118. {
  2119. Allows examination of pending signals. The signal mask of pending
  2120. signals is set in SSet
  2121. }
  2122. Var
  2123. sr : SyscallRegs;
  2124. dummy : Sigset;
  2125. begin
  2126. sr.reg2:=longint(@dummy);
  2127. SysCall(Syscall_nr_sigpending,sr);
  2128. linuxerror:=errno;
  2129. Sigpending:=dummy;
  2130. end;
  2131. Procedure SigSuspend(Mask:Sigset);
  2132. {
  2133. Set the signal mask with Mask, and suspend the program until a signal
  2134. is received.
  2135. }
  2136. Var
  2137. sr : SyscallRegs;
  2138. begin
  2139. sr.reg2:=mask;
  2140. SysCall(Syscall_nr_sigsuspend,sr);
  2141. linuxerror:=errno;
  2142. end;
  2143. Function Signal(Signum:Integer;Handler:SignalHandler):SignalHandler;
  2144. {
  2145. Install a new handler for signal Signum.
  2146. The old signal handler is returned.
  2147. This call does, in fact, the same as SigAction.
  2148. }
  2149. var
  2150. sr : Syscallregs;
  2151. begin
  2152. sr.reg2:=signum;
  2153. sr.reg3:=longint(handler);
  2154. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  2155. If linuxerror=Sig_Err then
  2156. begin
  2157. Signal:=nil;
  2158. Linuxerror:=errno;
  2159. end
  2160. else
  2161. begin
  2162. Signal:=signalhandler(Linuxerror);
  2163. linuxerror:=0;
  2164. end;
  2165. end;
  2166. {******************************************************************************
  2167. IOCtl and Termios calls
  2168. ******************************************************************************}
  2169. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  2170. {
  2171. Interface to Unix ioctl call.
  2172. Performs various operations on the filedescriptor Handle.
  2173. Ndx describes the operation to perform.
  2174. Data points to data needed for the Ndx function. The structure of this
  2175. data is function-dependent.
  2176. }
  2177. var
  2178. sr: SysCallRegs;
  2179. begin
  2180. sr.reg2:=Handle;
  2181. sr.reg3:=Ndx;
  2182. sr.reg4:=Longint(Data);
  2183. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  2184. LinuxError:=Errno;
  2185. end;
  2186. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  2187. begin
  2188. TCGetAttr:=IOCtl(fd,TCGETS,@tios);
  2189. end;
  2190. Function TCSetAttr(fd:longint;OptAct:longint;var tios:TermIOS):boolean;
  2191. var
  2192. nr:longint;
  2193. begin
  2194. case OptAct of
  2195. TCSANOW : nr:=TCSETS;
  2196. TCSADRAIN : nr:=TCSETSW;
  2197. TCSAFLUSH : nr:=TCSETSF;
  2198. else
  2199. begin
  2200. ErrNo:=Sys_EINVAL;
  2201. TCSetAttr:=false;
  2202. exit;
  2203. end;
  2204. end;
  2205. TCSetAttr:=IOCtl(fd,nr,@Tios);
  2206. end;
  2207. Procedure CFSetISpeed(var tios:TermIOS;speed:Longint);
  2208. begin
  2209. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  2210. end;
  2211. Procedure CFSetOSpeed(var tios:TermIOS;speed:Longint);
  2212. begin
  2213. CFSetISpeed(tios,speed);
  2214. end;
  2215. Procedure CFMakeRaw(var tios:TermIOS);
  2216. begin
  2217. with tios do
  2218. begin
  2219. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  2220. INLCR or IGNCR or ICRNL or IXON));
  2221. c_oflag:=c_oflag and (not OPOST);
  2222. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  2223. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  2224. end;
  2225. end;
  2226. Function TCSendBreak(fd,duration:longint):boolean;
  2227. begin
  2228. TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
  2229. end;
  2230. Function TCSetPGrp(fd,id:longint):boolean;
  2231. begin
  2232. TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
  2233. end;
  2234. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  2235. begin
  2236. TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
  2237. end;
  2238. Function TCDrain(fd:longint):boolean;
  2239. begin
  2240. TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
  2241. end;
  2242. Function TCFlow(fd,act:longint):boolean;
  2243. begin
  2244. TCFlow:=IOCtl(fd,TCXONC,pointer(act));
  2245. end;
  2246. Function TCFlush(fd,qsel:longint):boolean;
  2247. begin
  2248. TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
  2249. end;
  2250. Function IsATTY(Handle:Longint):Boolean;
  2251. {
  2252. Check if the filehandle described by 'handle' is a TTY (Terminal)
  2253. }
  2254. var
  2255. t : Termios;
  2256. begin
  2257. IsAtty:=TCGetAttr(Handle,t);
  2258. end;
  2259. Function IsATTY(f: text):Boolean;
  2260. {
  2261. Idem as previous, only now for text variables.
  2262. }
  2263. begin
  2264. IsATTY:=IsaTTY(textrec(f).handle);
  2265. end;
  2266. function TTYName(Handle:Longint):string;
  2267. {
  2268. Return the name of the current tty described by handle f.
  2269. returns empty string in case of an error.
  2270. }
  2271. Const
  2272. dev='/dev';
  2273. var
  2274. name : string;
  2275. st : stat;
  2276. mydev,
  2277. myino : longint;
  2278. dirstream : pdir;
  2279. d : pdirent;
  2280. begin
  2281. TTYName:='';
  2282. fstat(handle,st);
  2283. if (errno<>0) and isatty (handle) then
  2284. exit;
  2285. mydev:=st.dev;
  2286. myino:=st.ino;
  2287. dirstream:=opendir(dev);
  2288. if (linuxerror<>0) then
  2289. exit;
  2290. d:=Readdir(dirstream);
  2291. while (d<>nil) do
  2292. begin
  2293. if (d^.ino=myino) then
  2294. begin
  2295. name:=dev+'/'+strpas(@(d^.name));
  2296. fstat(name,st);
  2297. if (linuxerror=0) and (st.dev=mydev) then
  2298. begin
  2299. closedir(dirstream);
  2300. ttyname:=name;
  2301. exit;
  2302. end;
  2303. end;
  2304. d:=Readdir(dirstream);
  2305. end;
  2306. closedir(dirstream);
  2307. end;
  2308. function TTYName(var F:Text):string;
  2309. {
  2310. Idem as previous, only now for text variables;
  2311. }
  2312. begin
  2313. TTYName:=TTYName(textrec(f).handle);
  2314. end;
  2315. {******************************************************************************
  2316. Utility calls
  2317. ******************************************************************************}
  2318. Function Octal(l:longint):longint;
  2319. {
  2320. Convert an octal specified number to decimal;
  2321. }
  2322. var
  2323. octnr,
  2324. oct : longint;
  2325. begin
  2326. octnr:=0;
  2327. oct:=0;
  2328. while (l>0) do
  2329. begin
  2330. oct:=oct or ((l mod 10) shl octnr);
  2331. l:=l div 10;
  2332. inc(octnr,3);
  2333. end;
  2334. Octal:=oct;
  2335. end;
  2336. Function StringToPPChar(Var S:STring):ppchar;
  2337. {
  2338. Create a PPChar to structure of pchars which are the arguments specified
  2339. in the string S. Especially usefull for creating an ArgV for Exec-calls
  2340. }
  2341. var
  2342. nr : longint;
  2343. Buf : ^char;
  2344. p : ppchar;
  2345. begin
  2346. s:=s+#0;
  2347. buf:=@s[1];
  2348. nr:=0;
  2349. while(buf^<>#0) do
  2350. begin
  2351. while (buf^ in [' ',#8,#10]) do
  2352. buf:=buf+1;
  2353. inc(nr);
  2354. while not (buf^ in [' ',#0,#8,#10]) do
  2355. buf:=buf+1;
  2356. end;
  2357. getmem(p,nr*4);
  2358. StringToPPChar:=p;
  2359. if p=nil then
  2360. begin
  2361. LinuxError:=sys_enomem;
  2362. exit;
  2363. end;
  2364. buf:=@s[1];
  2365. while (buf^<>#0) do
  2366. begin
  2367. while (buf^ in [' ',#8,#10]) do
  2368. begin
  2369. buf^:=#0;
  2370. buf:=buf+1;
  2371. end;
  2372. p^:=buf;
  2373. p:=p+4;
  2374. p^:=nil;
  2375. while not (buf^ in [' ',#0,#8,#10]) do
  2376. buf:=buf+1;
  2377. end;
  2378. end;
  2379. Function FExpand(Const Path:PathStr):PathStr;
  2380. var
  2381. temp : pathstr;
  2382. i,j : longint;
  2383. p : pchar;
  2384. Begin
  2385. {Remove eventual drive - doesn't exist in Linux}
  2386. if path[2]=':' then
  2387. i:=3
  2388. else
  2389. i:=1;
  2390. temp:='';
  2391. {Replace ~/ with $HOME}
  2392. if (path[i]='~') and ((i+1>length(path)) or (path[i+1]='/')) then
  2393. begin
  2394. p:=getenv('HOME');
  2395. if not (p=nil) then
  2396. Insert(StrPas(p),temp,i);
  2397. i:=1;
  2398. temp:=temp+Copy(Path,2,255);
  2399. end;
  2400. {Do we have an absolute path ? No - prefix the current dir}
  2401. if temp='' then
  2402. begin
  2403. if path[i]<>'/' then
  2404. getdir(0,temp)
  2405. else
  2406. inc(i);
  2407. temp:=temp+'/'+copy(path,i,length(path)-i+1)+'/';
  2408. end;
  2409. {First remove all references to '/./'}
  2410. while pos('/./',temp)<>0 do
  2411. delete(temp,pos('/./',temp),2);
  2412. {Now remove also all references to '/../' + of course previous dirs..}
  2413. repeat
  2414. i:=pos('/../',temp);
  2415. {Find the pos of the previous dir}
  2416. if i>1 then
  2417. begin
  2418. j:=i-1;
  2419. while (j>1) and (temp[j]<>'/') do
  2420. dec (j);{temp[1] is always '/'}
  2421. delete(temp,j,i-j+3);
  2422. end
  2423. else
  2424. if i=1 then {i=1, so we have temp='/../something', just delete '/../'}
  2425. delete(temp,1,3);
  2426. until i=0;
  2427. { Remove ending /.. }
  2428. i:=pos('/..',temp);
  2429. if (i<>0) and (i =length(temp)-2) then
  2430. begin
  2431. j:=i-1;
  2432. while (j>1) and (temp[j]<>'/') do
  2433. dec (j);
  2434. delete (temp,j,i-j+3);
  2435. end;
  2436. { if last character is / then remove it - dir is also a file :-) }
  2437. if (length(temp)>0) and (temp[length(temp)]='/') then
  2438. dec(byte(temp[0]));
  2439. fexpand:=temp;
  2440. End;
  2441. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  2442. {
  2443. Searches for a file 'path' in the list of direcories in 'dirlist'.
  2444. returns an empty string if not found. Wildcards are NOT allowed.
  2445. If dirlist is empty, it is set to '.'
  2446. }
  2447. Var
  2448. NewDir : PathStr;
  2449. p1 : Longint;
  2450. Info : Stat;
  2451. Begin
  2452. {Replace ':' with ';'}
  2453. for p1:=1to length(dirlist) do
  2454. if dirlist[p1]=':' then
  2455. dirlist[p1]:=';';
  2456. {Check for WildCards}
  2457. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  2458. FSearch:='' {No wildcards allowed in these things.}
  2459. Else
  2460. Begin
  2461. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  2462. Repeat
  2463. p1:=Pos(';',DirList);
  2464. If p1=0 Then
  2465. p1:=255;
  2466. NewDir:=Copy(DirList,1,P1 - 1);
  2467. if NewDir[Length(NewDir)]<>'/' then
  2468. NewDir:=NewDir+'/';
  2469. NewDir:=NewDir+Path;
  2470. Delete(DirList,1,p1);
  2471. if FStat(NewDir,Info) then
  2472. Begin
  2473. If Pos('./',NewDir)=1 Then
  2474. Delete(NewDir,1,2);
  2475. {DOS strips off an initial .\}
  2476. End
  2477. Else
  2478. NewDir:='';
  2479. Until (DirList='') or (Length(NewDir) > 0);
  2480. FSearch:=NewDir;
  2481. End;
  2482. End;
  2483. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  2484. Var
  2485. DotPos,SlashPos,i : longint;
  2486. Begin
  2487. SlashPos:=0;
  2488. DotPos:=256;
  2489. i:=Length(Path);
  2490. While (i>0) and (SlashPos=0) Do
  2491. Begin
  2492. If (DotPos=256) and (Path[i]='.') Then
  2493. DotPos:=i;
  2494. If (Path[i]='/') Then
  2495. SlashPos:=i;
  2496. Dec(i);
  2497. End;
  2498. Ext:=Copy(Path,DotPos,255);
  2499. Dir:=Copy(Path,1,SlashPos);
  2500. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  2501. End;
  2502. Function Dirname(Const path:pathstr):pathstr;
  2503. {
  2504. This function returns the directory part of a complete path.
  2505. Unless the directory is root '/', The last character is not
  2506. a slash.
  2507. }
  2508. var
  2509. Dir : PathStr;
  2510. Name : NameStr;
  2511. Ext : ExtStr;
  2512. begin
  2513. FSplit(Path,Dir,Name,Ext);
  2514. if length(Dir)>1 then
  2515. Delete(Dir,length(Dir),1);
  2516. DirName:=Dir;
  2517. end;
  2518. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  2519. {
  2520. This function returns the filename part of a complete path. If suf is
  2521. supplied, it is cut off the filename.
  2522. }
  2523. var
  2524. Dir : PathStr;
  2525. Name : NameStr;
  2526. Ext : ExtStr;
  2527. begin
  2528. FSplit(Path,Dir,Name,Ext);
  2529. if Suf<>Ext then
  2530. Name:=Name+Ext;
  2531. BaseName:=Name;
  2532. end;
  2533. Function FNMatch(const Pattern,Name:string):Boolean;
  2534. Var
  2535. LenPat,LenName : longint;
  2536. Function DoFNMatch(i,j:longint):Boolean;
  2537. Var
  2538. Found : boolean;
  2539. Begin
  2540. Found:=true;
  2541. While Found and (i<=LenPat) Do
  2542. Begin
  2543. Case Pattern[i] of
  2544. '?' : Found:=(j<=LenName);
  2545. '*' : Begin
  2546. {find the next character in pattern, different of ? and *}
  2547. while Found and (i<LenPat) do
  2548. begin
  2549. inc(i);
  2550. case Pattern[i] of
  2551. '*' : ;
  2552. '?' : begin
  2553. inc(j);
  2554. Found:=(j<=LenName);
  2555. end;
  2556. else
  2557. Found:=false;
  2558. end;
  2559. end;
  2560. {Now, find in name the character which i points to, if the * or ?
  2561. wasn't the last character in the pattern, else, use up all the
  2562. chars in name}
  2563. Found:=true;
  2564. if (i<=LenPat) then
  2565. begin
  2566. repeat
  2567. {find a letter (not only first !) which maches pattern[i]}
  2568. while (j<=LenName) and (name[j]<>pattern[i]) do
  2569. inc (j);
  2570. if (j<LenName) then
  2571. begin
  2572. if DoFnMatch(i+1,j+1) then
  2573. begin
  2574. i:=LenPat;
  2575. j:=LenName;{we can stop}
  2576. Found:=true;
  2577. end
  2578. else
  2579. inc(j);{We didn't find one, need to look further}
  2580. end;
  2581. until (j>=LenName);
  2582. end
  2583. else
  2584. j:=LenName;{we can stop}
  2585. end;
  2586. else {not a wildcard character in pattern}
  2587. Found:=(j<=LenName) and (pattern[i]=name[j]);
  2588. end;
  2589. inc(i);
  2590. inc(j);
  2591. end;
  2592. DoFnMatch:=Found and (j>LenName);
  2593. end;
  2594. Begin {start FNMatch}
  2595. LenPat:=Length(Pattern);
  2596. LenName:=Length(Name);
  2597. FNMatch:=DoFNMatch(1,1);
  2598. End;
  2599. Procedure Globfree(var p : pglob);
  2600. {
  2601. Release memory occupied by pglob structure, and names in it.
  2602. sets p to nil.
  2603. }
  2604. var
  2605. temp : pglob;
  2606. begin
  2607. while p<>nil do
  2608. begin
  2609. temp:=p^.next;
  2610. if p^.name<>nil then
  2611. freemem(p^.name,strlen(p^.name));
  2612. dispose(p);
  2613. p:=temp;
  2614. end;
  2615. end;
  2616. Function Glob(Const path:pathstr):pglob;
  2617. {
  2618. Fills a tglob structure with entries matching path,
  2619. and returns a pointer to it. Returns nil on error,
  2620. linuxerror is set accordingly.
  2621. }
  2622. var
  2623. temp : string[255];
  2624. thedir : pdir;
  2625. buffer : pdirent;
  2626. root,run : pglob;
  2627. begin
  2628. { Get directory }
  2629. if dirname(path)='' then
  2630. temp:='.'
  2631. else
  2632. temp:=dirname(path);
  2633. temp:=temp+#0;
  2634. thedir:=opendir(@temp[1]);
  2635. if thedir=nil then
  2636. begin
  2637. glob:=nil;
  2638. linuxerror:=errno;
  2639. exit;
  2640. end;
  2641. temp:=basename(path,'');{ get the pattern }
  2642. if thedir^.fd<0 then
  2643. begin
  2644. linuxerror:=errno;
  2645. glob:=nil;
  2646. exit;
  2647. end;
  2648. {get the entries}
  2649. new(root);
  2650. root^.next:=nil;
  2651. root^.name:=nil;
  2652. run:=root;
  2653. repeat
  2654. buffer:=Sys_readdir(thedir);
  2655. if buffer<>nil then
  2656. begin
  2657. if fnmatch(temp,strpas(@(buffer^.name[0]))) then
  2658. begin
  2659. { get memory for pglob }
  2660. new(run^.next);
  2661. if run^.next=nil then
  2662. begin
  2663. linuxerror:=Sys_ENOMEM;
  2664. globfree(root);
  2665. glob:=nil;
  2666. exit;
  2667. end
  2668. else
  2669. begin
  2670. run:=run^.next;
  2671. run^.next:=nil;
  2672. end;
  2673. { Get memory for name }
  2674. getmem(run^.name,strlen(@(buffer^.name[0]))+1);
  2675. if run^.name=nil then
  2676. begin
  2677. linuxerror:=Sys_ENOMEM;
  2678. globfree(root);
  2679. glob:=nil;
  2680. exit;
  2681. end;
  2682. move(buffer^.name[0],run^.name^,strlen(@(buffer^.name[0]))+1);
  2683. end;{ if fnmatch }
  2684. end { buffer <> nil }
  2685. else
  2686. begin
  2687. run:=root;
  2688. if root^.next<>nil then
  2689. root:=root^.next;{ put root on first entry}
  2690. if run<>nil then
  2691. begin
  2692. run^.next:=nil;
  2693. globfree(run);
  2694. end;
  2695. end;
  2696. until buffer=nil;
  2697. if root^.name=nil then
  2698. begin
  2699. dispose(root);
  2700. linuxerror:=0;
  2701. glob:=nil;
  2702. end
  2703. else
  2704. glob:=root;
  2705. end;
  2706. {--------------------------------
  2707. FiledescriptorSets
  2708. --------------------------------}
  2709. Procedure FD_Zero(var fds:fdSet);
  2710. {
  2711. Clear the set of filedescriptors
  2712. }
  2713. begin
  2714. FillChar(fds,sizeof(fdSet),0);
  2715. end;
  2716. Procedure FD_Clr(fd:longint;var fds:fdSet);
  2717. {
  2718. Remove fd from the set of filedescriptors
  2719. }
  2720. begin
  2721. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  2722. end;
  2723. Procedure FD_Set(fd:longint;var fds:fdSet);
  2724. {
  2725. Add fd to the set of filedescriptors
  2726. }
  2727. begin
  2728. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  2729. end;
  2730. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  2731. {
  2732. Test if fd is part of the set of filedescriptors
  2733. }
  2734. begin
  2735. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  2736. end;
  2737. Function GetFS (var T:Text):longint;
  2738. {
  2739. Get File Descriptor of a text file.
  2740. }
  2741. begin
  2742. if textrec(t).mode=fmclosed then
  2743. exit(-1)
  2744. else
  2745. GETFS:=textrec(t).Handle
  2746. end;
  2747. Function GetFS(Var F:File):longint;
  2748. {
  2749. Get File Descriptor of an unTyped file.
  2750. }
  2751. begin
  2752. { Handle and mode are on the same place in textrec and filerec. }
  2753. if filerec(f).mode=fmclosed then
  2754. exit(-1)
  2755. else
  2756. GETFS:=filerec(f).Handle
  2757. end;
  2758. {--------------------------------
  2759. Stat.Mode Macro's
  2760. --------------------------------}
  2761. Function S_ISLNK(m:integer):boolean;
  2762. {
  2763. Check mode field of inode for link.
  2764. }
  2765. begin
  2766. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  2767. end;
  2768. Function S_ISREG(m:integer):boolean;
  2769. {
  2770. Check mode field of inode for regular file.
  2771. }
  2772. begin
  2773. S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
  2774. end;
  2775. Function S_ISDIR(m:integer):boolean;
  2776. {
  2777. Check mode field of inode for directory.
  2778. }
  2779. begin
  2780. S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
  2781. end;
  2782. Function S_ISCHR(m:integer):boolean;
  2783. {
  2784. Check mode field of inode for character device.
  2785. }
  2786. begin
  2787. S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
  2788. end;
  2789. Function S_ISBLK(m:integer):boolean;
  2790. {
  2791. Check mode field of inode for block device.
  2792. }
  2793. begin
  2794. S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
  2795. end;
  2796. Function S_ISFIFO(m:integer):boolean;
  2797. {
  2798. Check mode field of inode for named pipe (FIFO).
  2799. }
  2800. begin
  2801. S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
  2802. end;
  2803. Function S_ISSOCK(m:integer):boolean;
  2804. {
  2805. Check mode field of inode for socket.
  2806. }
  2807. begin
  2808. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  2809. end;
  2810. {--------------------------------
  2811. Port IO functions
  2812. --------------------------------}
  2813. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  2814. {
  2815. Set permissions on NUM ports starting with port FROM to VALUE
  2816. this works ONLY as root.
  2817. }
  2818. Var
  2819. Sr : Syscallregs;
  2820. begin
  2821. Sr.Reg2:=From;
  2822. Sr.Reg3:=Num;
  2823. Sr.Reg4:=Value;
  2824. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  2825. LinuxError:=Errno;
  2826. end;
  2827. {$IFDEF I386}
  2828. Procedure WritePort (Port : Longint; Value : Byte);
  2829. {
  2830. Writes 'Value' to port 'Port'
  2831. }
  2832. begin
  2833. asm
  2834. movl 8(%ebp),%edx
  2835. movb 12(%ebp),%al
  2836. outb %al,%dx
  2837. end;
  2838. end;
  2839. Procedure WritePort (Port : Longint; Value : Word);
  2840. {
  2841. Writes 'Value' to port 'Port'
  2842. }
  2843. begin
  2844. asm
  2845. movl 8(%ebp),%edx
  2846. movw 12(%ebp),%ax
  2847. outw %ax,%dx
  2848. end ['EAX','EBX'];
  2849. end;
  2850. Procedure WritePort (Port : Longint; Value : Longint);
  2851. {
  2852. Writes 'Value' to port 'Port'
  2853. }
  2854. begin
  2855. asm
  2856. movl 8(%ebp),%edx
  2857. movl 12(%ebp),%eax
  2858. outl %eax,%dx
  2859. end ['EAX','EBX'];
  2860. end;
  2861. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  2862. {
  2863. Writes 'Count' longints from 'Buf' to Port
  2864. }
  2865. begin
  2866. asm
  2867. movl 16(%ebp),%ecx
  2868. movl 12(%ebp),%esi
  2869. movl 8(%ebp),%edx
  2870. cld
  2871. rep
  2872. outsl
  2873. end ['ECX','ESI','EDX'];
  2874. end;
  2875. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  2876. {
  2877. Writes 'Count' words from 'Buf' to Port
  2878. }
  2879. begin
  2880. asm
  2881. movl 16(%ebp),%ecx
  2882. movl 12(%ebp),%esi
  2883. movl 8(%ebp),%edx
  2884. cld
  2885. rep
  2886. outsw
  2887. end ['ECX','ESI','EDX'];
  2888. end;
  2889. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  2890. {
  2891. Writes 'Count' bytes from 'Buf' to Port
  2892. }
  2893. begin
  2894. asm
  2895. movl 16(%ebp),%ecx
  2896. movl 12(%ebp),%esi
  2897. movl 8(%ebp),%edx
  2898. cld
  2899. rep
  2900. outsb
  2901. end ['ECX','ESI','EDX'];
  2902. end;
  2903. Procedure ReadPort (Port : Longint; Var Value : Byte);
  2904. {
  2905. Reads 'Value' from port 'Port'
  2906. }
  2907. begin
  2908. asm
  2909. movl 8(%ebp),%edx
  2910. inb %dx,%al
  2911. andl $255,%eax
  2912. movl %eax,12(%ebp)
  2913. end ['EAX','EBX'];
  2914. end;
  2915. Procedure ReadPort (Port : Longint; Var Value : Word);
  2916. {
  2917. Reads 'Value' from port 'Port'
  2918. }
  2919. begin
  2920. asm
  2921. movl 8(%ebp),%edx
  2922. inw %dx,%ax
  2923. andl $65535,%eax
  2924. movl %eax,12(%ebp)
  2925. end ['EAX','EBX'];
  2926. end;
  2927. Procedure ReadPort (Port : Longint; Var Value : Longint);
  2928. {
  2929. Reads 'Value' from port 'Port'
  2930. }
  2931. begin
  2932. asm
  2933. movl 8(%ebp),%edx
  2934. inl %dx,%eax
  2935. movl %eax,12(%ebp)
  2936. end ['EAX','EBX'];
  2937. end;
  2938. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  2939. {
  2940. Reads 'Count' longints from port 'Port' to 'Buf'.
  2941. }
  2942. begin
  2943. asm
  2944. movl 16(%ebp),%ecx
  2945. movl 12(%ebp),%edi
  2946. movl 8(%ebp),%edx
  2947. cld
  2948. rep
  2949. insl
  2950. end ['ECX','ESI','EDX'];
  2951. end;
  2952. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  2953. {
  2954. Reads 'Count' words from port 'Port' to 'Buf'.
  2955. }
  2956. begin
  2957. asm
  2958. movl 16(%ebp),%ecx
  2959. movl 12(%ebp),%edi
  2960. movl 8(%ebp),%edx
  2961. cld
  2962. rep
  2963. insw
  2964. end ['ECX','ESI','EDX'];
  2965. end;
  2966. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  2967. {
  2968. Reads 'Count' bytes from port 'Port' to 'Buf'.
  2969. }
  2970. begin
  2971. asm
  2972. movl 16(%ebp),%ecx
  2973. movl 12(%ebp),%edi
  2974. movl 8(%ebp),%edx
  2975. cld
  2976. rep
  2977. insb
  2978. end ['ECX','ESI','EDX'];
  2979. end;
  2980. {$ENDIF}
  2981. Begin
  2982. InitEpochToLocal;
  2983. End.
  2984. {
  2985. $Log$
  2986. Revision 1.27 1998-12-11 18:08:57 peter
  2987. * fixed assignstream
  2988. Revision 1.26 1998/11/24 15:30:12 michael
  2989. * Bugfix in assignstream. . Now wait is performed upon close
  2990. Revision 1.25 1998/11/16 10:21:28 peter
  2991. * fixes for H+
  2992. Revision 1.24 1998/11/10 14:57:53 peter
  2993. * renamed rename -> FRename
  2994. Revision 1.23 1998/10/30 15:47:11 peter
  2995. * fixed glob, which did not reset the root
  2996. Revision 1.22 1998/10/23 00:05:32 peter
  2997. * getenv with envp=nil check
  2998. Revision 1.21 1998/10/15 08:31:11 peter
  2999. * type aliases using delphi typenaming
  3000. Revision 1.20 1998/10/11 12:23:11 michael
  3001. + Implemented Rename
  3002. Revision 1.19 1998/09/18 09:56:33 peter
  3003. * merged
  3004. Revision 1.18.2.1 1998/09/18 09:53:46 peter
  3005. * fixed winsize record
  3006. Revision 1.18 1998/09/08 13:01:51 michael
  3007. + Signal call now correctly implemented
  3008. Revision 1.17 1998/08/19 00:50:31 peter
  3009. * 'i<>0 and ' needs brackets
  3010. Revision 1.16 1998/08/16 10:23:28 michael
  3011. fixed typos
  3012. Revision 1.15 1998/08/16 09:12:14 michael
  3013. Corrected fexpand behaviour.
  3014. Revision 1.14 1998/08/14 12:01:04 carl
  3015. * ifdef i386 for ports access
  3016. Revision 1.13 1998/08/12 11:10:25 michael
  3017. Added settimeofday function
  3018. Revision 1.12 1998/07/28 09:27:06 michael
  3019. restored previous version. A bug in the compiler prevents compilation.
  3020. Revision 1.10 1998/06/16 08:21:58 michael
  3021. * PClose didn't flush textfiles before closing. Now it does
  3022. Revision 1.9 1998/06/03 11:55:33 michael
  3023. + Added IO port calls
  3024. Revision 1.8 1998/05/06 18:45:32 peter
  3025. * fixed the shell() bug (the correct code was also in Popen) moved the
  3026. argv generation to CreateShellArgv
  3027. + Execve with pchar instead of string
  3028. Revision 1.7 1998/05/06 12:35:26 michael
  3029. + Removed log from before restored version.
  3030. Revision 1.6 1998/04/15 11:23:53 michael
  3031. + Added some calls to make common API more efficient
  3032. Revision 1.5 1998/04/10 15:23:03 michael
  3033. + Pclose now returns exit status of process
  3034. Revision 1.4 1998/04/07 13:08:29 michael
  3035. + Added flock for file locking
  3036. Revision 1.3 1998/04/07 12:27:41 peter
  3037. * fixed fexpand('..')
  3038. Revision 1.2 1998/04/04 17:07:17 michael
  3039. + Fixed AssignStream, it completely refused to work
  3040. }