linux.pp 77 KB

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