linux.pp 76 KB

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