linux.pp 79 KB

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