linux.pp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. BSD parts (c) 2000 by Marco van de Voort
  6. members of the Free Pascal development team.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY;without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. Unit Linux;
  14. Interface
  15. { Get Types and Constants }
  16. {$i sysconst.inc}
  17. {$i systypes.inc}
  18. { Get System call numbers and error-numbers}
  19. {$i sysnr.inc}
  20. {$i errno.inc}
  21. {$I signal.inc}
  22. var
  23. ErrNo,
  24. LinuxError : Longint;
  25. {********************
  26. Process
  27. ********************}
  28. const {Checked for BSD using Linuxthreads port}
  29. { cloning flags }
  30. CSIGNAL = $000000ff; // signal mask to be sent at exit
  31. CLONE_VM = $00000100; // set if VM shared between processes
  32. CLONE_FS = $00000200; // set if fs info shared between processes
  33. CLONE_FILES = $00000400; // set if open files shared between processes
  34. CLONE_SIGHAND = $00000800; // set if signal handlers shared
  35. CLONE_PID = $00001000; // set if pid shared
  36. type
  37. TCloneFunc=function(args:pointer):longint;cdecl;
  38. const
  39. { For getting/setting priority }
  40. Prio_Process = 0;
  41. Prio_PGrp = 1;
  42. Prio_User = 2;
  43. WNOHANG = $1;
  44. WUNTRACED = $2;
  45. __WCLONE = $80000000;
  46. {********************
  47. File
  48. ********************}
  49. Const
  50. P_IN = 1;
  51. P_OUT = 2;
  52. Const
  53. LOCK_SH = 1;
  54. LOCK_EX = 2;
  55. LOCK_UN = 8;
  56. LOCK_NB = 4;
  57. Type
  58. Tpipe = array[1..2] of longint;
  59. pglob = ^tglob;
  60. tglob = record
  61. name : pchar;
  62. next : pglob;
  63. end;
  64. ComStr = String[255];
  65. PathStr = String[255];
  66. DirStr = String[255];
  67. NameStr = String[255];
  68. ExtStr = String[255];
  69. const
  70. { For testing access rights }
  71. R_OK = 4;
  72. W_OK = 2;
  73. X_OK = 1;
  74. F_OK = 0;
  75. { For File control mechanism }
  76. F_GetFd = 1;
  77. F_SetFd = 2;
  78. F_GetFl = 3;
  79. F_SetFl = 4;
  80. F_GetLk = 5;
  81. F_SetLk = 6;
  82. F_SetLkW = 7;
  83. F_GetOwn = 8;
  84. F_SetOwn = 9;
  85. {********************
  86. IOCtl(TermIOS)
  87. ********************}
  88. Const
  89. { Amount of Control Chars }
  90. NCCS = 19;
  91. NCC = 8;
  92. { For Terminal handling }
  93. TCGETS = $5401;
  94. TCSETS = $5402;
  95. TCSETSW = $5403;
  96. TCSETSF = $5404;
  97. TCGETA = $5405;
  98. TCSETA = $5406;
  99. TCSETAW = $5407;
  100. TCSETAF = $5408;
  101. TCSBRK = $5409;
  102. TCXONC = $540A;
  103. TCFLSH = $540B;
  104. TIOCEXCL = $540C;
  105. TIOCNXCL = $540D;
  106. TIOCSCTTY = $540E;
  107. TIOCGPGRP = $540F;
  108. TIOCSPGRP = $5410;
  109. TIOCOUTQ = $5411;
  110. TIOCSTI = $5412;
  111. TIOCGWINSZ = $5413;
  112. TIOCSWINSZ = $5414;
  113. TIOCMGET = $5415;
  114. TIOCMBIS = $5416;
  115. TIOCMBIC = $5417;
  116. TIOCMSET = $5418;
  117. TIOCGSOFTCAR = $5419;
  118. TIOCSSOFTCAR = $541A;
  119. FIONREAD = $541B;
  120. TIOCINQ = FIONREAD;
  121. TIOCLINUX = $541C;
  122. TIOCCONS = $541D;
  123. TIOCGSERIAL = $541E;
  124. TIOCSSERIAL = $541F;
  125. TIOCPKT = $5420;
  126. FIONBIO = $5421;
  127. TIOCNOTTY = $5422;
  128. TIOCSETD = $5423;
  129. TIOCGETD = $5424;
  130. TCSBRKP = $5425;
  131. TIOCTTYGSTRUCT = $5426;
  132. FIONCLEX = $5450;
  133. FIOCLEX = $5451;
  134. FIOASYNC = $5452;
  135. TIOCSERCONFIG = $5453;
  136. TIOCSERGWILD = $5454;
  137. TIOCSERSWILD = $5455;
  138. TIOCGLCKTRMIOS = $5456;
  139. TIOCSLCKTRMIOS = $5457;
  140. TIOCSERGSTRUCT = $5458;
  141. TIOCSERGETLSR = $5459;
  142. TIOCSERGETMULTI = $545A;
  143. TIOCSERSETMULTI = $545B;
  144. TIOCMIWAIT = $545C;
  145. TIOCGICOUNT = $545D;
  146. TIOCPKT_DATA = 0;
  147. TIOCPKT_FLUSHREAD = 1;
  148. TIOCPKT_FLUSHWRITE = 2;
  149. TIOCPKT_STOP = 4;
  150. TIOCPKT_START = 8;
  151. TIOCPKT_NOSTOP = 16;
  152. TIOCPKT_DOSTOP = 32;
  153. Type
  154. winsize = packed record
  155. ws_row,
  156. ws_col,
  157. ws_xpixel,
  158. ws_ypixel : word;
  159. end;
  160. TWinSize=winsize;
  161. Termio = packed record
  162. c_iflag, { input mode flags }
  163. c_oflag, { output mode flags }
  164. c_cflag, { control mode flags }
  165. c_lflag : Word; { local mode flags }
  166. c_line : Word; { line discipline - careful, only High byte in use}
  167. c_cc : array [0..NCC-1] of char;{ control characters }
  168. end;
  169. TTermio=Termio;
  170. Termios = packed record
  171. c_iflag,
  172. c_oflag,
  173. c_cflag,
  174. c_lflag : longint;
  175. c_line : char;
  176. c_cc : array[0..NCCS-1] of byte;
  177. end;
  178. TTermios=Termios;
  179. const
  180. 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);
  181. const
  182. {c_cc characters}
  183. VINTR = 0;
  184. VQUIT = 1;
  185. VERASE = 2;
  186. VKILL = 3;
  187. VEOF = 4;
  188. VTIME = 5;
  189. VMIN = 6;
  190. VSWTC = 7;
  191. VSTART = 8;
  192. VSTOP = 9;
  193. VSUSP = 10;
  194. VEOL = 11;
  195. VREPRINT = 12;
  196. VDISCARD = 13;
  197. VWERASE = 14;
  198. VLNEXT = 15;
  199. VEOL2 = 16;
  200. {c_iflag bits}
  201. IGNBRK = $0000001;
  202. BRKINT = $0000002;
  203. IGNPAR = $0000004;
  204. PARMRK = $0000008;
  205. INPCK = $0000010;
  206. ISTRIP = $0000020;
  207. INLCR = $0000040;
  208. IGNCR = $0000080;
  209. ICRNL = $0000100;
  210. IUCLC = $0000200;
  211. IXON = $0000400;
  212. IXANY = $0000800;
  213. IXOFF = $0001000;
  214. IMAXBEL = $0002000;
  215. {c_oflag bits}
  216. OPOST = $0000001;
  217. OLCUC = $0000002;
  218. ONLCR = $0000004;
  219. OCRNL = $0000008;
  220. ONOCR = $0000010;
  221. ONLRET = $0000020;
  222. OFILL = $0000040;
  223. OFDEL = $0000080;
  224. NLDLY = $0000100;
  225. NL0 = $0000000;
  226. NL1 = $0000100;
  227. CRDLY = $0000600;
  228. CR0 = $0000000;
  229. CR1 = $0000200;
  230. CR2 = $0000400;
  231. CR3 = $0000600;
  232. TABDLY = $0001800;
  233. TAB0 = $0000000;
  234. TAB1 = $0000800;
  235. TAB2 = $0001000;
  236. TAB3 = $0001800;
  237. XTABS = $0001800;
  238. BSDLY = $0002000;
  239. BS0 = $0000000;
  240. BS1 = $0002000;
  241. VTDLY = $0004000;
  242. VT0 = $0000000;
  243. VT1 = $0004000;
  244. FFDLY = $0008000;
  245. FF0 = $0000000;
  246. FF1 = $0008000;
  247. {c_cflag bits}
  248. CBAUD = $000100F;
  249. B0 = $0000000;
  250. B50 = $0000001;
  251. B75 = $0000002;
  252. B110 = $0000003;
  253. B134 = $0000004;
  254. B150 = $0000005;
  255. B200 = $0000006;
  256. B300 = $0000007;
  257. B600 = $0000008;
  258. B1200 = $0000009;
  259. B1800 = $000000A;
  260. B2400 = $000000B;
  261. B4800 = $000000C;
  262. B9600 = $000000D;
  263. B19200 = $000000E;
  264. B38400 = $000000F;
  265. EXTA = B19200;
  266. EXTB = B38400;
  267. CSIZE = $0000030;
  268. CS5 = $0000000;
  269. CS6 = $0000010;
  270. CS7 = $0000020;
  271. CS8 = $0000030;
  272. CSTOPB = $0000040;
  273. CREAD = $0000080;
  274. PARENB = $0000100;
  275. PARODD = $0000200;
  276. HUPCL = $0000400;
  277. CLOCAL = $0000800;
  278. CBAUDEX = $0001000;
  279. B57600 = $0001001;
  280. B115200 = $0001002;
  281. B230400 = $0001003;
  282. B460800 = $0001004;
  283. CIBAUD = $100F0000;
  284. CMSPAR = $40000000;
  285. CRTSCTS = $80000000;
  286. {c_lflag bits}
  287. ISIG = $0000001;
  288. ICANON = $0000002;
  289. XCASE = $0000004;
  290. ECHO = $0000008;
  291. ECHOE = $0000010;
  292. ECHOK = $0000020;
  293. ECHONL = $0000040;
  294. NOFLSH = $0000080;
  295. TOSTOP = $0000100;
  296. ECHOCTL = $0000200;
  297. ECHOPRT = $0000400;
  298. ECHOKE = $0000800;
  299. FLUSHO = $0001000;
  300. PENDIN = $0004000;
  301. IEXTEN = $0008000;
  302. {c_line bits}
  303. TIOCM_LE = $001;
  304. TIOCM_DTR = $002;
  305. TIOCM_RTS = $004;
  306. TIOCM_ST = $008;
  307. TIOCM_SR = $010;
  308. TIOCM_CTS = $020;
  309. TIOCM_CAR = $040;
  310. TIOCM_RNG = $080;
  311. TIOCM_DSR = $100;
  312. TIOCM_CD = TIOCM_CAR;
  313. TIOCM_RI = TIOCM_RNG;
  314. TIOCM_OUT1 = $2000;
  315. TIOCM_OUT2 = $4000;
  316. {TCSetAttr}
  317. TCSANOW = 0;
  318. TCSADRAIN = 1;
  319. TCSAFLUSH = 2;
  320. {TCFlow}
  321. TCOOFF = 0;
  322. TCOON = 1;
  323. TCIOFF = 2;
  324. TCION = 3;
  325. {TCFlush}
  326. TCIFLUSH = 0;
  327. TCOFLUSH = 1;
  328. TCIOFLUSH = 2;
  329. {********************
  330. Info
  331. ********************}
  332. Type
  333. UTimBuf = packed record{in BSD array[0..1] of timeval, but this is
  334. backwards compatible with linux version}
  335. actime,
  336. {$ifdef BSD}
  337. uactime, {BSD Micro seconds}
  338. {$endif}
  339. modtime
  340. {$ifdef BSD}
  341. ,
  342. umodtime {BSD Micro seconds}
  343. {$endif}
  344. : longint;
  345. end;
  346. UTimeBuf=UTimBuf;
  347. TUTimeBuf=UTimeBuf;
  348. PUTimeBuf=^UTimeBuf;
  349. TSysinfo = packed record
  350. uptime : longint;
  351. loads : array[1..3] of longint;
  352. totalram,
  353. freeram,
  354. sharedram,
  355. bufferram,
  356. totalswap,
  357. freeswap : longint;
  358. procs : integer;
  359. s : string[18];
  360. end;
  361. PSysInfo = ^TSysInfo;
  362. {******************************************************************************
  363. Procedure/Functions
  364. ******************************************************************************}
  365. {$ifdef bsd}
  366. function Do_SysCall(sysnr:longint):longint;
  367. function Do_Syscall(sysnr,param1:integer):longint;
  368. function Do_SysCall(sysnr,param1:LONGINT):longint;
  369. function Do_SysCall(sysnr,param1,param2:LONGINT):longint;
  370. function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint;
  371. function Do_SysCall(sysnr,param1,param2,param3,param4:LONGINT):longint;
  372. function Do_SysCall(sysnr,param1,param2,param3,param4,param5:LONGINT):longint;
  373. function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:LONGINT):longint;
  374. function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:LONGINT):longint;
  375. {$else}
  376. Function SysCall(callnr:longint;var regs:SysCallregs):longint;
  377. {$endif}
  378. {**************************
  379. Time/Date Handling
  380. ***************************}
  381. var
  382. tzdaylight : boolean;
  383. tzseconds : longint;
  384. tzname : array[boolean] of pchar;
  385. { timezone support }
  386. procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
  387. procedure GetLocalTimezone(timer:longint);
  388. procedure ReadTimezoneFile(fn:string);
  389. function GetTimezoneFile:string;
  390. Procedure GetTimeOfDay(var tv:timeval);
  391. Function GetTimeOfDay:longint;
  392. {$ifndef bsd}
  393. Function GetEpochTime: longint;
  394. {$endif}
  395. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  396. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  397. procedure GetTime(var hour,min,sec,msec,usec:word);
  398. procedure GetTime(var hour,min,sec,sec100:word);
  399. procedure GetTime(var hour,min,sec:word);
  400. Procedure GetDate(Var Year,Month,Day:Word);
  401. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  402. {**************************
  403. Process Handling
  404. ***************************}
  405. function CreateShellArgV(const prog:string):ppchar;
  406. function CreateShellArgV(const prog:Ansistring):ppchar;
  407. Procedure Execve(Path:pathstr;args:ppchar;ep:ppchar);
  408. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  409. Procedure Execv(const path:pathstr;args:ppchar);
  410. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  411. Procedure Execl(const Todo:string);
  412. Procedure Execle(Todo:string;Ep:ppchar);
  413. Procedure Execlp(Todo:string;Ep:ppchar);
  414. Function Shell(const Command:String):Longint;
  415. Function Shell(const Command:AnsiString):Longint;
  416. Function Fork:longint;
  417. {Clone for FreeBSD is copied from the LinuxThread port, and rfork based}
  418. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  419. Procedure ExitProcess(val:longint);
  420. Function WaitPid(Pid:longint;Status:pointer;Options:Integer):Longint;
  421. Procedure Nice(N:integer);
  422. {$ifdef bsd}
  423. Function GetPriority(Which,Who:longint):longint;
  424. procedure SetPriority(Which,Who,What:longint);
  425. {$else}
  426. Function GetPriority(Which,Who:Integer):integer;
  427. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  428. {$endif}
  429. Function GetPid:LongInt;
  430. Function GetPPid:LongInt;
  431. Function GetUid:Longint;
  432. Function GetEUid:Longint;
  433. Function GetGid:Longint;
  434. Function GetEGid:Longint;
  435. {**************************
  436. File Handling
  437. ***************************}
  438. Function fdOpen(pathname:string;flags:longint):longint;
  439. Function fdOpen(pathname:string;flags,mode:longint):longint;
  440. Function fdOpen(pathname:pchar;flags:longint):longint;
  441. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  442. Function fdClose(fd:longint):boolean;
  443. Function fdRead(fd:longint;var buf;size:longint):longint;
  444. Function fdWrite(fd:longint;var buf;size:longint):longint;
  445. Function fdTruncate(fd,size:longint):boolean;
  446. Function fdSeek (fd,pos,seektype :longint): longint;
  447. Function fdFlush (fd : Longint) : Boolean;
  448. Function Link(OldPath,NewPath:pathstr):boolean;
  449. Function SymLink(OldPath,NewPath:pathstr):boolean;
  450. {$ifndef bsd}
  451. Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
  452. Function ReadLink(name:pathstr):pathstr;
  453. {$endif}
  454. Function UnLink(Path:pathstr):boolean;
  455. Function UnLink(Path:pchar):Boolean;
  456. Function FReName (OldName,NewName : Pchar) : Boolean;
  457. Function FReName (OldName,NewName : String) : Boolean;
  458. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  459. Function Chmod(path:pathstr;Newmode:longint):boolean;
  460. Function Utime(path:pathstr;utim:utimebuf):boolean;
  461. {$ifdef BSD}
  462. Function Access(Path:Pathstr ;mode:longint):boolean;
  463. {$else}
  464. Function Access(Path:Pathstr ;mode:integer):boolean;
  465. {$endif}
  466. Function Umask(Mask:Integer):integer;
  467. Function Flock (fd,mode : longint) : boolean;
  468. Function Flock (var T : text;mode : longint) : boolean;
  469. Function Flock (var F : File;mode : longint) : boolean;
  470. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  471. Function FStat(Fd:longint;Var Info:stat):Boolean;
  472. Function FStat(var F:Text;Var Info:stat):Boolean;
  473. Function FStat(var F:File;Var Info:stat):Boolean;
  474. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  475. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  476. Function FSStat(Fd: Longint;Var Info:statfs):Boolean;
  477. {$ifdef bsd}
  478. Function Fcntl(Fd:longint;Cmd:longint):longint;
  479. Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
  480. Function Fcntl(var Fd:Text;Cmd:longint):longint;
  481. Procedure Fcntl(var Fd:Text;Cmd:longint;Arg:Longint);
  482. {$else}
  483. Function Fcntl(Fd:longint;Cmd:Integer):integer;
  484. Procedure Fcntl(Fd:longint;Cmd:Integer;Arg:Longint);
  485. Function Fcntl(var Fd:Text;Cmd:Integer):integer;
  486. Procedure Fcntl(var Fd:Text;Cmd:Integer;Arg:Longint);
  487. {$endif}
  488. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  489. Function Dup(var oldfile,newfile:text):Boolean;
  490. Function Dup(var oldfile,newfile:file):Boolean;
  491. Function Dup2(oldfile,newfile:longint):Boolean;
  492. Function Dup2(var oldfile,newfile:text):Boolean;
  493. Function Dup2(var oldfile,newfile:file):Boolean;
  494. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  495. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  496. Function SelectText(var T:Text;TimeOut :PTimeVal):Longint;
  497. {**************************
  498. Directory Handling
  499. ***************************}
  500. Function OpenDir(f:pchar):pdir;
  501. Function OpenDir(f: String):pdir;
  502. function CloseDir(p:pdir):integer;
  503. Function ReadDir(p:pdir):pdirent;
  504. procedure SeekDir(p:pdir;off:longint);
  505. function TellDir(p:pdir):longint;
  506. {**************************
  507. Pipe/Fifo/Stream
  508. ***************************}
  509. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  510. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  511. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  512. Function PClose(Var F:text) : longint;
  513. Function PClose(Var F:file) : longint;
  514. Procedure POpen(var F:text;const Prog:String;rw:char);
  515. Procedure POpen(var F:file;const Prog:String;rw:char);
  516. Function mkFifo(pathname:string;mode:longint):boolean;
  517. function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  518. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  519. {**************************
  520. General information
  521. ***************************}
  522. Function GetEnv(P:string):Pchar;
  523. {$ifndef BSD}
  524. Function GetDomainName:String;
  525. Function GetHostName:String;
  526. Function Sysinfo(var Info:TSysinfo):Boolean;
  527. Function Uname(var unamerec:utsname):Boolean;
  528. {$endif}
  529. {**************************
  530. Signal
  531. ***************************}
  532. Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
  533. Procedure SigProcMask (How:longint;SSet,OldSSet:PSigSet);
  534. Function SigPending:SigSet;
  535. Procedure SigSuspend(Mask:Sigset);
  536. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  537. Function Kill(Pid:longint;Sig:longint):integer;
  538. Procedure SigRaise(Sig:integer);
  539. {$ifndef BSD}
  540. Function Alarm(Sec : Longint) : longint;
  541. Procedure Pause;
  542. {$endif}
  543. {**************************
  544. IOCtl/Termios Functions
  545. ***************************}
  546. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  547. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  548. Function TCSetAttr(fd:longint;OptAct:longint;var tios:TermIOS):boolean;
  549. Procedure CFSetISpeed(var tios:TermIOS;speed:Longint);
  550. Procedure CFSetOSpeed(var tios:TermIOS;speed:Longint);
  551. Procedure CFMakeRaw(var tios:TermIOS);
  552. Function TCSendBreak(fd,duration:longint):boolean;
  553. Function TCSetPGrp(fd,id:longint):boolean;
  554. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  555. Function TCFlush(fd,qsel:longint):boolean;
  556. Function TCDrain(fd:longint):boolean;
  557. Function TCFlow(fd,act:longint):boolean;
  558. Function IsATTY(Handle:Longint):Boolean;
  559. Function IsATTY(f:text):Boolean;
  560. function TTYname(Handle:Longint):string;
  561. function TTYname(var F:Text):string;
  562. {**************************
  563. Memory functions
  564. ***************************}
  565. const
  566. PROT_READ = $1; { page can be read }
  567. PROT_WRITE = $2; { page can be written }
  568. PROT_EXEC = $4; { page can be executed }
  569. PROT_NONE = $0; { page can not be accessed }
  570. MAP_SHARED = $1; { Share changes }
  571. MAP_PRIVATE = $2; { Changes are private }
  572. MAP_TYPE = $f; { Mask for type of mapping }
  573. MAP_FIXED = $10; { Interpret addr exactly }
  574. MAP_ANONYMOUS = $20; { don't use a file }
  575. MAP_GROWSDOWN = $100; { stack-like segment }
  576. MAP_DENYWRITE = $800; { ETXTBSY }
  577. MAP_EXECUTABLE = $1000; { mark it as an executable }
  578. MAP_LOCKED = $2000; { pages are locked }
  579. MAP_NORESERVE = $4000; { don't check for reservations }
  580. type
  581. tmmapargs=record
  582. address : longint;
  583. size : longint;
  584. prot : longint;
  585. flags : longint;
  586. fd : longint;
  587. offset : longint;
  588. end;
  589. function MMap(const m:tmmapargs):longint;
  590. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  591. {**************************
  592. Port IO functions
  593. ***************************}
  594. {$ifndef BSD}
  595. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  596. {$IFDEF I386}
  597. Procedure WritePort (Port : Longint; Value : Byte);
  598. Procedure WritePort (Port : Longint; Value : Word);
  599. Procedure WritePort (Port : Longint; Value : Longint);
  600. Procedure WritePortB (Port : Longint; Value : Byte);
  601. Procedure WritePortW (Port : Longint; Value : Word);
  602. Procedure WritePortL (Port : Longint; Value : Longint);
  603. Procedure WritePortL (Port : Longint; Var Buf; Count: longint);
  604. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  605. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  606. Procedure ReadPort (Port : Longint; Var Value : Byte);
  607. Procedure ReadPort (Port : Longint; Var Value : Word);
  608. Procedure ReadPort (Port : Longint; Var Value : Longint);
  609. function ReadPortB (Port : Longint): Byte;
  610. function ReadPortW (Port : Longint): Word;
  611. function ReadPortL (Port : Longint): LongInt;
  612. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  613. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  614. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  615. {$endif}
  616. {$endif}
  617. {**************************
  618. Utility functions
  619. ***************************}
  620. Function Octal(l:longint):longint;
  621. Function FExpand(Const Path: PathStr):PathStr;
  622. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  623. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  624. Function Dirname(Const path:pathstr):pathstr;
  625. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  626. Function FNMatch(const Pattern,Name:string):Boolean;
  627. Function Glob(Const path:pathstr):pglob;
  628. Procedure Globfree(var p:pglob);
  629. Function StringToPPChar(Var S:STring):ppchar;
  630. Function GetFS(var T:Text):longint;
  631. Function GetFS(Var F:File):longint;
  632. {Filedescriptorsets}
  633. Procedure FD_Zero(var fds:fdSet);
  634. Procedure FD_Clr(fd:longint;var fds:fdSet);
  635. Procedure FD_Set(fd:longint;var fds:fdSet);
  636. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  637. {Stat.Mode Types}
  638. Function S_ISLNK(m:word):boolean;
  639. Function S_ISREG(m:word):boolean;
  640. Function S_ISDIR(m:word):boolean;
  641. Function S_ISCHR(m:word):boolean;
  642. Function S_ISBLK(m:word):boolean;
  643. Function S_ISFIFO(m:word):boolean;
  644. Function S_ISSOCK(m:word):boolean;
  645. {******************************************************************************
  646. Implementation
  647. ******************************************************************************}
  648. Implementation
  649. Uses Strings;
  650. { Get the definitions of textrec and filerec }
  651. {$i textrec.inc}
  652. {$i filerec.inc}
  653. { Raw System calls are in Syscalls.inc}
  654. {$i syscalls.inc}
  655. {$ifdef BSD}
  656. {$i bsdsysca.inc}
  657. {$else}
  658. {$i linsysca.inc}
  659. {$endif}
  660. {******************************************************************************
  661. Process related calls
  662. ******************************************************************************}
  663. function CreateShellArgV(const prog:string):ppchar;
  664. {
  665. Create an argv which executes a command in a shell using /bin/sh -c
  666. }
  667. var
  668. pp,p : ppchar;
  669. temp : string;
  670. begin
  671. getmem(pp,4*4);
  672. temp:='/bin/sh'#0'-c'#0+prog+#0;
  673. p:=pp;
  674. p^:=@temp[1];
  675. inc(p);
  676. p^:=@temp[9];
  677. inc(p);
  678. p^:=@temp[12];
  679. inc(p);
  680. p^:=Nil;
  681. CreateShellArgV:=pp;
  682. end;
  683. function CreateShellArgV(const prog:Ansistring):ppchar;
  684. {
  685. Create an argv which executes a command in a shell using /bin/sh -c
  686. using a AnsiString;
  687. }
  688. var
  689. pp,p : ppchar;
  690. temp : AnsiString;
  691. begin
  692. getmem(pp,4*4);
  693. temp:='/bin/sh'#0'-c'#0+prog+#0;
  694. p:=pp;
  695. GetMem(p^,Length(Temp));
  696. Move(Temp[1],p^^,Length(Temp));
  697. inc(p);
  698. p^:=@pp[0][8];
  699. inc(p);
  700. p^:=@pp[0][11];
  701. inc(p);
  702. p^:=Nil;
  703. CreateShellArgV:=pp;
  704. end;
  705. Procedure Execv(const path:pathstr;args:ppchar);
  706. {
  707. Replaces the current program by the program specified in path,
  708. arguments in args are passed to Execve.
  709. the current environment is passed on.
  710. }
  711. begin
  712. Execve(path,args,envp); {On error linuxerror will get set there}
  713. end;
  714. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  715. {
  716. This does the same as Execve, only it searches the PATH environment
  717. for the place of the Executable, except when Path starts with a slash.
  718. if the PATH environment variable is unavailable, the path is set to '.'
  719. }
  720. var
  721. thepath : string;
  722. begin
  723. if path[1]<>'/' then
  724. begin
  725. Thepath:=strpas(getenv('PATH'));
  726. if thepath='' then
  727. thepath:='.';
  728. Path:=FSearch(path,thepath)
  729. end
  730. else
  731. Path:='';
  732. if Path='' then
  733. linuxerror:=Sys_enoent
  734. else
  735. Execve(Path,args,ep);{On error linuxerror will get set there}
  736. end;
  737. Procedure Execle(Todo:string;Ep:ppchar);
  738. {
  739. This procedure takes the string 'Todo', parses it for command and
  740. command options, and Executes the command with the given options.
  741. The string 'Todo' shoud be of the form 'command options', options
  742. separated by commas.
  743. the PATH environment is not searched for 'command'.
  744. The specified environment(in 'ep') is passed on to command
  745. }
  746. var
  747. p : ppchar;
  748. begin
  749. p:=StringToPPChar(ToDo);
  750. if (p=nil) or (p^=nil) then
  751. exit;
  752. ExecVE(p^,p,EP);
  753. end;
  754. Procedure Execl(const Todo:string);
  755. {
  756. This procedure takes the string 'Todo', parses it for command and
  757. command options, and Executes the command with the given options.
  758. The string 'Todo' shoud be of the form 'command options', options
  759. separated by commas.
  760. the PATH environment is not searched for 'command'.
  761. The current environment is passed on to command
  762. }
  763. begin
  764. ExecLE(ToDo,EnvP);
  765. end;
  766. Procedure Execlp(Todo:string;Ep:ppchar);
  767. {
  768. This procedure takes the string 'Todo', parses it for command and
  769. command options, and Executes the command with the given options.
  770. The string 'Todo' shoud be of the form 'command options', options
  771. separated by commas.
  772. the PATH environment is searched for 'command'.
  773. The specified environment (in 'ep') is passed on to command
  774. }
  775. var
  776. p : ppchar;
  777. begin
  778. p:=StringToPPchar(todo);
  779. if (p=nil) or (p^=nil) then
  780. exit;
  781. ExecVP(StrPas(p^),p,EP);
  782. end;
  783. Function Shell(const Command:String):Longint;
  784. {
  785. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  786. The current environment is passed to the shell.
  787. It waits for the shell to exit, and returns its exit status.
  788. If the Exec call failed exit status 127 is reported.
  789. }
  790. var
  791. p : ppchar;
  792. temp,pid : longint;
  793. begin
  794. pid:=fork;
  795. if pid=-1 then
  796. exit; {Linuxerror already set in Fork}
  797. if pid=0 then
  798. begin
  799. {This is the child.}
  800. p:=CreateShellArgv(command);
  801. Execve(p^,p,envp);
  802. exit(127);
  803. end;
  804. temp:=0;
  805. WaitPid(pid,@temp,0);{Linuxerror is set there}
  806. Shell:=temp;{ Return exit status }
  807. end;
  808. Function Shell(const Command:AnsiString):Longint;
  809. {
  810. AnsiString version of Shell
  811. }
  812. var
  813. p : ppchar;
  814. temp,pid : longint;
  815. begin
  816. pid:=fork;
  817. if pid=-1 then
  818. exit; {Linuxerror already set in Fork}
  819. if pid=0 then
  820. begin
  821. {This is the child.}
  822. p:=CreateShellArgv(command);
  823. Execve(p^,p,envp);
  824. exit(127);
  825. end;
  826. temp:=0;
  827. WaitPid(pid,@temp,0);{Linuxerror is set there}
  828. Shell:=temp;{ Return exit status }
  829. end;
  830. {******************************************************************************
  831. Date and Time related calls
  832. ******************************************************************************}
  833. Const
  834. {Date Translation}
  835. C1970=2440588;
  836. D0 = 1461;
  837. D1 = 146097;
  838. D2 =1721119;
  839. Function GregorianToJulian(Year,Month,Day:Longint):LongInt;
  840. Var
  841. Century,XYear: LongInt;
  842. Begin
  843. If Month<=2 Then
  844. Begin
  845. Dec(Year);
  846. Inc(Month,12);
  847. End;
  848. Dec(Month,3);
  849. Century:=(longint(Year Div 100)*D1) shr 2;
  850. XYear:=(longint(Year Mod 100)*D0) shr 2;
  851. GregorianToJulian:=((((Month*153)+2) div 5)+Day)+D2+XYear+Century;
  852. End;
  853. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  854. Var
  855. YYear,XYear,Temp,TempMonth : LongInt;
  856. Begin
  857. Temp:=((JulianDN-D2) shl 2)-1;
  858. JulianDN:=Temp Div D1;
  859. XYear:=(Temp Mod D1) or 3;
  860. YYear:=(XYear Div D0);
  861. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  862. Day:=((Temp Mod 153)+5) Div 5;
  863. TempMonth:=Temp Div 153;
  864. If TempMonth>=10 Then
  865. Begin
  866. inc(YYear);
  867. dec(TempMonth,12);
  868. End;
  869. inc(TempMonth,3);
  870. Month := TempMonth;
  871. Year:=YYear+(JulianDN*100);
  872. end;
  873. Function GetEpochTime: longint;
  874. {
  875. Get the number of seconds since 00:00, January 1 1970, GMT
  876. the time NOT corrected any way
  877. }
  878. begin
  879. GetEpochTime:=GetTimeOfDay;
  880. end;
  881. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  882. {
  883. Transforms Epoch time into local time (hour, minute,seconds)
  884. }
  885. Var
  886. DateNum: LongInt;
  887. Begin
  888. inc(Epoch,TZSeconds);
  889. Datenum:=(Epoch Div 86400) + c1970;
  890. JulianToGregorian(DateNum,Year,Month,day);
  891. Epoch:=Epoch Mod 86400;
  892. Hour:=Epoch Div 3600;
  893. Epoch:=Epoch Mod 3600;
  894. Minute:=Epoch Div 60;
  895. Second:=Epoch Mod 60;
  896. End;
  897. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  898. {
  899. Transforms local time (year,month,day,hour,minutes,second) to Epoch time
  900. (seconds since 00:00, january 1 1970, corrected for local time zone)
  901. }
  902. Begin
  903. LocalToEpoch:=((GregorianToJulian(Year,Month,Day)-c1970)*86400)+
  904. (LongInt(Hour)*3600)+(Minute*60)+Second-TZSeconds;
  905. End;
  906. procedure GetTime(var hour,min,sec,msec,usec:word);
  907. {
  908. Gets the current time, adjusted to local time
  909. }
  910. var
  911. year,day,month:Word;
  912. t : timeval;
  913. begin
  914. gettimeofday(t);
  915. EpochToLocal(t.sec,year,month,day,hour,min,sec);
  916. msec:=t.usec div 1000;
  917. usec:=t.usec mod 1000;
  918. end;
  919. procedure GetTime(var hour,min,sec,sec100:word);
  920. {
  921. Gets the current time, adjusted to local time
  922. }
  923. var
  924. usec : word;
  925. begin
  926. gettime(hour,min,sec,sec100,usec);
  927. sec100:=sec100 div 10;
  928. end;
  929. Procedure GetTime(Var Hour,Min,Sec:Word);
  930. {
  931. Gets the current time, adjusted to local time
  932. }
  933. var
  934. msec,usec : Word;
  935. Begin
  936. gettime(hour,min,sec,msec,usec);
  937. End;
  938. Procedure GetDate(Var Year,Month,Day:Word);
  939. {
  940. Gets the current date, adjusted to local time
  941. }
  942. var
  943. hour,minute,second : word;
  944. Begin
  945. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  946. End;
  947. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  948. {
  949. Gets the current date, adjusted to local time
  950. }
  951. Begin
  952. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  953. End;
  954. { Include timezone handling routines which use /usr/share/timezone info }
  955. {$i timezone.inc}
  956. {******************************************************************************
  957. FileSystem calls
  958. ******************************************************************************}
  959. Function fdOpen(pathname:string;flags:longint):longint;
  960. begin
  961. pathname:=pathname+#0;
  962. fdOpen:=Sys_Open(@pathname[1],flags,438);
  963. LinuxError:=Errno;
  964. end;
  965. Function fdOpen(pathname:string;flags,mode:longint):longint;
  966. begin
  967. pathname:=pathname+#0;
  968. fdOpen:=Sys_Open(@pathname[1],flags,mode);
  969. LinuxError:=Errno;
  970. end;
  971. Function fdOpen(pathname:pchar;flags:longint):longint;
  972. begin
  973. fdOpen:=Sys_Open(pathname,flags,0);
  974. LinuxError:=Errno;
  975. end;
  976. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  977. begin
  978. fdOpen:=Sys_Open(pathname,flags,mode);
  979. LinuxError:=Errno;
  980. end;
  981. Function fdClose(fd:longint):boolean;
  982. begin
  983. fdClose:=(Sys_Close(fd)=0);
  984. LinuxError:=Errno;
  985. end;
  986. Function fdRead(fd:longint;var buf;size:longint):longint;
  987. begin
  988. fdRead:=Sys_Read(fd,pchar(@buf),size);
  989. LinuxError:=Errno;
  990. end;
  991. Function fdWrite(fd:longint;var buf;size:longint):longint;
  992. begin
  993. fdWrite:=Sys_Write(fd,pchar(@buf),size);
  994. LinuxError:=Errno;
  995. end;
  996. Function fdSeek (fd,pos,seektype :longint): longint;
  997. {
  998. Do a Seek on a file descriptor fd to position pos, starting from seektype
  999. }
  1000. begin
  1001. fdseek:=Sys_LSeek (fd,pos,seektype);
  1002. LinuxError:=Errno;
  1003. end;
  1004. {$ifdef BSD}
  1005. Function Fcntl(Fd:longint;Cmd:longint):longint;
  1006. {
  1007. Read or manipulate a file.(See also fcntl (2) )
  1008. Possible values for Cmd are :
  1009. F_GetFd,F_GetFl,F_GetOwn
  1010. Errors are reported in Linuxerror;
  1011. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  1012. }
  1013. begin
  1014. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  1015. begin
  1016. Linuxerror:=sys_fcntl(fd,cmd,0);
  1017. if linuxerror=-1 then
  1018. begin
  1019. linuxerror:=errno;
  1020. fcntl:=0;
  1021. end
  1022. else
  1023. begin
  1024. fcntl:=linuxerror;
  1025. linuxerror:=0;
  1026. end;
  1027. end
  1028. else
  1029. begin
  1030. linuxerror:=Sys_einval;
  1031. Fcntl:=0;
  1032. end;
  1033. end;
  1034. Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
  1035. {
  1036. Read or manipulate a file. (See also fcntl (2) )
  1037. Possible values for Cmd are :
  1038. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  1039. Errors are reported in Linuxerror;
  1040. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  1041. F_DupFD is not allowed, due to the structure of Files in Pascal.
  1042. }
  1043. begin
  1044. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  1045. begin
  1046. sys_fcntl(fd,cmd,arg);
  1047. LinuxError:=ErrNo;
  1048. end
  1049. else
  1050. linuxerror:=Sys_einval;
  1051. end;
  1052. {$endif}
  1053. {$ifdef BSD}
  1054. Function Fcntl(var Fd:Text;Cmd:longint):longint;
  1055. {$else}
  1056. Function Fcntl(var Fd:Text;Cmd:integer):integer;
  1057. {$endif}
  1058. begin
  1059. Fcntl := Fcntl(textrec(Fd).handle, Cmd);
  1060. end;
  1061. {$ifdef BSD}
  1062. Procedure Fcntl(var Fd:Text;Cmd,Arg:Longint);
  1063. {$else}
  1064. Procedure Fcntl(var Fd:Text;Cmd:Integer;Arg:Longint);
  1065. {$endif}
  1066. begin
  1067. Fcntl(textrec(Fd).handle, Cmd, Arg);
  1068. end;
  1069. Function Flock (var T : text;mode : longint) : boolean;
  1070. begin
  1071. Flock:=Flock(TextRec(T).Handle,mode);
  1072. end;
  1073. Function Flock (var F : File;mode : longint) : boolean;
  1074. begin
  1075. Flock:=Flock(FileRec(F).Handle,mode);
  1076. end;
  1077. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  1078. {
  1079. Get all information on a file, and return it in Info.
  1080. }
  1081. begin
  1082. path:=path+#0;
  1083. FStat:=(Sys_stat(@(path[1]),Info)=0);
  1084. LinuxError:=errno;
  1085. end;
  1086. Function FStat(var F:Text;Var Info:stat):Boolean;
  1087. {
  1088. Get all information on a text file, and return it in info.
  1089. }
  1090. begin
  1091. FStat:=Fstat(TextRec(F).Handle,INfo);
  1092. end;
  1093. Function FStat(var F:File;Var Info:stat):Boolean;
  1094. {
  1095. Get all information on a untyped file, and return it in info.
  1096. }
  1097. begin
  1098. FStat:=Fstat(FileRec(F).Handle,Info);
  1099. end;
  1100. Function SymLink(OldPath,newPath:pathstr):boolean;
  1101. {
  1102. Proceduces a soft link from new to old.
  1103. }
  1104. begin
  1105. oldpath:=oldpath+#0;
  1106. newpath:=newpath+#0;
  1107. Symlink:=Sys_symlink(pchar(@(oldpath[1])),pchar(@(newpath[1])))=0;
  1108. linuxerror:=errno;
  1109. end;
  1110. Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
  1111. {
  1112. Read a link (where it points to)
  1113. }
  1114. begin
  1115. Readlink:=Sys_readlink(Name,LinkName,maxlen);
  1116. linuxerror:=errno;
  1117. end;
  1118. Function ReadLink(Name:pathstr):pathstr;
  1119. {
  1120. Read a link (where it points to)
  1121. }
  1122. var
  1123. LinkName : pathstr;
  1124. i : longint;
  1125. begin
  1126. Name:=Name+#0;
  1127. i:=ReadLink(@Name[1],@LinkName[1],high(linkname));
  1128. if i>0 then
  1129. begin
  1130. linkname[0]:=chr(i);
  1131. ReadLink:=LinkName;
  1132. end
  1133. else
  1134. ReadLink:='';
  1135. end;
  1136. Function UnLink(Path:pathstr):boolean;
  1137. {
  1138. Removes the file in 'Path' (that is, it decreases the link count with one.
  1139. if the link count is zero, the file is removed from the disk.
  1140. }
  1141. begin
  1142. path:=path+#0;
  1143. Unlink:=Sys_unlink(pchar(@(path[1])))=0;
  1144. linuxerror:=errno;
  1145. end;
  1146. Function UnLink(Path:pchar):Boolean;
  1147. {
  1148. Removes the file in 'Path' (that is, it decreases the link count with one.
  1149. if the link count is zero, the file is removed from the disk.
  1150. }
  1151. begin
  1152. Unlink:=(Sys_unlink(path)=0);
  1153. linuxerror:=errno;
  1154. end;
  1155. Function FRename (OldName,NewName : Pchar) : Boolean;
  1156. begin
  1157. FRename:=Sys_rename(OldName,NewName)=0;
  1158. LinuxError:=Errno;
  1159. end;
  1160. Function FRename (OldName,NewName : String) : Boolean;
  1161. begin
  1162. OldName:=OldName+#0;
  1163. NewName:=NewName+#0;
  1164. FRename:=FRename (@OldName[1],@NewName[1]);
  1165. end;
  1166. Function Dup(var oldfile,newfile:text):Boolean;
  1167. {
  1168. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  1169. oldfile.
  1170. After which the two textfiles are, in effect, the same, except
  1171. that they don't share the same buffer, and don't share the same
  1172. close_on_exit flag.
  1173. }
  1174. begin
  1175. flush(oldfile);{ We cannot share buffers, so we flush them. }
  1176. textrec(newfile):=textrec(oldfile);
  1177. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  1178. Dup:=Dup(textrec(oldfile).handle,textrec(newfile).handle);
  1179. end;
  1180. Function Dup(var oldfile,newfile:file):Boolean;
  1181. {
  1182. Copies the filedescriptor oldfile to newfile
  1183. }
  1184. begin
  1185. filerec(newfile):=filerec(oldfile);
  1186. Dup:=Dup(filerec(oldfile).handle,filerec(newfile).handle);
  1187. end;
  1188. Function Dup2(var oldfile,newfile:text):Boolean;
  1189. {
  1190. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  1191. oldfile. It closes newfile if it was still open.
  1192. After which the two textfiles are, in effect, the same, except
  1193. that they don't share the same buffer, and don't share the same
  1194. close_on_exit flag.
  1195. }
  1196. var
  1197. tmphandle : word;
  1198. begin
  1199. case TextRec(oldfile).mode of
  1200. fmOutput, fmInOut, fmAppend :
  1201. flush(oldfile);{ We cannot share buffers, so we flush them. }
  1202. end;
  1203. case TextRec(newfile).mode of
  1204. fmOutput, fmInOut, fmAppend :
  1205. flush(newfile);
  1206. end;
  1207. tmphandle:=textrec(newfile).handle;
  1208. textrec(newfile):=textrec(oldfile);
  1209. textrec(newfile).handle:=tmphandle;
  1210. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  1211. Dup2:=Dup2(textrec(oldfile).handle,textrec(newfile).handle);
  1212. end;
  1213. Function Dup2(var oldfile,newfile:file):Boolean;
  1214. {
  1215. Copies the filedescriptor oldfile to newfile
  1216. }
  1217. begin
  1218. filerec(newfile):=filerec(oldfile);
  1219. Dup2:=Dup2(filerec(oldfile).handle,filerec(newfile).handle);
  1220. end;
  1221. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  1222. {
  1223. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  1224. have changed.
  1225. This function allows specification of a timeout as a longint.
  1226. }
  1227. var
  1228. p : PTimeVal;
  1229. tv : TimeVal;
  1230. begin
  1231. if TimeOut=-1 then
  1232. p:=nil
  1233. else
  1234. begin
  1235. tv.Sec:=Timeout div 1000;
  1236. tv.Usec:=(Timeout mod 1000)*1000;
  1237. p:=@tv;
  1238. end;
  1239. Select:=Select(N,Readfds,WriteFds,ExceptFds,p);
  1240. end;
  1241. Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
  1242. Var
  1243. F:FDSet;
  1244. begin
  1245. if textrec(t).mode=fmclosed then
  1246. begin
  1247. LinuxError:=Sys_EBADF;
  1248. exit(-1);
  1249. end;
  1250. FD_Zero(f);
  1251. FD_Set(textrec(T).handle,f);
  1252. if textrec(T).mode=fminput then
  1253. SelectText:=select(textrec(T).handle+1,@f,nil,nil,TimeOut)
  1254. else
  1255. SelectText:=select(textrec(T).handle+1,nil,@f,nil,TimeOut);
  1256. end;
  1257. {******************************************************************************
  1258. Directory
  1259. ******************************************************************************}
  1260. Function OpenDir(F:String):PDir;
  1261. begin
  1262. F:=F+#0;
  1263. OpenDir:=OpenDir(@F[1]);
  1264. end;
  1265. procedure SeekDir(p:pdir;off:longint);
  1266. begin
  1267. if p=nil then
  1268. begin
  1269. errno:=Sys_EBADF;
  1270. exit;
  1271. end;
  1272. {$ifndef bsd}
  1273. p^.nextoff:=Sys_lseek(p^.fd,off,seek_set);
  1274. {$endif}
  1275. p^.size:=0;
  1276. p^.loc:=0;
  1277. end;
  1278. function TellDir(p:pdir):longint;
  1279. begin
  1280. if p=nil then
  1281. begin
  1282. errno:=Sys_EBADF;
  1283. telldir:=-1;
  1284. exit;
  1285. end;
  1286. telldir:=Sys_lseek(p^.fd,0,seek_cur)
  1287. { We could try to use the nextoff field here, but on my 1.2.13
  1288. kernel, this gives nothing... This may have to do with
  1289. the readdir implementation of libc... I also didn't find any trace of
  1290. the field in the kernel code itself, So I suspect it is an artifact of libc.
  1291. Michael. }
  1292. end;
  1293. Function ReadDir(P:pdir):pdirent;
  1294. begin
  1295. ReadDir:=Sys_ReadDir(p);
  1296. LinuxError:=Errno;
  1297. end;
  1298. {******************************************************************************
  1299. Pipes/Fifo
  1300. ******************************************************************************}
  1301. Procedure OpenPipe(var F:Text);
  1302. begin
  1303. case textrec(f).mode of
  1304. fmoutput :
  1305. if textrec(f).userdata[1]<>P_OUT then
  1306. textrec(f).mode:=fmclosed;
  1307. fminput :
  1308. if textrec(f).userdata[1]<>P_IN then
  1309. textrec(f).mode:=fmclosed;
  1310. else
  1311. textrec(f).mode:=fmclosed;
  1312. end;
  1313. end;
  1314. Procedure IOPipe(var F:text);
  1315. begin
  1316. case textrec(f).mode of
  1317. fmoutput :
  1318. begin
  1319. { first check if we need something to write, else we may
  1320. get a SigPipe when Close() is called (PFV) }
  1321. if textrec(f).bufpos>0 then
  1322. Sys_write(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  1323. end;
  1324. fminput :
  1325. textrec(f).bufend:=Sys_read(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  1326. end;
  1327. textrec(f).bufpos:=0;
  1328. end;
  1329. Procedure FlushPipe(var F:Text);
  1330. begin
  1331. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  1332. IOPipe(f);
  1333. textrec(f).bufpos:=0;
  1334. end;
  1335. Procedure ClosePipe(var F:text);
  1336. begin
  1337. textrec(f).mode:=fmclosed;
  1338. Sys_close(textrec(f).handle);
  1339. end;
  1340. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  1341. {
  1342. Sets up a pair of file variables, which act as a pipe. The first one can
  1343. be read from, the second one can be written to.
  1344. If the operation was unsuccesful, linuxerror is set.
  1345. }
  1346. var
  1347. f_in,f_out : longint;
  1348. begin
  1349. if not AssignPipe(f_in,f_out) then
  1350. begin
  1351. AssignPipe:=false;
  1352. exit;
  1353. end;
  1354. { Set up input }
  1355. Assign(Pipe_in,'');
  1356. Textrec(Pipe_in).Handle:=f_in;
  1357. Textrec(Pipe_in).Mode:=fmInput;
  1358. Textrec(Pipe_in).userdata[1]:=P_IN;
  1359. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  1360. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  1361. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  1362. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  1363. { Set up output }
  1364. Assign(Pipe_out,'');
  1365. Textrec(Pipe_out).Handle:=f_out;
  1366. Textrec(Pipe_out).Mode:=fmOutput;
  1367. Textrec(Pipe_out).userdata[1]:=P_OUT;
  1368. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  1369. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  1370. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  1371. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  1372. AssignPipe:=true;
  1373. end;
  1374. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  1375. {
  1376. Sets up a pair of file variables, which act as a pipe. The first one can
  1377. be read from, the second one can be written to.
  1378. If the operation was unsuccesful, linuxerror is set.
  1379. }
  1380. var
  1381. f_in,f_out : longint;
  1382. begin
  1383. if not AssignPipe(f_in,f_out) then
  1384. begin
  1385. AssignPipe:=false;
  1386. exit;
  1387. end;
  1388. { Set up input }
  1389. Assign(Pipe_in,'');
  1390. Filerec(Pipe_in).Handle:=f_in;
  1391. Filerec(Pipe_in).Mode:=fmInput;
  1392. Filerec(Pipe_in).recsize:=1;
  1393. Filerec(Pipe_in).userdata[1]:=P_IN;
  1394. { Set up output }
  1395. Assign(Pipe_out,'');
  1396. Filerec(Pipe_out).Handle:=f_out;
  1397. Filerec(Pipe_out).Mode:=fmoutput;
  1398. Filerec(Pipe_out).recsize:=1;
  1399. Filerec(Pipe_out).userdata[1]:=P_OUT;
  1400. AssignPipe:=true;
  1401. end;
  1402. Procedure PCloseText(Var F:text);
  1403. {
  1404. May not use @PClose due overloading
  1405. }
  1406. begin
  1407. PClose(f);
  1408. end;
  1409. Procedure POpen(var F:text;const Prog:String;rw:char);
  1410. {
  1411. Starts the program in 'Prog' and makes it's input or out put the
  1412. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  1413. F, will be read from stdin by the program in 'Prog'. The inverse is true
  1414. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  1415. read from 'f'.
  1416. }
  1417. var
  1418. pipi,
  1419. pipo : text;
  1420. pid : longint;
  1421. pl : ^longint;
  1422. pp : ppchar;
  1423. begin
  1424. LinuxError:=0;
  1425. rw:=upcase(rw);
  1426. if not (rw in ['R','W']) then
  1427. begin
  1428. LinuxError:=Sys_enoent;
  1429. exit;
  1430. end;
  1431. AssignPipe(pipi,pipo);
  1432. if Linuxerror<>0 then
  1433. exit;
  1434. pid:=fork;
  1435. if linuxerror<>0 then
  1436. begin
  1437. close(pipi);
  1438. close(pipo);
  1439. exit;
  1440. end;
  1441. if pid=0 then
  1442. begin
  1443. { We're in the child }
  1444. if rw='W' then
  1445. begin
  1446. close(pipo);
  1447. dup2(pipi,input);
  1448. close(pipi);
  1449. if linuxerror<>0 then
  1450. halt(127);
  1451. end
  1452. else
  1453. begin
  1454. close(pipi);
  1455. dup2(pipo,output);
  1456. close(pipo);
  1457. if linuxerror<>0 then
  1458. halt(127);
  1459. end;
  1460. pp:=createshellargv(prog);
  1461. Execve(pp^,pp,envp);
  1462. halt(127);
  1463. end
  1464. else
  1465. begin
  1466. { We're in the parent }
  1467. if rw='W' then
  1468. begin
  1469. close(pipi);
  1470. f:=pipo;
  1471. textrec(f).bufptr:=@textrec(f).buffer;
  1472. end
  1473. else
  1474. begin
  1475. close(pipo);
  1476. f:=pipi;
  1477. textrec(f).bufptr:=@textrec(f).buffer;
  1478. end;
  1479. {Save the process ID - needed when closing }
  1480. pl:=@(textrec(f).userdata[2]);
  1481. pl^:=pid;
  1482. textrec(f).closefunc:=@PCloseText;
  1483. end;
  1484. end;
  1485. Procedure POpen(var F:file;const Prog:String;rw:char);
  1486. {
  1487. Starts the program in 'Prog' and makes it's input or out put the
  1488. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  1489. F, will be read from stdin by the program in 'Prog'. The inverse is true
  1490. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  1491. read from 'f'.
  1492. }
  1493. var
  1494. pipi,
  1495. pipo : file;
  1496. pid : longint;
  1497. pl : ^longint;
  1498. p,pp : ppchar;
  1499. temp : string[255];
  1500. begin
  1501. LinuxError:=0;
  1502. rw:=upcase(rw);
  1503. if not (rw in ['R','W']) then
  1504. begin
  1505. LinuxError:=Sys_enoent;
  1506. exit;
  1507. end;
  1508. AssignPipe(pipi,pipo);
  1509. if Linuxerror<>0 then
  1510. exit;
  1511. pid:=fork;
  1512. if linuxerror<>0 then
  1513. begin
  1514. close(pipi);
  1515. close(pipo);
  1516. exit;
  1517. end;
  1518. if pid=0 then
  1519. begin
  1520. { We're in the child }
  1521. if rw='W' then
  1522. begin
  1523. close(pipo);
  1524. dup2(filerec(pipi).handle,stdinputhandle);
  1525. close(pipi);
  1526. if linuxerror<>0 then
  1527. halt(127);
  1528. end
  1529. else
  1530. begin
  1531. close(pipi);
  1532. dup2(filerec(pipo).handle,stdoutputhandle);
  1533. close(pipo);
  1534. if linuxerror<>0 then
  1535. halt(127);
  1536. end;
  1537. getmem(pp,sizeof(pchar)*4);
  1538. temp:='/bin/sh'#0'-c'#0+prog+#0;
  1539. p:=pp;
  1540. p^:=@temp[1];
  1541. inc(p);
  1542. p^:=@temp[9];
  1543. inc(p);
  1544. p^:=@temp[12];
  1545. inc(p);
  1546. p^:=Nil;
  1547. Execve('/bin/sh',pp,envp);
  1548. halt(127);
  1549. end
  1550. else
  1551. begin
  1552. { We're in the parent }
  1553. if rw='W' then
  1554. begin
  1555. close(pipi);
  1556. f:=pipo;
  1557. end
  1558. else
  1559. begin
  1560. close(pipo);
  1561. f:=pipi;
  1562. end;
  1563. {Save the process ID - needed when closing }
  1564. pl:=@(filerec(f).userdata[2]);
  1565. pl^:=pid;
  1566. end;
  1567. end;
  1568. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  1569. {
  1570. Starts the program in 'Prog' and makes its input and output the
  1571. other end of two pipes, which are the stdin and stdout of a program
  1572. specified in 'Prog'.
  1573. streamout can be used to write to the program, streamin can be used to read
  1574. the output of the program. See the following diagram :
  1575. Parent Child
  1576. STreamout --> Input
  1577. Streamin <-- Output
  1578. Return value is the process ID of the process being spawned, or -1 in case of failure.
  1579. }
  1580. var
  1581. pipi,
  1582. pipo : text;
  1583. pid : longint;
  1584. pl : ^Longint;
  1585. begin
  1586. LinuxError:=0;
  1587. AssignStream:=-1;
  1588. AssignPipe(streamin,pipo);
  1589. if Linuxerror<>0 then
  1590. exit;
  1591. AssignPipe(pipi,streamout);
  1592. if Linuxerror<>0 then
  1593. exit;
  1594. pid:=fork;
  1595. if linuxerror<>0 then
  1596. begin
  1597. close(pipi);
  1598. close(pipo);
  1599. close (streamin);
  1600. close (streamout);
  1601. exit;
  1602. end;
  1603. if pid=0 then
  1604. begin
  1605. { We're in the child }
  1606. { Close what we don't need }
  1607. close(streamout);
  1608. close(streamin);
  1609. dup2(pipi,input);
  1610. if linuxerror<>0 then
  1611. halt(127);
  1612. close(pipi);
  1613. dup2(pipo,output);
  1614. if linuxerror<>0 then
  1615. halt (127);
  1616. close(pipo);
  1617. Execl(Prog);
  1618. halt(127);
  1619. end
  1620. else
  1621. begin
  1622. { we're in the parent}
  1623. close(pipo);
  1624. close(pipi);
  1625. {Save the process ID - needed when closing }
  1626. pl:=@(textrec(StreamIn).userdata[2]);
  1627. pl^:=pid;
  1628. textrec(StreamIn).closefunc:=@PCloseText;
  1629. {Save the process ID - needed when closing }
  1630. pl:=@(textrec(StreamOut).userdata[2]);
  1631. pl^:=pid;
  1632. textrec(StreamOut).closefunc:=@PCloseText;
  1633. AssignStream:=Pid;
  1634. end;
  1635. end;
  1636. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  1637. {
  1638. Starts the program in 'prog' and makes its input, output and error output the
  1639. other end of three pipes, which are the stdin, stdout and stderr of a program
  1640. specified in 'prog'.
  1641. StreamOut can be used to write to the program, StreamIn can be used to read
  1642. the output of the program, StreamErr reads the error output of the program.
  1643. See the following diagram :
  1644. Parent Child
  1645. StreamOut --> StdIn (input)
  1646. StreamIn <-- StdOut (output)
  1647. StreamErr <-- StdErr (error output)
  1648. }
  1649. var
  1650. PipeIn, PipeOut, PipeErr: text;
  1651. pid: LongInt;
  1652. pl: ^LongInt;
  1653. begin
  1654. LinuxError := 0;
  1655. AssignStream := -1;
  1656. // Assign pipes
  1657. AssignPipe(StreamIn, PipeOut);
  1658. if LinuxError <> 0 then exit;
  1659. AssignPipe(StreamErr, PipeErr);
  1660. if LinuxError <> 0 then begin
  1661. Close(StreamIn);
  1662. Close(PipeOut);
  1663. exit;
  1664. end;
  1665. AssignPipe(PipeIn, StreamOut);
  1666. if LinuxError <> 0 then begin
  1667. Close(StreamIn);
  1668. Close(PipeOut);
  1669. Close(StreamErr);
  1670. Close(PipeErr);
  1671. exit;
  1672. end;
  1673. // Fork
  1674. pid := Fork;
  1675. if LinuxError <> 0 then begin
  1676. Close(StreamIn);
  1677. Close(PipeOut);
  1678. Close(StreamErr);
  1679. Close(PipeErr);
  1680. Close(PipeIn);
  1681. Close(StreamOut);
  1682. exit;
  1683. end;
  1684. if pid = 0 then begin
  1685. // *** We are in the child ***
  1686. // Close what we don not need
  1687. Close(StreamOut);
  1688. Close(StreamIn);
  1689. Close(StreamErr);
  1690. // Connect pipes
  1691. dup2(PipeIn, Input);
  1692. if LinuxError <> 0 then Halt(127);
  1693. Close(PipeIn);
  1694. dup2(PipeOut, Output);
  1695. if LinuxError <> 0 then Halt(127);
  1696. Close(PipeOut);
  1697. dup2(PipeErr, StdErr);
  1698. if LinuxError <> 0 then Halt(127);
  1699. Close(PipeErr);
  1700. // Execute program
  1701. Execl(Prog);
  1702. Halt(127);
  1703. end else begin
  1704. // *** We are in the parent ***
  1705. Close(PipeErr);
  1706. Close(PipeOut);
  1707. Close(PipeIn);
  1708. // Save the process ID - needed when closing
  1709. pl := @(TextRec(StreamIn).userdata[2]);
  1710. pl^ := pid;
  1711. TextRec(StreamIn).closefunc := @PCloseText;
  1712. // Save the process ID - needed when closing
  1713. pl := @(TextRec(StreamOut).userdata[2]);
  1714. pl^ := pid;
  1715. TextRec(StreamOut).closefunc := @PCloseText;
  1716. // Save the process ID - needed when closing
  1717. pl := @(TextRec(StreamErr).userdata[2]);
  1718. pl^ := pid;
  1719. TextRec(StreamErr).closefunc := @PCloseText;
  1720. AssignStream := pid;
  1721. end;
  1722. end;
  1723. {******************************************************************************
  1724. General information calls
  1725. ******************************************************************************}
  1726. Function GetEnv(P:string):Pchar;
  1727. {
  1728. Searches the environment for a string with name p and
  1729. returns a pchar to it's value.
  1730. A pchar is used to accomodate for strings of length > 255
  1731. }
  1732. var
  1733. ep : ppchar;
  1734. found : boolean;
  1735. Begin
  1736. p:=p+'='; {Else HOST will also find HOSTNAME, etc}
  1737. ep:=envp;
  1738. found:=false;
  1739. if ep<>nil then
  1740. begin
  1741. while (not found) and (ep^<>nil) do
  1742. begin
  1743. if strlcomp(@p[1],(ep^),length(p))=0 then
  1744. found:=true
  1745. else
  1746. inc(ep);
  1747. end;
  1748. end;
  1749. if found then
  1750. getenv:=ep^+length(p)
  1751. else
  1752. getenv:=nil;
  1753. end;
  1754. {$ifndef bsd}
  1755. Function GetDomainName:String;
  1756. {
  1757. Get machines domain name. Returns empty string if not set.
  1758. }
  1759. Var
  1760. Sysn : utsname;
  1761. begin
  1762. Uname(Sysn);
  1763. linuxerror:=errno;
  1764. If linuxerror<>0 then
  1765. getdomainname:=''
  1766. else
  1767. getdomainname:=strpas(@Sysn.domainname[0]);
  1768. end;
  1769. Function GetHostName:String;
  1770. {
  1771. Get machines name. Returns empty string if not set.
  1772. }
  1773. Var
  1774. Sysn : utsname;
  1775. begin
  1776. uname(Sysn);
  1777. linuxerror:=errno;
  1778. If linuxerror<>0 then
  1779. gethostname:=''
  1780. else
  1781. gethostname:=strpas(@Sysn.nodename[0]);
  1782. end;
  1783. {$endif}
  1784. {******************************************************************************
  1785. Signal handling calls
  1786. ******************************************************************************}
  1787. procedure SigRaise(sig:integer);
  1788. begin
  1789. Kill(GetPid,Sig);
  1790. end;
  1791. {******************************************************************************
  1792. IOCtl and Termios calls
  1793. ******************************************************************************}
  1794. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  1795. begin
  1796. TCGetAttr:=IOCtl(fd,TCGETS,@tios);
  1797. end;
  1798. Function TCSetAttr(fd:longint;OptAct:longint;var tios:TermIOS):boolean;
  1799. var
  1800. nr:longint;
  1801. begin
  1802. case OptAct of
  1803. TCSANOW : nr:=TCSETS;
  1804. TCSADRAIN : nr:=TCSETSW;
  1805. TCSAFLUSH : nr:=TCSETSF;
  1806. else
  1807. begin
  1808. ErrNo:=Sys_EINVAL;
  1809. TCSetAttr:=false;
  1810. exit;
  1811. end;
  1812. end;
  1813. TCSetAttr:=IOCtl(fd,nr,@Tios);
  1814. end;
  1815. Procedure CFSetISpeed(var tios:TermIOS;speed:Longint);
  1816. begin
  1817. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  1818. end;
  1819. Procedure CFSetOSpeed(var tios:TermIOS;speed:Longint);
  1820. begin
  1821. CFSetISpeed(tios,speed);
  1822. end;
  1823. Procedure CFMakeRaw(var tios:TermIOS);
  1824. begin
  1825. with tios do
  1826. begin
  1827. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  1828. INLCR or IGNCR or ICRNL or IXON));
  1829. c_oflag:=c_oflag and (not OPOST);
  1830. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  1831. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  1832. end;
  1833. end;
  1834. Function TCSendBreak(fd,duration:longint):boolean;
  1835. begin
  1836. TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
  1837. end;
  1838. Function TCSetPGrp(fd,id:longint):boolean;
  1839. begin
  1840. TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
  1841. end;
  1842. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  1843. begin
  1844. TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
  1845. end;
  1846. Function TCDrain(fd:longint):boolean;
  1847. begin
  1848. TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
  1849. end;
  1850. Function TCFlow(fd,act:longint):boolean;
  1851. begin
  1852. TCFlow:=IOCtl(fd,TCXONC,pointer(act));
  1853. end;
  1854. Function TCFlush(fd,qsel:longint):boolean;
  1855. begin
  1856. TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
  1857. end;
  1858. Function IsATTY(Handle:Longint):Boolean;
  1859. {
  1860. Check if the filehandle described by 'handle' is a TTY (Terminal)
  1861. }
  1862. var
  1863. t : Termios;
  1864. begin
  1865. IsAtty:=TCGetAttr(Handle,t);
  1866. end;
  1867. Function IsATTY(f: text):Boolean;
  1868. {
  1869. Idem as previous, only now for text variables.
  1870. }
  1871. begin
  1872. IsATTY:=IsaTTY(textrec(f).handle);
  1873. end;
  1874. function TTYName(Handle:Longint):string;
  1875. {
  1876. Return the name of the current tty described by handle f.
  1877. returns empty string in case of an error.
  1878. }
  1879. Const
  1880. dev='/dev';
  1881. var
  1882. name : string;
  1883. st : stat;
  1884. mydev,
  1885. myino : longint;
  1886. dirstream : pdir;
  1887. d : pdirent;
  1888. begin
  1889. TTYName:='';
  1890. fstat(handle,st);
  1891. if (errno<>0) and isatty (handle) then
  1892. exit;
  1893. mydev:=st.dev;
  1894. myino:=st.ino;
  1895. dirstream:=opendir(dev);
  1896. if (linuxerror<>0) then
  1897. exit;
  1898. d:=Readdir(dirstream);
  1899. while (d<>nil) do
  1900. begin
  1901. if (d^.ino=myino) then
  1902. begin
  1903. name:=dev+'/'+strpas(@(d^.name));
  1904. fstat(name,st);
  1905. if (linuxerror=0) and (st.dev=mydev) then
  1906. begin
  1907. closedir(dirstream);
  1908. ttyname:=name;
  1909. exit;
  1910. end;
  1911. end;
  1912. d:=Readdir(dirstream);
  1913. end;
  1914. closedir(dirstream);
  1915. end;
  1916. function TTYName(var F:Text):string;
  1917. {
  1918. Idem as previous, only now for text variables;
  1919. }
  1920. begin
  1921. TTYName:=TTYName(textrec(f).handle);
  1922. end;
  1923. {******************************************************************************
  1924. Utility calls
  1925. ******************************************************************************}
  1926. Function Octal(l:longint):longint;
  1927. {
  1928. Convert an octal specified number to decimal;
  1929. }
  1930. var
  1931. octnr,
  1932. oct : longint;
  1933. begin
  1934. octnr:=0;
  1935. oct:=0;
  1936. while (l>0) do
  1937. begin
  1938. oct:=oct or ((l mod 10) shl octnr);
  1939. l:=l div 10;
  1940. inc(octnr,3);
  1941. end;
  1942. Octal:=oct;
  1943. end;
  1944. Function StringToPPChar(Var S:STring):ppchar;
  1945. {
  1946. Create a PPChar to structure of pchars which are the arguments specified
  1947. in the string S. Especially usefull for creating an ArgV for Exec-calls
  1948. }
  1949. var
  1950. nr : longint;
  1951. Buf : ^char;
  1952. p : ppchar;
  1953. begin
  1954. s:=s+#0;
  1955. buf:=@s[1];
  1956. nr:=0;
  1957. while(buf^<>#0) do
  1958. begin
  1959. while (buf^ in [' ',#8,#10]) do
  1960. inc(buf);
  1961. inc(nr);
  1962. while not (buf^ in [' ',#0,#8,#10]) do
  1963. inc(buf);
  1964. end;
  1965. getmem(p,nr*4);
  1966. StringToPPChar:=p;
  1967. if p=nil then
  1968. begin
  1969. LinuxError:=sys_enomem;
  1970. exit;
  1971. end;
  1972. buf:=@s[1];
  1973. while (buf^<>#0) do
  1974. begin
  1975. while (buf^ in [' ',#8,#10]) do
  1976. begin
  1977. buf^:=#0;
  1978. inc(buf);
  1979. end;
  1980. p^:=buf;
  1981. inc(p);
  1982. p^:=nil;
  1983. while not (buf^ in [' ',#0,#8,#10]) do
  1984. inc(buf);
  1985. end;
  1986. end;
  1987. Function FExpand(Const Path:PathStr):PathStr;
  1988. var
  1989. temp : pathstr;
  1990. i,j : longint;
  1991. p : pchar;
  1992. Begin
  1993. {Remove eventual drive - doesn't exist in Linux}
  1994. if path[2]=':' then
  1995. i:=3
  1996. else
  1997. i:=1;
  1998. temp:='';
  1999. {Replace ~/ with $HOME}
  2000. if (path[i]='~') and ((i+1>length(path)) or (path[i+1]='/')) then
  2001. begin
  2002. p:=getenv('HOME');
  2003. if not (p=nil) then
  2004. Insert(StrPas(p),temp,i);
  2005. i:=1;
  2006. temp:=temp+Copy(Path,2,255);
  2007. end;
  2008. {Do we have an absolute path ? No - prefix the current dir}
  2009. if temp='' then
  2010. begin
  2011. if path[i]<>'/' then
  2012. begin
  2013. {$I-}
  2014. getdir(0,temp);
  2015. {$I+}
  2016. if ioresult<>0 then;
  2017. end
  2018. else
  2019. inc(i);
  2020. temp:=temp+'/'+copy(path,i,length(path)-i+1)+'/';
  2021. end;
  2022. {First remove all references to '/./'}
  2023. while pos('/./',temp)<>0 do
  2024. delete(temp,pos('/./',temp),2);
  2025. {Now remove also all references to '/../' + of course previous dirs..}
  2026. repeat
  2027. i:=pos('/../',temp);
  2028. {Find the pos of the previous dir}
  2029. if i>1 then
  2030. begin
  2031. j:=i-1;
  2032. while (j>1) and (temp[j]<>'/') do
  2033. dec (j);{temp[1] is always '/'}
  2034. delete(temp,j,i-j+3);
  2035. end
  2036. else
  2037. if i=1 then {i=1, so we have temp='/../something', just delete '/../'}
  2038. delete(temp,1,3);
  2039. until i=0;
  2040. { Remove ending /.. }
  2041. i:=pos('/..',temp);
  2042. if (i<>0) and (i =length(temp)-2) then
  2043. begin
  2044. j:=i-1;
  2045. while (j>1) and (temp[j]<>'/') do
  2046. dec (j);
  2047. delete (temp,j,i-j+3);
  2048. end;
  2049. { if last character is / then remove it - dir is also a file :-) }
  2050. if (length(temp)>0) and (temp[length(temp)]='/') then
  2051. dec(byte(temp[0]));
  2052. fexpand:=temp;
  2053. End;
  2054. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  2055. {
  2056. Searches for a file 'path' in the list of direcories in 'dirlist'.
  2057. returns an empty string if not found. Wildcards are NOT allowed.
  2058. If dirlist is empty, it is set to '.'
  2059. }
  2060. Var
  2061. NewDir : PathStr;
  2062. p1 : Longint;
  2063. Info : Stat;
  2064. Begin
  2065. {Replace ':' with ';'}
  2066. for p1:=1to length(dirlist) do
  2067. if dirlist[p1]=':' then
  2068. dirlist[p1]:=';';
  2069. {Check for WildCards}
  2070. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  2071. FSearch:='' {No wildcards allowed in these things.}
  2072. Else
  2073. Begin
  2074. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  2075. Repeat
  2076. p1:=Pos(';',DirList);
  2077. If p1=0 Then
  2078. p1:=255;
  2079. NewDir:=Copy(DirList,1,P1 - 1);
  2080. if NewDir[Length(NewDir)]<>'/' then
  2081. NewDir:=NewDir+'/';
  2082. NewDir:=NewDir+Path;
  2083. Delete(DirList,1,p1);
  2084. if FStat(NewDir,Info) then
  2085. Begin
  2086. If Pos('./',NewDir)=1 Then
  2087. Delete(NewDir,1,2);
  2088. {DOS strips off an initial .\}
  2089. End
  2090. Else
  2091. NewDir:='';
  2092. Until (DirList='') or (Length(NewDir) > 0);
  2093. FSearch:=NewDir;
  2094. End;
  2095. End;
  2096. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  2097. Var
  2098. DotPos,SlashPos,i : longint;
  2099. Begin
  2100. SlashPos:=0;
  2101. DotPos:=256;
  2102. i:=Length(Path);
  2103. While (i>0) and (SlashPos=0) Do
  2104. Begin
  2105. If (DotPos=256) and (Path[i]='.') Then
  2106. begin
  2107. DotPos:=i;
  2108. end;
  2109. If (Path[i]='/') Then
  2110. SlashPos:=i;
  2111. Dec(i);
  2112. End;
  2113. Ext:=Copy(Path,DotPos,255);
  2114. Dir:=Copy(Path,1,SlashPos);
  2115. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  2116. End;
  2117. Function Dirname(Const path:pathstr):pathstr;
  2118. {
  2119. This function returns the directory part of a complete path.
  2120. Unless the directory is root '/', The last character is not
  2121. a slash.
  2122. }
  2123. var
  2124. Dir : PathStr;
  2125. Name : NameStr;
  2126. Ext : ExtStr;
  2127. begin
  2128. FSplit(Path,Dir,Name,Ext);
  2129. if length(Dir)>1 then
  2130. Delete(Dir,length(Dir),1);
  2131. DirName:=Dir;
  2132. end;
  2133. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  2134. {
  2135. This function returns the filename part of a complete path. If suf is
  2136. supplied, it is cut off the filename.
  2137. }
  2138. var
  2139. Dir : PathStr;
  2140. Name : NameStr;
  2141. Ext : ExtStr;
  2142. begin
  2143. FSplit(Path,Dir,Name,Ext);
  2144. if Suf<>Ext then
  2145. Name:=Name+Ext;
  2146. BaseName:=Name;
  2147. end;
  2148. Function FNMatch(const Pattern,Name:string):Boolean;
  2149. Var
  2150. LenPat,LenName : longint;
  2151. Function DoFNMatch(i,j:longint):Boolean;
  2152. Var
  2153. Found : boolean;
  2154. Begin
  2155. Found:=true;
  2156. While Found and (i<=LenPat) Do
  2157. Begin
  2158. Case Pattern[i] of
  2159. '?' : Found:=(j<=LenName);
  2160. '*' : Begin
  2161. {find the next character in pattern, different of ? and *}
  2162. while Found and (i<LenPat) do
  2163. begin
  2164. inc(i);
  2165. case Pattern[i] of
  2166. '*' : ;
  2167. '?' : begin
  2168. inc(j);
  2169. Found:=(j<=LenName);
  2170. end;
  2171. else
  2172. Found:=false;
  2173. end;
  2174. end;
  2175. {Now, find in name the character which i points to, if the * or ?
  2176. wasn't the last character in the pattern, else, use up all the
  2177. chars in name}
  2178. Found:=true;
  2179. if (i<=LenPat) then
  2180. begin
  2181. repeat
  2182. {find a letter (not only first !) which maches pattern[i]}
  2183. while (j<=LenName) and (name[j]<>pattern[i]) do
  2184. inc (j);
  2185. if (j<LenName) then
  2186. begin
  2187. if DoFnMatch(i+1,j+1) then
  2188. begin
  2189. i:=LenPat;
  2190. j:=LenName;{we can stop}
  2191. Found:=true;
  2192. end
  2193. else
  2194. inc(j);{We didn't find one, need to look further}
  2195. end;
  2196. until (j>=LenName);
  2197. end
  2198. else
  2199. j:=LenName;{we can stop}
  2200. end;
  2201. else {not a wildcard character in pattern}
  2202. Found:=(j<=LenName) and (pattern[i]=name[j]);
  2203. end;
  2204. inc(i);
  2205. inc(j);
  2206. end;
  2207. DoFnMatch:=Found and (j>LenName);
  2208. end;
  2209. Begin {start FNMatch}
  2210. LenPat:=Length(Pattern);
  2211. LenName:=Length(Name);
  2212. FNMatch:=DoFNMatch(1,1);
  2213. End;
  2214. Procedure Globfree(var p : pglob);
  2215. {
  2216. Release memory occupied by pglob structure, and names in it.
  2217. sets p to nil.
  2218. }
  2219. var
  2220. temp : pglob;
  2221. begin
  2222. while assigned(p) do
  2223. begin
  2224. temp:=p^.next;
  2225. if assigned(p^.name) then
  2226. freemem(p^.name);
  2227. dispose(p);
  2228. p:=temp;
  2229. end;
  2230. end;
  2231. Function Glob(Const path:pathstr):pglob;
  2232. {
  2233. Fills a tglob structure with entries matching path,
  2234. and returns a pointer to it. Returns nil on error,
  2235. linuxerror is set accordingly.
  2236. }
  2237. var
  2238. temp,
  2239. temp2 : string[255];
  2240. thedir : pdir;
  2241. buffer : pdirent;
  2242. root,
  2243. current : pglob;
  2244. begin
  2245. { Get directory }
  2246. temp:=dirname(path);
  2247. if temp='' then
  2248. temp:='.';
  2249. temp:=temp+#0;
  2250. thedir:=opendir(@temp[1]);
  2251. if thedir=nil then
  2252. begin
  2253. glob:=nil;
  2254. linuxerror:=errno;
  2255. exit;
  2256. end;
  2257. temp:=basename(path,''); { get the pattern }
  2258. if thedir^.fd<0 then
  2259. begin
  2260. linuxerror:=errno;
  2261. glob:=nil;
  2262. exit;
  2263. end;
  2264. {get the entries}
  2265. root:=nil;
  2266. current:=nil;
  2267. repeat
  2268. buffer:=Sys_readdir(thedir);
  2269. if buffer=nil then
  2270. break;
  2271. temp2:=strpas(@(buffer^.name[0]));
  2272. if fnmatch(temp,temp2) then
  2273. begin
  2274. if root=nil then
  2275. begin
  2276. new(root);
  2277. current:=root;
  2278. end
  2279. else
  2280. begin
  2281. new(current^.next);
  2282. current:=current^.next;
  2283. end;
  2284. if current=nil then
  2285. begin
  2286. linuxerror:=Sys_ENOMEM;
  2287. globfree(root);
  2288. break;
  2289. end;
  2290. current^.next:=nil;
  2291. getmem(current^.name,length(temp2)+1);
  2292. if current^.name=nil then
  2293. begin
  2294. linuxerror:=Sys_ENOMEM;
  2295. globfree(root);
  2296. break;
  2297. end;
  2298. move(buffer^.name[0],current^.name^,length(temp2)+1);
  2299. end;
  2300. until false;
  2301. closedir(thedir);
  2302. glob:=root;
  2303. end;
  2304. {--------------------------------
  2305. FiledescriptorSets
  2306. --------------------------------}
  2307. Procedure FD_Zero(var fds:fdSet);
  2308. {
  2309. Clear the set of filedescriptors
  2310. }
  2311. begin
  2312. FillChar(fds,sizeof(fdSet),0);
  2313. end;
  2314. Procedure FD_Clr(fd:longint;var fds:fdSet);
  2315. {
  2316. Remove fd from the set of filedescriptors
  2317. }
  2318. begin
  2319. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  2320. end;
  2321. Procedure FD_Set(fd:longint;var fds:fdSet);
  2322. {
  2323. Add fd to the set of filedescriptors
  2324. }
  2325. begin
  2326. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  2327. end;
  2328. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  2329. {
  2330. Test if fd is part of the set of filedescriptors
  2331. }
  2332. begin
  2333. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  2334. end;
  2335. Function GetFS (var T:Text):longint;
  2336. {
  2337. Get File Descriptor of a text file.
  2338. }
  2339. begin
  2340. if textrec(t).mode=fmclosed then
  2341. exit(-1)
  2342. else
  2343. GETFS:=textrec(t).Handle
  2344. end;
  2345. Function GetFS(Var F:File):longint;
  2346. {
  2347. Get File Descriptor of an unTyped file.
  2348. }
  2349. begin
  2350. { Handle and mode are on the same place in textrec and filerec. }
  2351. if filerec(f).mode=fmclosed then
  2352. exit(-1)
  2353. else
  2354. GETFS:=filerec(f).Handle
  2355. end;
  2356. {--------------------------------
  2357. Stat.Mode Macro's
  2358. --------------------------------}
  2359. Function S_ISLNK(m:word):boolean;
  2360. {
  2361. Check mode field of inode for link.
  2362. }
  2363. begin
  2364. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  2365. end;
  2366. Function S_ISREG(m:word):boolean;
  2367. {
  2368. Check mode field of inode for regular file.
  2369. }
  2370. begin
  2371. S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
  2372. end;
  2373. Function S_ISDIR(m:word):boolean;
  2374. {
  2375. Check mode field of inode for directory.
  2376. }
  2377. begin
  2378. S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
  2379. end;
  2380. Function S_ISCHR(m:word):boolean;
  2381. {
  2382. Check mode field of inode for character device.
  2383. }
  2384. begin
  2385. S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
  2386. end;
  2387. Function S_ISBLK(m:word):boolean;
  2388. {
  2389. Check mode field of inode for block device.
  2390. }
  2391. begin
  2392. S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
  2393. end;
  2394. Function S_ISFIFO(m:word):boolean;
  2395. {
  2396. Check mode field of inode for named pipe (FIFO).
  2397. }
  2398. begin
  2399. S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
  2400. end;
  2401. Function S_ISSOCK(m:word):boolean;
  2402. {
  2403. Check mode field of inode for socket.
  2404. }
  2405. begin
  2406. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  2407. end;
  2408. {--------------------------------
  2409. Memory functions
  2410. --------------------------------}
  2411. Initialization
  2412. InitLocalTime;
  2413. finalization
  2414. DoneLocalTime;
  2415. End.
  2416. {
  2417. $Log$
  2418. Revision 1.6 2000-09-11 14:05:31 marco
  2419. * FreeBSD support and removed old signalhandling
  2420. Revision 1.5 2000/09/06 20:47:34 peter
  2421. * removed previous fsplit() patch as it's not the correct behaviour for
  2422. LFNs. The code showing the bug could easily be adapted (merged)
  2423. Revision 1.4 2000/09/04 20:17:53 peter
  2424. * fixed previous commit (merged)
  2425. Revision 1.3 2000/09/04 19:38:13 peter
  2426. * fsplit with .. fix from Thomas (merged)
  2427. Revision 1.2 2000/07/13 11:33:48 michael
  2428. + removed logs
  2429. }