linux.pp 78 KB

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