linux.tex 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The LINUX unit.}
  22. This chapter describes the LINUX unit for Free Pascal. The unit was written
  23. by Micha\"el van Canneyt. It works only on the Linux operating system.
  24. This chapter is divided in 2 sections:
  25. \begin{itemize}
  26. \item The first section lists all constants, types and variables, as listed
  27. in the interface section of the LINUX unit.
  28. \item The second section describes all procedures and functions in the LINUX
  29. unit.
  30. \end{itemize}
  31. \section{Type, Variable and Constant declarations}
  32. \subsection{Types}
  33. \label{sec:types}
  34. PGlob and TGlob are 2 types used in the \seef{Glob} function:
  35. \begin{verbatim}
  36. PGlob = ^TGlob;
  37. TGlob = record
  38. Name : PChar;
  39. Next : PGlob;
  40. end;
  41. \end{verbatim}
  42. The following types are used in the signal-processing procedures.
  43. \begin{verbatim}
  44. {$Packrecords 1}
  45. SignalHandler = Procedure ( Sig : Integer);cdecl;
  46. PSignalHandler = SignalHandler;
  47. SignalRestorer = Procedure;cdecl;
  48. PSignalrestorer = SignalRestorer;
  49. SigActionRec = Record
  50. Sa_Handler : Signalhandler;
  51. Sa_Mask : Longint;
  52. Sa_flags : Integer;
  53. Sa_Restorer : SignalRestorer;
  54. end;
  55. PSigActionRec = ^SigActionRec;
  56. \end{verbatim}
  57. Stat is used to store information about a file. It is defined in the
  58. syscalls unit.
  59. \begin{verbatim}
  60. stat = record
  61. dev : word;
  62. pad1 : word;
  63. ino : longint;
  64. mode : word;
  65. nlink : word;
  66. uid : word;
  67. gid : word;
  68. rdev : word;
  69. pad2 : word;
  70. size : longint;
  71. blksze : Longint;
  72. blocks : Longint;
  73. atime : Longint;
  74. unused1 : longint;
  75. mtime : Longint;
  76. unused2 : longint;
  77. ctime : Longint;
  78. unused3 : longint;
  79. unused4 : longint;
  80. unused5 : longint;
  81. end;
  82. \end{verbatim}
  83. Statfs is used to store information about a filesystem. It is defined in
  84. the syscalls unit.
  85. \begin{verbatim}
  86. statfs = record
  87. fstype : longint;
  88. bsize : longint;
  89. blocks : longint;
  90. bfree : longint;
  91. bavail : longint;
  92. files : longint;
  93. ffree : longint;
  94. fsid : longint;
  95. namelen : longint;
  96. spare : array [0..6] of longint;
  97. end
  98. \end{verbatim}
  99. \var{Dir and PDir} are used in the \seef{OpenDir} and \seef{ReadDir}
  100. functions.
  101. \begin{verbatim}
  102. TDir =record
  103. fd : integer;
  104. loc : longint;
  105. size : integer;
  106. buf : pdirent;
  107. nextoff: longint;
  108. dd_max : integer;
  109. lock : pointer;
  110. end;
  111. PDir =^TDir;
  112. \end{verbatim}
  113. \var{Dirent, PDirent} are used in the \seef{ReadDir} function to return files in a directory.
  114. \begin{verbatim}
  115. PDirent = ^Dirent;
  116. Dirent = Record
  117. ino,
  118. off : longint;
  119. reclen : word;
  120. name : string[255]
  121. end;
  122. \end{verbatim}
  123. Termio and Termios are used with iotcl() calls for terminal handling.
  124. \begin{verbatim}
  125. Const NCCS = 19;
  126. NCC = 8;
  127. Type termio = record
  128. c_iflag, { input mode flags }
  129. c_oflag, { output mode flags }
  130. c_cflag, { control mode flags }
  131. c_lflag : Word; { local mode flags }
  132. c_line : Word; { line discipline - careful, only High byte in use}
  133. c_cc : array [0..NCC-1] of char; { control characters }
  134. end;
  135. termios = record
  136. c_iflag, { input mode flags }
  137. c_oflag, { output mode flags }
  138. c_cflag, { control mode flags }
  139. c_lflag : Cardinal; { local mode flags }
  140. c_line : char; { line discipline }
  141. c_cc : array [0..NCCS-1] of char; { control characters }
  142. end;
  143. \end{verbatim}
  144. \var{Utimbuf} is used in the \seef{Utime} call to set access and modificaton time
  145. of a file.
  146. \begin{verbatim}
  147. utimbuf = record
  148. actime,modtime : Longint;
  149. end;
  150. \end{verbatim}
  151. For the \seef{Select} call, the following 4 types are needed:
  152. \begin{verbatim}
  153. FDSet = Array [0..31] of longint;
  154. PFDSet = ^FDSet;
  155. TimeVal = Record
  156. sec,usec : Longint;
  157. end;
  158. PTimeVal = ^TimeVal;
  159. \end{verbatim}
  160. The \seep{Uname} function uses the \var{utsname} to return information about
  161. the current kernel :
  162. \begin{verbatim}
  163. utsname =record
  164. sysname,nodename,release,
  165. version,machine,domainname : Array[0..64] of char;
  166. end;
  167. \end{verbatim}
  168. Its elements are null-terminated C style strings, you cannot access them
  169. directly !
  170. \subsection{Variables}
  171. \var{Linuxerror} is the variable in which the procedures in the linux unit
  172. report errors.
  173. \begin{verbatim}
  174. LinuxError : Longint;
  175. \end{verbatim}
  176. \var{StdErr} Is a \var{Text} variable, corresponding to Standard Error or
  177. diagnostic output. It is connected to file descriptor 2. It can be freely
  178. used, and will be closed on exit.
  179. \begin{verbatim}
  180. StdErr : Text;
  181. \end{verbatim}
  182. \subsection{Constants}
  183. Constants for setting/getting process priorities :
  184. \begin{verbatim}
  185. Prio_Process = 0;
  186. Prio_PGrp = 1;
  187. Prio_User = 2;
  188. \end{verbatim}
  189. For testing access rights:
  190. \begin{verbatim}
  191. R_OK = 4;
  192. W_OK = 2;
  193. X_OK = 1;
  194. F_OK = 0;
  195. \end{verbatim}
  196. For signal handling functions :
  197. \begin{verbatim}
  198. SA_NOCLDSTOP = 1;
  199. SA_SHIRQ = $04000000;
  200. SA_STACK = $08000000;
  201. SA_RESTART = $10000000;
  202. SA_INTERRUPT = $20000000;
  203. SA_NOMASK = $40000000;
  204. SA_ONESHOT = $80000000;
  205. SIG_BLOCK = 0;
  206. SIG_UNBLOCK = 1;
  207. SIG_SETMASK = 2;
  208. SIG_DFL = 0 ;
  209. SIG_IGN = 1 ;
  210. SIG_ERR = -1;
  211. SIGHUP = 1;
  212. SIGINT = 2;
  213. SIGQUIT = 3;
  214. SIGILL = 4;
  215. SIGTRAP = 5;
  216. SIGABRT = 6;
  217. SIGIOT = 6;
  218. SIGBUS = 7;
  219. SIGFPE = 8;
  220. SIGKILL = 9;
  221. SIGUSR1 = 10;
  222. SIGSEGV = 11;
  223. SIGUSR2 = 12;
  224. SIGPIPE = 13;
  225. SIGALRM = 14;
  226. SIGTERM = 15;
  227. SIGSTKFLT = 16;
  228. SIGCHLD = 17;
  229. SIGCONT = 18;
  230. SIGSTOP = 19;
  231. SIGTSTP = 20;
  232. SIGTTIN = 21;
  233. SIGTTOU = 22;
  234. SIGURG = 23;
  235. SIGXCPU = 24;
  236. SIGXFSZ = 25;
  237. SIGVTALRM = 26;
  238. SIGPROF = 27;
  239. SIGWINCH = 28;
  240. SIGIO = 29;
  241. SIGPOLL = SIGIO;
  242. SIGPWR = 30;
  243. SIGUNUSED = 31;
  244. \end{verbatim}
  245. For file control mechanism :
  246. \begin{verbatim}
  247. F_GetFd = 1;
  248. F_SetFd = 2;
  249. F_GetFl = 3;
  250. F_SetFl = 4;
  251. F_GetLk = 5;
  252. F_SetLk = 6;
  253. F_SetLkW = 7;
  254. F_GetOwn = 8;
  255. F_SetOwn = 9;
  256. \end{verbatim}
  257. For Terminal handling :
  258. \begin{verbatim}
  259. TCGETS = $5401 ;
  260. TCSETS = $5402 ;
  261. TCSETSW = $5403 ;
  262. TCSETSF = $5404 ;
  263. TCGETA = $5405 ;
  264. TCSETA = $5406 ;
  265. TCSETAW = $5407 ;
  266. TCSETAF = $5408 ;
  267. TCSBRK = $5409 ;
  268. TCXONC = $540A ;
  269. TCFLSH = $540B ;
  270. TIOCEXCL = $540C ;
  271. TIOCNXCL = $540D ;
  272. TIOCSCTTY = $540E ;
  273. TIOCGPGRP = $540F ;
  274. TIOCSPGRP = $5410 ;
  275. TIOCOUTQ = $5411 ;
  276. TIOCSTI = $5412 ;
  277. TIOCGWINSZ = $5413 ;
  278. TIOCSWINSZ = $5414 ;
  279. TIOCMGET = $5415 ;
  280. TIOCMBIS = $5416 ;
  281. TIOCMBIC = $5417 ;
  282. TIOCMSET = $5418 ;
  283. TIOCGSOFTCAR = $5419 ;
  284. TIOCSSOFTCAR = $541A ;
  285. FIONREAD = $541B ;
  286. TIOCINQ = FIONREAD;
  287. TIOCLINUX = $541C ;
  288. TIOCCONS = $541D ;
  289. TIOCGSERIAL = $541E ;
  290. TIOCSSERIAL = $541F ;
  291. TIOCPKT = $5420 ;
  292. FIONBIO = $5421 ;
  293. TIOCNOTTY = $5422 ;
  294. TIOCSETD = $5423 ;
  295. TIOCGETD = $5424 ;
  296. TCSBRKP = $5425 ;
  297. TIOCTTYGSTRUCT = $5426 ;
  298. FIONCLEX = $5450 ;
  299. FIOCLEX = $5451 ;
  300. FIOASYNC = $5452 ;
  301. TIOCSERCONFIG = $5453 ;
  302. TIOCSERGWILD = $5454 ;
  303. TIOCSERSWILD = $5455 ;
  304. TIOCGLCKTRMIOS = $5456 ;
  305. TIOCSLCKTRMIOS = $5457 ;
  306. TIOCSERGSTRUCT = $5458 ;
  307. TIOCSERGETLSR = $5459 ;
  308. TIOCSERGETMULTI = $545A ;
  309. TIOCSERSETMULTI = $545B ;
  310. TIOCMIWAIT = $545C ;
  311. TIOCGICOUNT = $545D ;
  312. TIOCPKT_DATA = 0;
  313. TIOCPKT_FLUSHREAD = 1;
  314. TIOCPKT_FLUSHWRITE = 2;
  315. TIOCPKT_STOP = 4;
  316. TIOCPKT_START = 8;
  317. TIOCPKT_NOSTOP = 16;
  318. TIOCPKT_DOSTOP = 32;
  319. \end{verbatim}
  320. Other than that, all constants for setting the speed and control flags of a
  321. terminal line, as described in the \seem{termios}{2} man
  322. page, are defined in the linux unit. It would take too much place to list
  323. them here.
  324. To check the \var{mode} field of a \var{stat} record, you ca use the
  325. following constants :
  326. \begin{verbatim}
  327. { Constants to check stat.mode }
  328. STAT_IFMT = $f000; {00170000}
  329. STAT_IFSOCK = $c000; {0140000}
  330. STAT_IFLNK = $a000; {0120000}
  331. STAT_IFREG = $8000; {0100000}
  332. STAT_IFBLK = $6000; {0060000}
  333. STAT_IFDIR = $4000; {0040000}
  334. STAT_IFCHR = $2000; {0020000}
  335. STAT_IFIFO = $1000; {0010000}
  336. STAT_ISUID = $0800; {0004000}
  337. STAT_ISGID = $0400; {0002000}
  338. STAT_ISVTX = $0200; {0001000}
  339. { Constants to check permissions }
  340. STAT_IRWXO = $7;
  341. STAT_IROTH = $4;
  342. STAT_IWOTH = $2;
  343. STAT_IXOTH = $1;
  344. STAT_IRWXG = STAT_IRWXO shl 3;
  345. STAT_IRGRP = STAT_IROTH shl 3;
  346. STAT_IWGRP = STAT_IWOTH shl 3;
  347. STAT_IXGRP = STAT_IXOTH shl 3;
  348. STAT_IRWXU = STAT_IRWXO shl 6;
  349. STAT_IRUSR = STAT_IROTH shl 6;
  350. STAT_IWUSR = STAT_IWOTH shl 6;
  351. STAT_IXUSR = STAT_IXOTH shl 6;
  352. \end{verbatim}
  353. You can test the type of a filesystem returned by a \seef{FSStat} call with
  354. the following constants:
  355. \begin{verbatim}
  356. fs_old_ext2 = $ef51;
  357. fs_ext2 = $ef53;
  358. fs_ext = $137d;
  359. fs_iso = $9660;
  360. fs_minix = $137f;
  361. fs_minix_30 = $138f;
  362. fs_minux_V2 = $2468;
  363. fs_msdos = $4d44;
  364. fs_nfs = $6969;
  365. fs_proc = $9fa0;
  366. fs_xia = $012FD16D;
  367. \end{verbatim}
  368. the \seep{FLock} call uses the following mode constants :
  369. \begin{verbatim}
  370. LOCK_SH = 1;
  371. LOCK_EX = 2;
  372. LOCK_UN = 8;
  373. LOCK_NB = 4;
  374. \end{verbatim}
  375. \section{Functions and procedures}
  376. %\function{Name}{arguments}{return type}{explain}{errors}{refs}
  377. %\procedure{Name}{arguments}{explain}{errors}{refs}
  378. %\function{}{()}{}{}{}{}{}
  379. %\procedure{}{}{}{}{}{}
  380. \function{Access}{(Path : Pathstr; Mode : integer)}{Boolean}
  381. {
  382. Tests user's access rights on the specified file. Mode is a mask existing of
  383. one or more of
  384. \begin{description}
  385. \item[R\_OK] User has read rights.
  386. \item[W\_OK] User has write rights.
  387. \item[X\_OK] User has execute rights.
  388. \item[F\_OK] User has search rights in the directory where the file is.
  389. \end{description}
  390. The test is done with the real user ID, instead of the effective user ID.
  391. If access is denied, or an error occurred, false is returned.
  392. }
  393. { \var{LinuxError} is used to report errors:
  394. \begin{description}
  395. \item[sys\_eaccess] The requested access is denied, either to the file or one
  396. of the directories in its path.
  397. \item[sys\_einval] \var{Mode} was incorrect.
  398. \item[sys\_enoent] A directory component in \var{Path} doesn't exist or is a
  399. dangling symbolic link.
  400. \item[sys\_enotdir] A directory component in \var{Path} is not a directory.
  401. \item[sys\_enomem] Insufficient kernel memory.
  402. \item[sys\_eloop] \var{Path} has a circular symbolic link.
  403. \end{description}
  404. }
  405. {\seef{Chown}, \seef{Chmod}, \seem{Access}{2} }
  406. \latex{\inputlisting{linuxex/ex26.pp}}
  407. \html{\input{linuxex/ex26.tex}}
  408. \procedure{AssignPipe}{(Pipe\_in, Pipe\_out : Text)}
  409. {\var{AssignePipe} creates a pipe, i.e. two file objects, one for input, one for output.
  410. What is written to \var{Pipe\_out}, can be read from \var{Pipe\_in}.
  411. Reading and writing happens through the usual \var{Readln(Pipe\_in,...)} and
  412. \var{Writeln (Pipe\_out,...)} procedures.
  413. }
  414. { \var{LinuxError} is used to report errors:
  415. \begin{description}
  416. \item[sys\_emfile] Too many file descriptors for this process.
  417. \item[sys\_enfile] The system file table is full.
  418. \end{description}
  419. }
  420. {\seep{POpen}, \seef{MkFifo}, \seem{pipe}{2}}
  421. \latex{\inputlisting{linuxex/ex36.pp}}
  422. \html{\input{linuxex/ex36.tex}}
  423. \procedure{AssignStream}{(StreamIn,StreamOut : Text; Const prog : String)}
  424. {\var{AssignStream} creates a 2 pipes, i.e. two file objects, one for input, one for
  425. output, the other ends of these pipes are connected to standard input and and
  426. output of \var{Prog}. \var{Prog} is the name of a program (including path)
  427. with options, which will be executed.
  428. What is written to \var{StreamOut}, will go to the standard input of
  429. \var{Prog}. Whatever is written by \var{Prog} to it's standard output be read from
  430. \var{StreamIn}.
  431. Reading and writing happens through the usual \var{Readln(StreamIn,...)} and
  432. \var{Writeln (StreamOut,...)} procedures.
  433. }
  434. { \var{LinuxError} is used to report errors:
  435. \begin{description}
  436. \item[sys\_emfile] Too many file descriptors for this process.
  437. \item[sys\_enfile] The system file table is full.
  438. \end{description}
  439. Other errors include the ones by the fork and exec programs
  440. }
  441. {\seep{AssignPipe}, \seep{POpen},\seem{pipe}{2}}
  442. \latex{\inputlisting{linuxex/ex38.pp}}
  443. \html{\input{linuxex/ex38.tex}}
  444. \function{BaseName}{(Const Path;Suf : Pathstr)}{Pathstr}
  445. {Returns the filename part of \var{Path}, stripping off \var{Suf} if it
  446. exists.
  447. The filename part is the whole name if \var{Path} contains no slash,
  448. or the part of \var{Path} after the last slash.
  449. The last character of the result is not a slash, unless the directory is the
  450. root directory.
  451. }
  452. {None.}
  453. {\seef{DirName}, \seef{FExpand}, \seem{Basename}{1}}
  454. \latex{\inputlisting{linuxex/ex48.pp}}
  455. \html{\input{linuxex/ex48.tex}}
  456. \procedure{CFMakeRaw}{(var Tios:TermIOS)}
  457. { \var{CFMakeRaw}
  458. Sets the flags in the \var{Termios} structure \var{Tios} to a state so that
  459. the terminal will function in Raw Mode.
  460. }
  461. {None.}
  462. { \seep{CFSetOSpeed}, \seep{CFSetISpeed}, \seem{termios}{2}}
  463. For an example, see \seef{TCGetAttr}.
  464. \procedure{CFSetISpeed}{(var Tios:TermIOS;Speed:Longint)}
  465. { \var{CFSetISpeed}
  466. Sets the input baudrate in the \var{TermIOS} structure \var{Tios} to
  467. \var{Speed}.
  468. }
  469. {None.}
  470. {\seep{CFSetOSpeed}, \seep{CFMakeRaw}, \seem{termios}{2}}
  471. \procedure{CFSetOSpeed}{(var Tios:TermIOS;Speed:Longint)}
  472. { \var{CFSetOSpeed}
  473. Sets the output baudrate in the \var{Termios} structure \var{Tios} to
  474. \var{Speed}.
  475. }
  476. {None.}
  477. {\seep{CFSetISpeed}, \seep{CFMakeRaw}, \seem{termios}{2}}
  478. \function{Chown}{(Path : Pathstr;NewUid,NewGid : Longint)}{Boolean}
  479. { \var{Chown} sets the User ID and Group ID of the file in \var{Path} to \var{NewUid,
  480. NewGid}.
  481. The function returns \var{True} if the call was succesfull, \var{False} if the call
  482. failed.
  483. }
  484. {
  485. Errors are returned in \var{LinuxError}.
  486. \begin{description}
  487. \item[sys\_eperm] The effective UID doesn't match the ownership of the file,
  488. and is not zero. Owner or group were not specified correctly.
  489. \item[sys\_eaccess] One of the directories in \var{Path} has no
  490. search (=execute) permission.
  491. \item[sys\_enoent] A directory entry in \var{Path} does
  492. not exist or is a symbolic link pointing to a non-existent directory.
  493. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  494. nor a directory.
  495. \item[sys\_enomem] Insufficient kernel memory.
  496. \item[sys\_erofs] The file is on a read-only filesystem.
  497. \item[sys\_eloop] \var{Path} has a reference to a circular
  498. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  499. \end{description}
  500. }
  501. {\seef{Chmod}, \seef{Access}, \seem{Chown}(2)}
  502. \latex{\inputlisting{linuxex/ex24.pp}}
  503. \html{\input{linuxex/ex24.tex}}
  504. \function{Chmod}{(Path : Pathstr;NewMode : Longint)}{Boolean}
  505. { \var{Chmod}
  506. Sets the Mode bits of the file in \var{Path} to \var{NewMode}. Newmode can be
  507. specified by 'or'-ing the following:
  508. \begin{description}
  509. \item[S\_ISUID] Set user ID on execution.
  510. \item[S\_ISGID] Set Group ID on execution.
  511. \item[S\_ISVTX] Set sticky bit.
  512. \item[S\_IRUSR] Read by owner.
  513. \item[S\_IWUSR] Write by owner.
  514. \item[S\_IXUSR] Execute by owner.
  515. \item[S\_IRGRP] Read by group.
  516. \item[S\_IWGRP] Write by group.
  517. \item[S\_IXGRP] Execute by group.
  518. \item[S\_IROTH] Read by others.
  519. \item[S\_IWOTH] Write by others.
  520. \item[S\_IXOTH] Execute by others.
  521. \item[S\_IRWXO] Read, write, execute by others.
  522. \item[S\_IRWXG] Read, write, execute by groups.
  523. \item[S\_IRWXU] Read, write, execute by user.
  524. \end{description}
  525. }
  526. {
  527. Errors are returned in \var{LinuxError}.
  528. \begin{description}
  529. \item[sys\_eperm] The effective UID doesn't match the ownership of the file,
  530. and is not zero. Owner or group were not specified correctly.
  531. \item[sys\_eaccess] One of the directories in \var{Path} has no
  532. search (=execute) permission.
  533. \item[sys\_enoent] A directory entry in \var{Path} does
  534. not exist or is a symbolic link pointing to a non-existent directory.
  535. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  536. nor a directory.
  537. \item[sys\_enomem] Insufficient kernel memory.
  538. \item[sys\_erofs] The file is on a read-only filesystem.
  539. \item[sys\_eloop] \var{Path} has a reference to a circular
  540. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  541. \end{description}
  542. }
  543. {\seef{Chown}, \seef{Access}, \seem{Chmod}(2)}
  544. \latex{\inputlisting{linuxex/ex23.pp}}
  545. \html{\input{linuxex/ex23.tex}}
  546. \function{CloseDir}{(p:pdir)}{integer}
  547. { \var{CloseDir} closes the directory pointed to by \var{p}.
  548. It returns zero if the directory was closed succesfully, -1 otherwise.}
  549. {Errors are returned in LinuxError.}
  550. {\seef{OpenDir}, \seef{ReadDir}, \seep{SeekDir}, \seef{TellDir},
  551. \seem{closedir}{3}}
  552. For an example, see \seef{OpenDir}.
  553. \function{DirName}{(Const Path : Pathstr)}{Pathstr}
  554. {Returns the directory part of \var{Path}.
  555. The directory is the part of \var{Path} before the last slash,
  556. or empty if there is no slash.
  557. The last character of the result is not a slash, unless the directory is the
  558. root directory.
  559. }
  560. {None.}
  561. {\seef{BaseName}, \seef{FExpand}, \seem{Dirname}{1}}
  562. \latex{\inputlisting{linuxex/ex47.pp}}
  563. \html{\input{linuxex/ex47.tex}}
  564. \procedure{Dup}{(Var OldFile, NewFile : Text)}
  565. {
  566. Makes \var{NewFile} an exact copy of \var{OldFile}, after having flushed the
  567. buffer of \var{OldFile}. Due to the buffering mechanism of Pascal, this has not
  568. the same functionality as the \seem{dup}{2} call in C. The internal Pascal
  569. buffers are not the same after this call, but when the buffers are flushed
  570. (e.g. after output), the output is sent to the same file.
  571. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the
  572. fileposition in both files.
  573. }
  574. { \var{Linuxerror} is used to report errors.
  575. \begin{description}
  576. \item[sys\_ebadf] \var{OldFile} hasn't been assigned.
  577. \item[sys\_emfile] Maximum number of open files for the process is reached.
  578. \end{description}
  579. }
  580. {\seep{Dup2}, \seem{Dup}{2} }
  581. \latex{\inputlisting{linuxex/ex31.pp}}
  582. \html{\input{linuxex/ex31.tex}}
  583. \procedure{Dup2}{(Var OldFile, NewFile : Text)}
  584. {
  585. Makes \var{NewFile} an exact copy of \var{OldFile}, after having flushed the
  586. buffer of \var{OldFile}. \var{NewFile} can be an assigned file.
  587. If \var{newfile} was open, it is closed first.
  588. Due to the buffering mechanism of Pascal, this has not
  589. the same functionality as the \seem{dup2}{2} call in C. The internal Pascal
  590. buffers are not the same after this call, but when the buffers are flushed
  591. (e.g. after output), the output is sent to the same file.
  592. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the
  593. fileposition in both files.
  594. }
  595. { \var{Linuxerror} is used to report errors.
  596. \begin{description}
  597. \item[sys\_ebadf] \var{OldFile} hasn't been assigned.
  598. \item[sys\_emfile] Maximum number of open files for the process is reached.
  599. \end{description}
  600. }
  601. { \seep{Dup}, \seem{Dup2}{2} }
  602. \latex{\inputlisting{linuxex/ex32.pp}}
  603. \html{\input{linuxex/ex32.tex}}
  604. \procedure{EpochToLocal}
  605. {(Epoch : Longint; var Year,Month,Day,Hour,Minute,Second : Word)}
  606. {
  607. Converts the epoch time (=Number of seconds since 00:00:00 , January 1,
  608. 1970, corrected for your time zone ) to local date and time.
  609. }
  610. {None}
  611. {\seef{GetEpochTime}, \seef{LocalToEpoch}, \seep{GetTime},\seep{GetDate} }
  612. \latex{\inputlisting{linuxex/ex3.pp}}
  613. \html{\input{linuxex/ex3.tex}}
  614. \procedure{Execl}
  615. {(Path : pathstr)}
  616. {
  617. Replaces the currently running program with the program, specified in
  618. \var{path}. Path is split into a command and it's options.
  619. The executable in \var{path} is NOT searched in the path.
  620. The current environment is passed to the program.
  621. On success, \var{execl} does not return.
  622. }
  623. {Errors are reported in \var{LinuxError}:
  624. \begin{description}
  625. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  626. A compononent of the path has no search permission.
  627. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  628. \item[sys\_e2big] Argument list too big.
  629. \item[sys\_enoexec] The magic number in the file is incorrect.
  630. \item[sys\_enoent] The file does not exist.
  631. \item[sys\_enomem] Not enough memory for kernel, or to split command line.
  632. \item[sys\_enotdir] A component of the path is not a directory.
  633. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  634. \end{description}}
  635. {\seep{Execve}, \seep{Execv}, \seep{Execvp}, \seep{Execle},
  636. \seep{Execlp}, \seef {Fork}, \seem{execvp}{3} }
  637. \latex{\inputlisting{linuxex/ex10.pp}}
  638. \html{\input{linuxex/ex10.tex}}
  639. \procedure{Execle}
  640. {(Path : pathstr, Ep : ppchar)}
  641. {
  642. Replaces the currently running program with the program, specified in
  643. \var{path}. Path is split into a command and it's options.
  644. The executable in \var{path} is searched in the path, if it isn't
  645. an absolute filename.
  646. The environment in \var{ep} is passed to the program.
  647. On success, \var{execle} does not return.
  648. }
  649. {Errors are reported in \var{LinuxError}:
  650. \begin{description}
  651. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  652. A compononent of the path has no search permission.
  653. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  654. \item[sys\_e2big] Argument list too big.
  655. \item[sys\_enoexec] The magic number in the file is incorrect.
  656. \item[sys\_enoent] The file does not exist.
  657. \item[sys\_enomem] Not enough memory for kernel, or to split command line.
  658. \item[sys\_enotdir] A component of the path is not a directory.
  659. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  660. \end{description}}
  661. {\seep{Execve}, \seep{Execv}, \seep{Execvp},
  662. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execvp}{3} }
  663. \latex{\inputlisting{linuxex/ex11.pp}}
  664. \html{\input{linuxex/ex11.tex}}
  665. \procedure{Execlp}
  666. {(Path : pathstr)}
  667. {
  668. Replaces the currently running program with the program, specified in
  669. \var{path}. Path is split into a command and it's options.
  670. The executable in \var{path} is searched in the path, if it isn't
  671. an absolute filename.
  672. The current environment is passed to the program.
  673. On success, \var{execlp} does not return.
  674. }
  675. {Errors are reported in \var{LinuxError}:
  676. \begin{description}
  677. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  678. A compononent of the path has no search permission.
  679. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  680. \item[sys\_e2big] Argument list too big.
  681. \item[sys\_enoexec] The magic number in the file is incorrect.
  682. \item[sys\_enoent] The file does not exist.
  683. \item[sys\_enomem] Not enough memory for kernel, or to split command line.
  684. \item[sys\_enotdir] A component of the path is not a directory.
  685. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  686. \end{description}}
  687. {\seep{Execve}, \seep{Execv}, \seep{Execvp}, \seep{Execle},
  688. \seep{Execl}, \seef {Fork}, \seem{execvp}{3} }
  689. \latex{\inputlisting{linuxex/ex12.pp}}
  690. \html{\input{linuxex/ex12.tex}}
  691. \procedure{Execv}
  692. {(Path : pathstr; args : ppchar)}
  693. {
  694. Replaces the currently running program with the program, specified in
  695. \var{path}.
  696. It gives the program the options in \var{args}.
  697. This is a pointer to an array of pointers to null-terminated
  698. strings. The last pointer in this array should be nil.
  699. The current environment is passed to the program.
  700. On success, \var{execv} does not return.
  701. }
  702. {Errors are reported in \var{LinuxError}:
  703. \begin{description}
  704. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  705. A compononent of the path has no search permission.
  706. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  707. \item[sys\_e2big] Argument list too big.
  708. \item[sys\_enoexec] The magic number in the file is incorrect.
  709. \item[sys\_enoent] The file does not exist.
  710. \item[sys\_enomem] Not enough memory for kernel.
  711. \item[sys\_enotdir] A component of the path is not a directory.
  712. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  713. \end{description}}
  714. {\seep{Execve}, \seep{Execvp}, \seep{Execle},
  715. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execv}{3} }
  716. \latex{\inputlisting{linuxex/ex8.pp}}
  717. \html{\input{linuxex/ex8.tex}}
  718. \procedure{Execve}
  719. {(Path : pathstr; args,ep : ppchar)}
  720. {
  721. Replaces the currently running program with the program, specified in
  722. \var{path}.
  723. It gives the program the options in \var{args}, and the environment in
  724. \var{ep}. They are pointers to an array of pointers to null-terminated
  725. strings. The last pointer in this array should be nil.
  726. On success, \var{execve} does not return.
  727. }
  728. {Errors are reported in \var{LinuxError}:
  729. \begin{description}
  730. \item[eacces] File is not a regular file, or has no execute permission.
  731. A compononent of the path has no search permission.
  732. \item[sys\_ eperm] The file system is mounted \textit{noexec}.
  733. \item[sys\_ e2big] Argument list too big.
  734. \item[sys\_ enoexec] The magic number in the file is incorrect.
  735. \item[sys\_ enoent] The file does not exist.
  736. \item[sys\_ enomem] Not enough memory for kernel.
  737. \item[sys\_ enotdir] A component of the path is not a directory.
  738. \item[sys\_ eloop] The path contains a circular reference (via symlinks).
  739. \end{description}}
  740. {\seep{Execve}, \seep{Execv}, \seep{Execvp} \seep{Execle},
  741. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execve}{2} }
  742. \latex{\inputlisting{linuxex/ex7.pp}}
  743. \html{\input{linuxex/ex7.tex}}
  744. \procedure{Execvp}
  745. {(Path : pathstr; args : ppchar)}
  746. {
  747. Replaces the currently running program with the program, specified in
  748. \var{path}. The executable in \var{path} is searched in the path, if it isn't
  749. an absolute filename.
  750. It gives the program the options in \var{args}. This is a pointer to an array of pointers to null-terminated
  751. strings. The last pointer in this array should be nil.
  752. The current environment is passed to the program.
  753. On success, \var{execvp} does not return.
  754. }
  755. {Errors are reported in \var{LinuxError}:
  756. \begin{description}
  757. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  758. A compononent of the path has no search permission.
  759. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  760. \item[sys\_e2big] Argument list too big.
  761. \item[sys\_enoexec] The magic number in the file is incorrect.
  762. \item[sys\_enoent] The file does not exist.
  763. \item[sys\_enomem] Not enough memory for kernel.
  764. \item[sys\_enotdir] A component of the path is not a directory.
  765. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  766. \end{description}}
  767. {\seep{Execve}, \seep{Execv}, \seep{Execle},
  768. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execvp}{3} }
  769. \latex{\inputlisting{linuxex/ex9.pp}}
  770. \html{\input{linuxex/ex9.tex}}
  771. \procedurel{FD\_Clear}{FDClear}{(var fds:fdSet)}
  772. {\var{FD\_Clear} clears all the filedescriptors in the file descriptor
  773. set \var{fds}.}
  774. {None.}
  775. {\seef{Select},
  776. \seef{SelectText},
  777. \seef{GetFS},
  778. \seepl{FD\_Clr}{FDClr},
  779. \seepl{FD\_Set}{FDSet},
  780. \seefl{FD\_IsSet}{FDIsSet}
  781. }
  782. For an example, see \seef{Select}.
  783. \procedurel{FD\_Clr}{FDClr}{(fd:longint;var fds:fdSet)}
  784. { \var{FD\_Clr} clears file descriptor \var{fd} in filedescriptor s
  785. et \var{fds}.}
  786. {None.}
  787. {\seef{Select},
  788. \seef{SelectText},
  789. \seef{GetFS},
  790. \seepl{FD\_Clear}{FDClear},
  791. \seepl{FD\_Set}{FDSet},
  792. \seefl{FD\_IsSet}{FDIsSet}}
  793. For an example, see \seef{Select}.
  794. \functionl{FD\_IsSet}{FDIsSet}{(fd:longint;var fds:fdSet)}{boolean}
  795. {\var{FD\_Set} Checks whether file descriptor \var{fd} in filedescriptor set \var{fds}
  796. is set.}
  797. {None.}
  798. {\seef{Select}, \seef{SelectText}, \seef{GetFS},
  799. \seepl{FD\_Clear}{FDClear},
  800. \seepl{FD\_Clr}{FDClr},
  801. \seepl{FD\_Set}{FDSet}}
  802. For an example, see \seef{Select}.
  803. \procedurel{FD\_Set}{FDSet}{(fd:longint;var fds:fdSet)}
  804. {\var{FD\_Set} sets file descriptor \var{fd} in filedescriptor set \var{fds}.}
  805. {None.}
  806. {\seef{Select}, \seef{SelectText}, \seef{GetFS},\seepl{FD\_Clear}{FDClear},
  807. \seepl{FD\_Clr}{FDClr}, \seefl{FD\_IsSet}{FDIsSet}}
  808. For an example, see \seef{Select}.
  809. \function{fdClose}{(fd:longint)}{boolean}
  810. {
  811. \var{fdClose} closes a file with file descriptor \var{Fd}. The function
  812. returns \var{True} if the file was closed successfully, \var{False}
  813. otherwise.
  814. }
  815. {Errors are returned in LinuxError}
  816. {\seef{fdOpen}, \seef{fdRead}, \seef{fdWrite},\seef{fdTruncate},
  817. \seef{fdFlush}, seef{FdSeek}}
  818. For an example, see \seef{fdOpen}.
  819. \function{fdFlush}{(fd:Longint)}{boolean}
  820. {\var{fdflush} flushes the Linux kernel file buffer, so the file is actually
  821. written to disk. This is NOT the same as the internal buffer, maintained by
  822. Free Pascal.
  823. The function returns \var{True} if the call was successful, \var{false} if
  824. an error occurred.}
  825. {Errors are returned in LinuxError.}
  826. {\seef{fdOpen}, \seef{fdClose}, \seef{fdRead},\seef{fdWrite},
  827. \seef{fdTruncate}, \seef{fdSeek}}
  828. For an example, see \seef{fdRead}.
  829. \function{fdOpen}{(Var PathName;flags:longint[; Mode: longint])}{longint}
  830. { \var{fdOpen} opens a file in \var{pathname} with flags \var{flags} a ORed combination of
  831. \var{Open\_Accmode, Open\_RdOnly, Open\_WrOnly, Open\_RdWr, Open\_Creat,
  832. Open\_Excl, Open\_NoCtty, Open\_Trunc, Open\_Append, Open\_NonBlock,
  833. Open\_NDelay, Open\_Sync} \var{PathName} can be of type \var{PChar} or
  834. \var{String}
  835. The optional \var{mode} argument specifies the permissions to set when opening
  836. the file. This is modified by the umask setting. The real permissions are
  837. \var{Mode and not umask}.
  838. The return value of the function is the filedescriptor, or a negative
  839. value if there was an error.
  840. }
  841. {Errors are returned in LinuxError}
  842. {\seef{fdClose}, \seef{fdRead}, \seef{fdWrite},\seef{fdTruncate},
  843. \seef{fdFlush}, \seef{fdSeek}}
  844. \latex{\inputlisting{linuxex/ex19.pp}}
  845. \html{\input{linuxex/ex19.tex}}
  846. \function{fdRead}{(fd:longint;var buf;size:longint}{longint}
  847. { \var{fdRead} reads at most \var{size} bytes from the file descriptor
  848. \var{fd}, and stores them in \var{buf}.
  849. The function returns the number of bytes actually read, or -1 if
  850. an error occurred.
  851. No checking on the length of \var{buf} is done.
  852. }
  853. {Errors are returned in LinuxError.}
  854. {\seef{fdOpen}, \seef{fdClose}, \seef{fdWrite},\seef{fdTruncate},
  855. \seef{fdFlush}, \seef{fdSeek}}
  856. \latex{\inputlisting{linuxex/ex20.pp}}
  857. \html{\input{linuxex/ex20.tex}}
  858. \function{fdSeek}{(fd,Pos,SeekType:longint}{longint}
  859. {\var{fdSeek} sets the current fileposition of file \var{fd} to
  860. \var{Pos}, starting from \var{SeekType}, which can be one of the following:
  861. \begin{description}
  862. \item [Seek\_Set] \ \var{Pos} is the absolute position in the file.
  863. \item [Seek\_Cur] \ \var{Pos} is relative to the current position.
  864. \item [Seek\_end] \ \var{Pos} is relative to the end of the file.
  865. \end{description}
  866. The function returns the new fileposition, or -1 of an error occurred.
  867. }
  868. {Errors are returned in LinuxError.}
  869. {\seef{fdOpen}, \seef{fdWrite}, \seef{fdClose},
  870. \seef{fdRead},\seef{fdTruncate},
  871. \seef{fdFlush}}
  872. For an example, see \seef{fdOpen}.
  873. \function{fdTruncate}{(fd,size:longint)}{boolean}
  874. {\var{fdTruncate} sets the length of a file in \var{fd} on \var{size}
  875. bytes, where \var{size} must be less than or equal to the current length of
  876. the file in \var{fd}.
  877. The function returns \var{True} if the call was successful, \var{false} if
  878. an error occurred.}
  879. {Errors are returned in LinuxError.}
  880. {\seef{fdOpen}, \seef{fdClose}, \seef{fdRead},\seef{fdWrite},\seef{fdFlush},
  881. \seef{fdSeek}}
  882. \function{fdWrite}{(fd:longint;var buf;size:longint}{longint}
  883. {\var{fdWrite} writes at most \var{size} bytes from \var{buf} to
  884. file descriptor \var{fd}.
  885. The function returns the number of bytes actually written, or -1 if an error
  886. occurred.
  887. }
  888. {Errors are returned in LinuxError.}
  889. {\seef{fdOpen}, \seef{fdClose}, \seef{fdRead},\seef{fdTruncate},
  890. \seef{fdSeek}, \seef{fdFlush}}
  891. \function{FExpand}{(Const Path: Pathstr)}{pathstr}
  892. { Expands \var {Path} to a full path, starting from root,
  893. eliminating directory references such as . and .. from the result.
  894. }
  895. {None}
  896. {\seef{BaseName},\seef{DirName} }
  897. \latex{\inputlisting{linuxex/ex45.pp}}
  898. \html{\input{linuxex/ex45.tex}}
  899. \procedure{FLock}{(Var F; Mode : longint)}
  900. {\var{FLock} implements file locking. it sets or removes a lock on the file
  901. \var{F}. F can be of type \var{Text} or \var{File}, or it can be a \linux
  902. filedescriptor (a longint)
  903. \var{Mode} can be one of the following constants :
  904. \begin{description}
  905. \item [LOCK\_SH] \ sets a shared lock.
  906. \item [LOCK\_EX] \ sets an exclusive lock.
  907. \item [LOCK\_UN] \ unlocks the file.
  908. \item [LOCK\_NB] \ This can be OR-ed together with the other. If this is done
  909. the application doesn't block when locking.
  910. \end{description}
  911. }
  912. {Errors are reported in \var{LinuxError}.}
  913. {\seef{Fcntl}, \seem{flock}{2}}
  914. \function{FSStat}{(Path : Pathstr; Var Info : statfs)}{Boolean}
  915. { Return in \var{Info} information about the filesystem on which the file
  916. \var{Path} resides. Info is of type \var{statfs}.
  917. The function returns \var{True} if the call was succesfull, \var{False} if the call
  918. failed.
  919. }
  920. { \var{LinuxError} is used to report errors.
  921. \begin{description}
  922. \item[sys\_enotdir] A component of \var{Path} is not a directory.
  923. \item[sys\_einval] Invalid character in \var{Path}.
  924. \item[sys\_enoent] \var{Path} does not exist.
  925. \item[sys\_eaccess] Search permission is denied for component in
  926. \var{Path}.
  927. \item[sys\_eloop] A circular symbolic link was encountered in \var{Path}.
  928. \item[sys\_eio] An error occurred while reading from the filesystem.
  929. \end{description}
  930. }
  931. {\seef{FStat}, \seef{LStat}, \seem{statfs}{2}}
  932. \latex{\inputlisting{linuxex/ex30.pp}}
  933. \html{\input{linuxex/ex30.tex}}
  934. \function{FSearch}{(Path : pathstr;DirList : string)}{Pathstr}
  935. { Searches in \var{DirList}, a colon separated list of directories,
  936. for a file named \var{Path}. It then returns a path to the found file.}
  937. {An empty string if no such file was found.}
  938. {\seef{BaseName}, \seef{DirName}, \seef{FExpand} }
  939. \latex{\inputlisting{linuxex/ex46.pp}}
  940. \html{\input{linuxex/ex46.tex}}
  941. \function{FStat}{(Path : Pathstr; Var Info : stat)}{Boolean}
  942. {
  943. \var{FStat} gets information about the file specified in \var{Path}, and stores it in
  944. \var{Info}, which is of type \var{stat}.
  945. The function returns \var{True} if the call was succesfull, \var{False} if the call
  946. failed.
  947. }
  948. { \var{LinuxError} is used to report errors.
  949. \begin{description}
  950. \item[sys\_enoent] \var{Path} does not exist.
  951. \end{description}
  952. }
  953. {\seef{FSStat}, \seef{LStat}, \seem{stat}{2}}
  954. \latex{\inputlisting{linuxex/ex28.pp}}
  955. \html{\input{linuxex/ex28.tex}}
  956. \function{Fcntl}{(Fd : text, Cmd : Integer)}{Integer}
  957. {
  958. Read a file's attributes. \var{Fd} is an assigned file.
  959. \var{Cmd} speciefies what to do, and is one of the following:
  960. \begin{description}
  961. \item[F\_GetFd] Read the close\_on\_exec flag. If the low-order bit is 0, then
  962. the file will remain open across execve calls.
  963. \item[F\_GetFl] Read the descriptor's flags.
  964. \item[F\_GetOwn] Get the Process ID of the owner of a socket.
  965. \end{description}
  966. }
  967. {
  968. \var{LinuxError} is used to report errors.
  969. \begin{description}
  970. \item[sys\_ebadf] \var{Fd} has a bad file descriptor.
  971. \end{description}
  972. }
  973. {\seep{Fcntl}, \seem{Fcntl}{2} }
  974. \procedure{Fcntl}{(Fd : text, Cmd : Integer; Arg : longint)}
  975. {
  976. Read or Set a file's attributes. \var{Fd} is an assigned file.
  977. \var{Cmd} speciefies what to do, and is one of the following:
  978. \begin{description}
  979. \item[F\_SetFd] Set the close\_on\_exec flag of \var{Fd}. (only the least
  980. siginificant bit is used).
  981. \item[F\_GetLk] Return the \var{flock} record that prevents this process from
  982. obtaining the lock, or set the \var{l\_type} field of the lock of there is no
  983. obstruction. Arg is a pointer to a flock record.
  984. \item[F\_SetLk] Set the lock or clear it (depending on \var{l\_type} in the
  985. \var{flock} structure). if the lock is held by another process, an error
  986. occurs.
  987. \item[F\_GetLkw] Same as for \textbf{F\_Setlk}, but wait until the lock is
  988. released.
  989. \item[F\_SetOwn] Set the Process or process group that owns a socket.
  990. \end{description}
  991. }
  992. {
  993. \var{LinuxError} is used to report errors.
  994. \begin{description}
  995. \item[sys\_ebadf] \var{Fd} has a bad file descriptor.
  996. \item[sys\_eagain or sys\_eaccess] For \textbf{F\_SetLk}, if the lock is
  997. held by another process.
  998. \end{description}
  999. }
  1000. {\seef{Fcntl}, \seem{Fcntl}{2} }
  1001. \function{Fork}{}{Longint}
  1002. {
  1003. Fork creates a child process which is a copy of the parent process.
  1004. Fork returns the process ID in the parent process, and zero in the child's
  1005. process. (you can get the parent's PID with \seef{GetPPid}).
  1006. }
  1007. {On error, -1 is returned to the parent, and no child is created.
  1008. \begin{description}
  1009. \item [sys\_eagain] Not enough memory to create child process.
  1010. \end{description}
  1011. }
  1012. {\seep{Execve}, \seem{fork}{2}}
  1013. \latex{\inputlisting{linuxex/ex14.pp}}
  1014. \html{\input{linuxex/ex14.tex}}
  1015. \procedure{GetDate}
  1016. { (Var Year, Month, Day : Word) }
  1017. {
  1018. Returns the current day.
  1019. }
  1020. {None}
  1021. {\seef{GetEpochTime}, \seep{GetTime}, \seep{EpochToLocal} }
  1022. \latex{\inputlisting{linuxex/ex6.pp}}
  1023. \html{\input{linuxex/ex6.tex}}
  1024. \function{GetDomainName}{}{String}
  1025. {
  1026. Get the domain name of the machine on which the process is running.
  1027. An empty string is returned if the domain is not set.
  1028. }
  1029. {None.}
  1030. { \seef{GetHostName},seem{Getdomainname}{2} }
  1031. \latex{\inputlisting{linuxex/ex39.pp}}
  1032. \html{\input{linuxex/ex39.tex}}
  1033. \function{GetEGid}{}{Longint}
  1034. { Get the effective group ID of the currently running process.}
  1035. {None.}
  1036. {\seef{GetGid}, \seem{getegid}{2} }
  1037. \latex{\inputlisting{linuxex/ex18.pp}}
  1038. \html{\input{linuxex/ex18.tex}}
  1039. \function{GetEUid}{}{Longint}
  1040. { Get the effective user ID of the currently running process.}
  1041. {None.}
  1042. {\seef{GetEUid}, \seem{geteuid}{2} }
  1043. \latex{\inputlisting{linuxex/ex17.pp}}
  1044. \html{\input{linuxex/ex17.tex}}
  1045. \function{GetEnv}{(P : String)}{PChar}
  1046. {Returns the value of the environment variable in \var{P}. If the variable is
  1047. not defined, nil is returned. The value of the environment variable may be
  1048. the empty string.
  1049. A PChar is returned to accomodate for strings longer than 255 bytes,
  1050. \var{TERMCAP} and \var{LS\_COLORS}, for instance.
  1051. }
  1052. {None.}
  1053. {\seem{sh}{1}, \seem{csh}{1} }
  1054. \latex{\inputlisting{linuxex/ex41.pp}}
  1055. \html{\input{linuxex/ex41.tex}}
  1056. \function{GetEpochTime}{}{longint}
  1057. {
  1058. returns the number of seconds since 00:00:00 gmt, january 1, 1970.
  1059. it is adjusted to the local time zone, but not to DST.
  1060. }
  1061. {no errors}
  1062. {\seep{EpochToLocal}, \seep{GetTime}, \seem{time}{2}}
  1063. \latex{\inputlisting{linuxex/ex1.pp}}
  1064. \html{\input{linuxex/ex1.tex}}
  1065. \function{GetFS}{(Var F : Any File Type)}{Longint}
  1066. {\var{GetFS} returns the file selector that the kernel provided for your
  1067. file. In principle you don' need this file selector. Only for some calls
  1068. it is needed, such as the \seef{Select} call or so.}
  1069. {In case the file was not opened, then -1 is returned.}
  1070. {\seef{Select}}
  1071. \latex{\inputlisting{linuxex/ex34.pp}}
  1072. \html{\input{linuxex/ex34.tex}}
  1073. \function{GetGid}{}{Longint}
  1074. { Get the real group ID of the currently running process.}
  1075. {None.}
  1076. {\seef{GetEGid}, \seem{getgid}{2} }
  1077. \latex{\inputlisting{linuxex/ex18.pp}}
  1078. \html{\input{linuxex/ex18.tex}}
  1079. \function{GetHostName}{}{String}
  1080. {
  1081. Get the hostname of the machine on which the process is running.
  1082. An empty string is returned if hostname is not set.
  1083. }
  1084. {None.}
  1085. { \seef{GetDomainName},seem{Gethostname}{2} }
  1086. \latex{\inputlisting{linuxex/ex40.pp}}
  1087. \html{\input{linuxex/ex40.tex}}
  1088. \function{GetPid}{}{Longint}
  1089. { Get the Process ID of the currently running process.}
  1090. {None.}
  1091. {\seef{GetPPid}, \seem{getpid}{2}}
  1092. \latex{\inputlisting{linuxex/ex16.pp}}
  1093. \html{\input{linuxex/ex16.tex}}
  1094. \function{GetPPid}{}{Longint}
  1095. { Get the Process ID of the parent process.}
  1096. {None.}
  1097. {\seef{GetPid}, \seem{getppid}{2}}
  1098. \latex{\inputlisting{linuxex/ex16.pp}}
  1099. \html{\input{linuxex/ex16.tex}}
  1100. \function{GetPriority}{(Which,Who : Integer)}{Integer}
  1101. {
  1102. GetPriority returns the priority with which a process is running.
  1103. Which process(es) is determined by the \var{Which} and \var{Who} variables.
  1104. \var{Which} can be one of the pre-defined \var{Prio\_Process, Prio\_PGrp,
  1105. Prio\_User}, in which case \var{Who} is the process ID, Process group ID or
  1106. User ID, respectively.
  1107. }
  1108. {
  1109. Error checking must be done on LinuxError, since a priority can be negative.
  1110. \begin{description}
  1111. \item[sys\_esrch] No process found using \var{which} and \var{who}.
  1112. \item[sys\_einval] \var{Which} was not one of \var{Prio\_Process, Prio\_Grp
  1113. or Prio\_User}.
  1114. \end{description}
  1115. }
  1116. {\seef{SetPriority}, \seep{Nice}, \seem{Getpriority}{2}}
  1117. For an example, see \seep{Nice}.
  1118. \procedure{GetTime}
  1119. { (Var Hour,Minute, Second : Word) }
  1120. {
  1121. Returns the current time of the day.
  1122. }
  1123. {None}
  1124. {\seef{GetEpochTime}, \seep{GetDate}, \seep{EpochToLocal} }
  1125. \latex{\inputlisting{linuxex/ex5.pp}}
  1126. \html{\input{linuxex/ex5.tex}}
  1127. \function{GetUid}{}{Longint}
  1128. { Get the real user ID of the currently running process.}
  1129. {None.}
  1130. {\seef{GetEUid}, \seem{getuid}{2} }
  1131. \latex{\inputlisting{linuxex/ex17.pp}}
  1132. \html{\input{linuxex/ex17.tex}}
  1133. \function{Glob}{(Const Path : Pathstr)}{PGlob}
  1134. {
  1135. Glob returns a pointer to a glob structure which contains all filenames which
  1136. exist and match the pattern in \var{Path}.
  1137. The pattern can contain wildcard characters, which have their
  1138. usual meaning.
  1139. }
  1140. { Returns nil on error, and \var{LinuxError} is set.
  1141. \begin{description}
  1142. \item[sys\_enomem] No memory on heap for glob structure.
  1143. \item[others] As returned by the opendir call, and sys\_readdir.
  1144. \end{description}
  1145. }
  1146. {\seep{GlobFree}, \seem{Glob}{3} }
  1147. \latex{\inputlisting{linuxex/ex49.pp}}
  1148. \html{\input{linuxex/ex49.tex}}
  1149. \procedure{GlobFree}{(Var P : Pglob)}
  1150. {Releases the memory, occupied by a pglob structure. \var{P} is set to nil.}{None}
  1151. { \seef{Glob} }
  1152. For an example, see \seef{Glob}.
  1153. \procedure{IOCtl}{(Handle,Ndx: Longint; Data: Pointer)}
  1154. {
  1155. This is a general interface to the Unix/ \linux ioctl call.
  1156. It performs various operations on the filedescriptor \var{Handle}.
  1157. \var{Ndx} describes the operation to perform.
  1158. \var{Data} points to data needed for the \var{Ndx} function.
  1159. The structure of this data is function-dependent, so we don't elaborate on
  1160. this here.
  1161. For more information on this, see various manual pages under linux.
  1162. }
  1163. {
  1164. Errors are reported in LinuxError. They are very dependent on the used
  1165. function, that's why we don't list them here
  1166. }
  1167. {\seem{ioctl}{2}}
  1168. \latex{\inputlisting{linuxex/ex54.pp}}
  1169. \html{\input{linuxex/ex54.tex}}
  1170. \function{IOperm}{(From,Num : Cadinal; Value : Longint)}{boolean}
  1171. {\var{IOperm}
  1172. sets permissions on \var{Num} ports starting with port \var{From} to
  1173. \var{Value}. The function returns \var{True} if the call was successfull,
  1174. \var{False} otherwise.
  1175. {\em Remark:}
  1176. \begin{itemize}
  1177. \item This works ONLY as root.
  1178. \item Only the first \var{0x03ff} ports can be set.
  1179. \item When doing a \seef{Fork}, the permissions are reset. When doing a
  1180. \seep{Execve} they are kept.
  1181. \end{itemize}
  1182. }{Errors are returned in \var{LinuxError}}{\seem{ioperm}{2}}
  1183. \function{IsATTY}{(var f)}{Boolean};
  1184. {
  1185. Check if the filehandle described by \var{f} is a terminal.
  1186. f can be of type
  1187. \begin{enumerate}
  1188. \item \var{longint} for file handles;
  1189. \item \var{Text} for \var{text} variables such as \var{input} etc.
  1190. \end{enumerate}
  1191. Returns \var{True} if \var{f} is a terminal, \var{False} otherwise.
  1192. }
  1193. {No errors are reported}
  1194. {\seep{IOCtl},\seef{TTYName}}
  1195. \functionl{S\_ISBLK}{ISBLK}{(m:integer)}{boolean}
  1196. { \var{S\_ISBLK} checks the file mode \var{m} to see whether the file is a
  1197. block device file. If so it returns \var{True}.
  1198. }
  1199. {\seef{FStat},
  1200. \seefl{S\_ISLNK}{ISLNK},
  1201. \seefl{S\_ISREG}{ISREG},
  1202. \seefl{S\_ISDIR}{ISDIR},
  1203. \seefl{S\_ISCHR}{ISCHR},
  1204. \seefl{S\_ISFIFO}{ISFIFO},
  1205. \seefl{S\_ISSOCK}{ISSOCK}
  1206. }
  1207. For an example, see \seef{ISLNK}.
  1208. \functionl{S\_ISCHR}{ISCHR}{(m:integer)}{boolean}
  1209. { \var{S\_ISCHR} checks the file mode \var{m} to see whether the file is a
  1210. character device file. If so it returns \var{True}.
  1211. }
  1212. {\seef{FStat},
  1213. \seefl{S\_ISLNK}{ISLNK},
  1214. \seefl{S\_ISREG}{ISREG},
  1215. \seefl{S\_ISDIR}{ISDIR},
  1216. \seefl{S\_ISBLK}{ISBLK},
  1217. \seefl{S\_ISFIFO}{ISFIFO},
  1218. \seefl{S\_ISSOCK}{ISSOCK}
  1219. }
  1220. For an example, see \seef{ISLNK}.
  1221. \functionl{S\_ISDIR}{ISDIR}{(m:integer)}{boolean}
  1222. { \var{S\_ISDIR} checks the file mode \var{m} to see whether the file is a
  1223. directory. If so it returns \var{True}
  1224. }
  1225. {\seef{FStat},
  1226. \seefl{S\_ISLNK}{ISLNK},
  1227. \seefl{S\_ISREG}{ISREG},
  1228. \seefl{S\_ISCHR}{ISCHR},
  1229. \seefl{S\_ISBLK}{ISBLK},
  1230. \seefl{S\_ISFIFO}{ISFIFO},
  1231. \seefl{S\_ISSOCK}{ISSOCK}
  1232. }
  1233. For an example, see \seef{ISLNK}.
  1234. \functionl{S\_ISFIFO}{ISFIFO}{(m:integer)}{boolean}
  1235. { \var{S\_ISFIFO} checks the file mode \var{m} to see whether the file is a
  1236. fifo (a named pipe). If so it returns \var{True}.
  1237. }
  1238. {\seef{FStat},
  1239. \seefl{S\_ISLNK}{ISLNK},
  1240. \seefl{S\_ISREG}{ISREG},
  1241. \seefl{S\_ISDIR}{ISDIR},
  1242. \seefl{S\_ISCHR}{ISCHR},
  1243. \seefl{S\_ISBLK}{ISBLK},
  1244. \seefl{S\_ISSOCK}{ISSOCK}
  1245. }
  1246. For an example, see \seef{ISLNK}.
  1247. \functionl{S\_ISLNK}{ISLNK}{(m:integer)}{boolean}
  1248. { \var{S\_ISLNK} checks the file mode \var{m} to see whether the file is a
  1249. symbolic link. If so it returns \var{True}
  1250. }
  1251. {\seef{FStat},
  1252. \seefl{S\_ISREG}{ISREG},
  1253. \seefl{S\_ISDIR}{ISDIR},
  1254. \seefl{S\_ISCHR}{ISCHR},
  1255. \seefl{S\_ISBLK}{ISBLK},
  1256. \seefl{S\_ISFIFO}{ISFIFO},
  1257. \seefl{S\_ISSOCK}{ISSOCK}
  1258. }
  1259. \latex{\inputlisting{linuxex/ex53.pp}}
  1260. \html{\input{linuxex/ex53.tex}}
  1261. \functionl{S\_ISREG}{ISREG}{(m:integer)}{boolean}
  1262. { \var{S\_ISREG} checks the file mode \var{m} to see whether the file is a
  1263. regular file. If so it returns \var{True}
  1264. }
  1265. {\seef{FStat},
  1266. \seefl{S\_ISLNK}{ISLNK},
  1267. \seefl{S\_ISDIR}{ISDIR},
  1268. \seefl{S\_ISCHR}{ISCHR},
  1269. \seefl{S\_ISBLK}{ISBLK},
  1270. \seefl{S\_ISFIFO}{ISFIFO},
  1271. \seefl{S\_ISSOCK}{ISSOCK}
  1272. }
  1273. For an example, see \seef{ISLNK}.
  1274. \functionl{S\_ISSOCK}{ISSOCK}{(m:integer)}{boolean}
  1275. { \var{S\_ISSOCK} checks the file mode \var{m} to see whether the file is a
  1276. socket. If so it returns \var{True}.
  1277. }
  1278. {\seef{FStat},
  1279. \seefl{S\_ISLNK}{ISLNK},
  1280. \seefl{S\_ISREG}{ISREG},
  1281. \seefl{S\_ISDIR}{ISDIR},
  1282. \seefl{S\_ISCHR}{ISCHR},
  1283. \seefl{S\_ISBLK}{ISBLK},
  1284. \seefl{S\_ISFIFO}{ISFIFO}
  1285. }
  1286. For an example, see \seef{ISLNK}.
  1287. \function{Kill}{Pid : Longint; Sig : Integer)}{Integer}
  1288. { Send a signal \var{Sig} to a process or process group. If \var{Pid}>0 then
  1289. the signal is sent to \var{Pid}, if it equals -1, then the signal is sent to
  1290. all processes except process 1. If \var{Pid}<-1 then the signal is sent to
  1291. process group -Pid.
  1292. The return value is zero, except in case three, where the return value is the
  1293. number of processes to which the signal was sent.
  1294. }
  1295. {\var{LinuxError} is used to report errors:
  1296. \begin{description}
  1297. \item[sys\_einval] An invalid signal is sent.
  1298. \item[sys\_esrch] The \var{Pid} or process group don't exist.
  1299. \item[sys\_eperm] The effective userid of the current process doesn't math
  1300. the one of process \var{Pid}.
  1301. \end{description}
  1302. }
  1303. {\seep{SigAction}, \seef{Signal}, \seem{Kill}{2} }
  1304. \function{LStat}{(Path : Pathstr; Var Info : stat)}{Boolean}
  1305. {
  1306. \var{LStat} gets information about the link specified in \var{Path}, and stores it in
  1307. \var{Info}, which is of type \var{stat}. Contrary to \var{FStat}, it stores
  1308. information about the link, not about the file the link points to.
  1309. The function returns \var{True} if the call was succesfull, \var{False} if the call
  1310. failed.
  1311. }
  1312. { \var{LinuxError} is used to report errors.
  1313. \begin{description}
  1314. \item[sys\_enoent] \var{Path} does not exist.
  1315. \end{description}
  1316. }
  1317. {\seef{FStat}, \seef{FSStat}, \seem{stat}{2}}
  1318. \latex{\inputlisting{linuxex/ex29.pp}}
  1319. \html{\input{linuxex/ex29.tex}}
  1320. \function{Link}{(OldPath,NewPath : pathstr)}{Boolean}
  1321. {\var{Link} makes \var{NewPath} point to the same file als \var{OldPath}. The two files
  1322. then have the same inode number. This is known as a 'hard' link.
  1323. The function returns \var{True} if the call was succesfull, \var{False} if the call
  1324. failed.
  1325. }
  1326. { Errors are returned in \var{LinuxError}.
  1327. \begin{description}
  1328. \item[sys\_exdev] \var {OldPath} and \var {NewPath} are not on the same
  1329. filesystem.
  1330. \item[sys\_eperm] The filesystem containing oldpath and newpath doesn't
  1331. support linking files.
  1332. \item[sys\_eaccess] Write access for the directory containing \var{Newpath}
  1333. is disallowed, or one of the directories in \var{OldPath} or {NewPath} has no
  1334. search (=execute) permission.
  1335. \item[sys\_enoent] A directory entry in \var{OldPath} or \var{NewPath} does
  1336. not exist or is a symbolic link pointing to a non-existent directory.
  1337. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  1338. nor a directory.
  1339. \item[sys\_enomem] Insufficient kernel memory.
  1340. \item[sys\_erofs] The files are on a read-only filesystem.
  1341. \item[sys\_eexist] \var{NewPath} already exists.
  1342. \item[sys\_emlink] \var{OldPath} has reached maximal link count.
  1343. \item[sys\_eloop] \var{OldPath} or \var{NewPath} has a reference to a circular
  1344. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  1345. \item[sys\_enospc] The device containing \var{NewPath} has no room for anothe
  1346. entry.
  1347. \item[sys\_eperm] \var{OldPath} points to . or .. of a directory.
  1348. \end{description}
  1349. }
  1350. {\seef{SymLink}, \seef{UnLink}, \seem{Link}{2} }
  1351. \latex{\inputlisting{linuxex/ex21.pp}}
  1352. \html{\input{linuxex/ex21.tex}}
  1353. \function{LocalToEpoch}{(Year,Month,Day,Hour,Minute,Second : Word)}{longint}
  1354. {
  1355. Converts the Local time to epoch time (=Number of seconds since 00:00:00 , January 1,
  1356. 1970 ).
  1357. }
  1358. {None}
  1359. {\seef{GetEpochTime}, \seep{EpochToLocal}, \seep{GetTime},\seep{GetDate} }
  1360. \latex{\inputlisting{linuxex/ex4.pp}}
  1361. \html{\input{linuxex/ex4.tex}}
  1362. \function{MkFifo}{(PathName: String; Mode : Longint)}{Boolean}
  1363. {\var{MkFifo} creates named a named pipe in the filesystem, with name
  1364. \var{PathName} and mode {Mode}.
  1365. }
  1366. { \var{LinuxError} is used to report errors:
  1367. \begin{description}
  1368. \item[sys\_emfile] Too many file descriptors for this process.
  1369. \item[sys\_enfile] The system file table is full.
  1370. \end{description}
  1371. }
  1372. {\seep{POpen}, \seef{MkFifo}, \seem{mkfifo}{4}}
  1373. \procedure{Nice}{( N : Integer)}
  1374. {Nice adds \var{-N} to the priority of the running process. The lower the
  1375. priority numerically, the less the process is favored.
  1376. Only the superuser can specify a negative \var{N}, i.e. increase the rate at
  1377. which the process is run.
  1378. }
  1379. { Errors are returned in \var{LinuxError}
  1380. \begin{description}
  1381. \item [sys\_eperm] A non-superuser tried to specify a negative \var{N}, i.e.
  1382. do a priority increase.
  1383. \end{description}
  1384. }{\seef{GetPriority}, \seef{SetPriority}, \seem{Nice}{2}}
  1385. \latex{\inputlisting{linuxex/ex15.pp}}
  1386. \html{\input{linuxex/ex15.tex}}
  1387. \function{OpenDir}{(f:pchar)}{pdir}
  1388. { \var{OpenDir} opens the directory \var{f}, and returns a \var{pdir}
  1389. pointer to a \var{Dir} record, which can be used to read the directory
  1390. structure. If the directory cannot be opened, \var{nil} is returned.}
  1391. {Errors are returned in LinuxError.}
  1392. {\seef{CloseDir}, \seef{ReadDir}, \seep{SeekDir}, \seef{TellDir},
  1393. \seem{opendir}{3}}
  1394. \latex{\inputlisting{linuxex/ex35.pp}}
  1395. \html{\input{linuxex/ex35.tex}}
  1396. \function{PClose}{(Var F : FileType)}{longint}
  1397. { \var{PClose} closes a file opened with \var{POpen}. It waits for the
  1398. command to complete, and then returns the exit status of the command.
  1399. }
  1400. {\var{LinuxError} is used to report errors. If it is different from zero,
  1401. the exit status is not valid.}
  1402. {\seep{POpen}}
  1403. For an example, see \seep{POpen}
  1404. \procedure {POpen}{(Var F : FileType; Cmd : pathstr; rw : char)}
  1405. { Popen runs the command specified in \var{Cmd},
  1406. and redirects the standard in or output of the
  1407. command to the other end of the pipe \var{F}. The parameter \var{rw}
  1408. indicates the direction of the pipe. If it is set to \var{'W'}, then F can
  1409. be used to write data, which will then be read by the command from stdinput.
  1410. If it is set to \var{'R'}, then the standard output of the command can be
  1411. read from \var{F}. \var{F} should be reset or rewritten prior to using it.
  1412. \var{F} can be of type \var{Text} or \var{File}.
  1413. A file opened with \var {POpen} can be closed with \var{Close}, but also
  1414. with \seef{PClose}. The result is the same, but \var{PClose} returns the
  1415. exit status of the command \var{Cmd}.}
  1416. {Errors are reported in \var{LinuxError} and are essentially those of the
  1417. Execve, Dup and AssignPipe commands.
  1418. }
  1419. {\seep{AssignPipe}, \seem{popen}{3}, \seef{PClose}}
  1420. \latex{\inputlisting{linuxex/ex37.pp}}
  1421. \html{\input{linuxex/ex37.tex}}
  1422. \function{ReadDir}{(p:pdir)}{pdirent}
  1423. {\var{ReadDir} reads the next entry in the directory pointed to by \var{p}.
  1424. It returns a \var{pdirent} pointer to a structure describing the entry.
  1425. If the next entry can't be read, \var{Nil} is returned.
  1426. }
  1427. {Errors are returned in LinuxError.}
  1428. {\seef{CloseDir}, \seef{OpenDir}, \seep{SeekDir}, \seef{TellDir},
  1429. \seem{readdir}{3}}
  1430. For an example, see \seef{OpenDir}.
  1431. \procedure {SeekDir}{(p:pdir;off:longint)}
  1432. { \var{SeekDir} sets the directory pointer to the \var{off}-th entry in the
  1433. directory structure pointed to by \var{p}.}
  1434. {Errors are returned in LinuxError.}
  1435. {\seef{CloseDir}, \seef{ReadDir}, \seef{OpenDir}, \seef{TellDir},
  1436. \seem{seekdir}{3}}
  1437. For an example, see \seef{OpenDir}.
  1438. \function{Select}{(N : Longint; \\ var readfds,writefds,exceptfds : PFDset;
  1439. Var Timeout)}{Longint}
  1440. {\var{Select} checks one of the file descriptors in the \var{FDSets} to see if its
  1441. status changed.
  1442. \var{readfds, writefds} and \var{exceptfds} are pointers to arrays of 256
  1443. bits. If you want a file descriptor to be checked, you set the
  1444. corresponding element in the array to 1. The other elements in the array
  1445. must be set to zero. Three arrays are passed : The entries in \var{readfds}
  1446. are checked to see if characters become available for reading. The entries
  1447. in \var{writefds} are checked to see if it is OK to write to them, while
  1448. entries in \var{exceptfds} are cheked to see if an exception occorred on
  1449. them.
  1450. You can use the functions \seepl{FD\_Clear}{FDClear}, \seepl{FD\_Clr}{FDClr},
  1451. \seepl{FD\_Set}{FDSet}, \seefl{FD\_IsSet}{FDIsSet} to manipulate the individual elements of a set.
  1452. The pointers can be nil.
  1453. \var{N} is the largest index of a nonzero entry plus 1. (= the largest
  1454. file-descriptor + 1).
  1455. \var{TimeOut} can be used to set a time limit.
  1456. If \var{TimeOut} can be two types :
  1457. \begin{enumerate}
  1458. \item \var{TimeOut} is of type \var{PTime} and contains a
  1459. zero time, the call returns immediately. If \var{TimeOut} is \var{Nil}, the
  1460. kernel will wait forever, or until a status changed.
  1461. \item \var{TimeOut} is of type \var{Longint}. If it is -1, this has the same
  1462. effect as a \var{Timeout} of type \var{PTime} which is \var{Nil}.
  1463. Otherwise, \var{TimeOut} contains a time in milliseconds.
  1464. \end{enumerate}
  1465. When the TimeOut is reached, or one of the file descriptors has changed,
  1466. the \var{Select} call returns. On return, it will have modified the entries
  1467. in the array which have actually changed, and it returns the number of
  1468. entries that have been changed. If the timout was reached, and no decsriptor
  1469. changed, zero is returned; The arrays of indexes are undefined after that.
  1470. On error, -1 is returned.}
  1471. {On error, the function returns -1, and Errors are reported in LinuxError :
  1472. \begin{description}
  1473. \item[SYS\_EBADF\ ] An invalid descriptot was specified in one of the sets.
  1474. \item[SYS\_EINTR\ ] A non blocked signal was caught.
  1475. \item[SYS\_EINVAL\ ] \var{N} is negative or too big.
  1476. \item[SYS\_ENOMEM\ ] \var{Select} was unable to allocate memory for its
  1477. internal tables.
  1478. \end{description}}
  1479. {\seef{SelectText}, \seef{GetFS},
  1480. \seepl{FD\_Clear}{FDClear},
  1481. \seepl{FD\_Clr}{FDClr},
  1482. \seepl{FD\_Set}{FDSet},
  1483. \seefl{FD\_IsSet}{FDIsSet}}
  1484. \latex{\inputlisting{linuxex/ex33.pp}}
  1485. \html{\input{linuxex/ex33.tex}}
  1486. \function{SelectText}{( var T : Text; TimeOut :PTime)}{Longint}
  1487. {\var{SelectText} executes the \seef{Select} call on a file of type
  1488. \var{Text}. You can specify a timeout in \var{TimeOut}. The SelectText call
  1489. determines itself whether it should check for read or write, depending on
  1490. how the file was opened : With \var{Reset} it is checked for reading, with
  1491. \var{Rewrite} and \var{Append} it is checked for writing.}
  1492. {See \seef{Select}. \var{SYS\_EBADF} can also mean that the file wasn't
  1493. opened.}
  1494. {\seef{Select}, \seef{GetFS}}
  1495. \function{SetPriority}{(Which,Who,Prio : Integer)}{Integer}
  1496. {
  1497. SetPriority sets the priority with which a process is running.
  1498. Which process(es) is determined by the \var{Which} and \var{Who} variables.
  1499. \var{Which} can be one of the pre-defined \var{Prio\_Process, Prio\_PGrp,
  1500. Prio\_User}, in which case \var{Who} is the process ID, Process group ID or
  1501. User ID, respectively.
  1502. \var{Prio} is a value in the range -20 to 20.
  1503. }
  1504. {
  1505. Error checking must be done on LinuxError, since a priority can be negative.
  1506. \begin{description}
  1507. \item[sys\_esrch] No process found using \var{which} and \var{who}.
  1508. \item[sys\_einval] \var{Which} was not one of \var{Prio\_Process, Prio\_Grp
  1509. or Prio\_User}.
  1510. \item[sys\_eperm] A process was found, but neither its effective or real
  1511. user ID match the effective user ID of the caller.
  1512. \item [sys\_eacces] A non-superuser tried to a priority increase.
  1513. \end{description}
  1514. }
  1515. {\seef{GetPriority}, \seep{Nice}, \seem{Setpriority}{2}}
  1516. For an example, see \seep{Nice}.
  1517. \function{Shell}{(Command : String)}{Longint}
  1518. {\var{Shell} invokes the bash shell (\file{/bin/sh}), and feeds it the
  1519. command \var{Command} (using the \var{-c} option). The function then waits
  1520. for the command to complete, and then returns the exit
  1521. status of the command, or 127 if it could not complete the \seef{Fork}
  1522. or \seep{Execve} calls.
  1523. }
  1524. {Errors are reported in LinuxError.}
  1525. {\seep{POpen}, \seef{Fork}, \seep{Execve}, \seem{system}{3}}
  1526. \latex{\inputlisting{linuxex/ex56.pp}}
  1527. \html{\input{linuxex/ex56.tex}}
  1528. \procedure{SigAction}{(Signum : Integer; Var Act,OldAct : PSigActionRec)}
  1529. { Changes the action to take upon receipt of a signal. \var{Act} and
  1530. \var{Oldact} are pointers to a \var{SigActionRec} record.
  1531. \var{SigNum} specifies the signal, and can be any signal except
  1532. \textbf{SIGKILL} or \textbf{SIGSTOP}.
  1533. If \var{Act} is non-nil, then the new action for signal \var{SigNum} is taken
  1534. from it. If \var{OldAct} is non-nil, the old action is stored there.
  1535. \var{Sa\_Handler} may be \var{SIG\_DFL} for the default action or
  1536. \var{SIG\_IGN} to ignore the signal.
  1537. \var{Sa\_Mask} Specifies which signals should be ignord during the execution
  1538. of the signal handler.
  1539. \var{Sa\_Flags} Speciefies a series of flags which modify the behaviour of
  1540. the signal handler. You can 'or' none or more of the following :
  1541. \begin{description}
  1542. \item[SA\_NOCLDSTOP] If signum is \textbf{SIGCHLD} do not receive
  1543. notification when child processes stop.
  1544. \item[SA\_ONESHOT or SA\_RESETHAND] Restore the signal action to the default
  1545. state once the signal handler has been called.
  1546. \item[SA\_RESTART] For compatibility with BSD signals.
  1547. \item[SA\_NOMASK or SA\_NODEFER] Do not prevent the signal from being received
  1548. from within its own signal handler.
  1549. \end{description}
  1550. }
  1551. {\var{LinuxError} is used to report errors.
  1552. \begin{description}
  1553. \item[sys\_einval] an invalid signal was specified, or it was
  1554. \textbf{SIGKILL} or \textbf{SIGSTOP}.
  1555. \item[sys\_efault] \var{Act,OldAct} point outside this process address space
  1556. \item[sys\_eintr] System call was interrupted.
  1557. \end{description}
  1558. }
  1559. {
  1560. \seep{SigProcMask}, \seef{SigPending}, \seep{SigSuspend}, \seef{Kill},
  1561. \seem{Sigaction}{2}
  1562. }
  1563. \latex{\inputlisting{linuxex/ex57.pp}}
  1564. \html{\input{linuxex/ex57.tex}}
  1565. \function{SigPending}{}{SigSet}
  1566. {
  1567. Sigpending allows the examination of pending signals (which have been raised
  1568. while blocked.) The signal mask of pending signals is returned.
  1569. }
  1570. {None}
  1571. {\seep{SigAction}, \seep{SigProcMask}, \seep{SigSuspend}, \seef{Signal},
  1572. \seef{Kill}, \seem{Sigpending}{2} }
  1573. \procedure {SigProcMask}{(How : Integer; SSet,OldSSet : PSigSet)}
  1574. {
  1575. Changes the list of currently blocked signals. The behaviour of the call
  1576. depends on \var{How} :
  1577. \begin{description}
  1578. \item[SIG\_BLOCK] The set of blocked signals is the union of the current set
  1579. and the \var{SSet} argument.
  1580. \item[SIG\_UNBLOCK] The signals in \var{SSet} are removed from the set of
  1581. currently blocked signals.
  1582. \item[SIG\_SETMASK] The list of blocked signals is set so \var{SSet}.
  1583. \end{description}
  1584. If \var{OldSSet} is non-nil, then the old set is stored in it.
  1585. }
  1586. {\var{LinuxError} is used to report errors.
  1587. \begin{description}
  1588. \item[sys\_efault] \var{SSet} or \var{OldSSet} point to an adress outside
  1589. the range of the process.
  1590. \item[sys\_eintr] System call was interrupted.
  1591. \end{description}
  1592. }
  1593. {\seep{SigAction}, \seef{SigPending}, \seep{SigSuspend}, \seef{Kill},
  1594. \seem{Sigprocmask}{2} }
  1595. \procedure{SigSuspend}{(Mask : SigSet)}
  1596. {SigSuspend temporarily replaces the signal mask for the process with the one
  1597. given in \var{Mask}, and then suspends the process until a signal is received.
  1598. }
  1599. {None}
  1600. {\seep{SigAction}, \seep{SigProcMask}, \seef{SigPending}, \seef{Signal},
  1601. \seef{Kill}, \seem{SigSuspend}{2} }
  1602. \function{Signal}{(SigNum : Integer; Handler : SignalHandler)}{SignalHandler}
  1603. {
  1604. Signal installs a new signal handler for signal \var{SigNum}. This call has
  1605. the same functionality as the \textbf{SigAction} call.
  1606. The return value for Signal is the old signal handler, or nil on error.
  1607. }
  1608. {\var {LinuxError} is used to report errors :
  1609. \begin{description}
  1610. \item[SIG\_ERR] An error occurred.
  1611. \end{description}
  1612. }
  1613. {\seep{SigAction},\seef{Kill}, \seem{Signal}{2} }
  1614. \latex{\inputlisting{linuxex/ex58.pp}}
  1615. \html{\input{linuxex/ex58.tex}}
  1616. \function{SymLink}{(OldPath,NewPath : pathstr)}{Boolean}
  1617. {\var{SymLink} makes \var{Newpath} point to the file in \var{OldPath}, which doesn't
  1618. necessarily exist. The two files DO NOT have the same inode number.
  1619. This is known as a 'soft' link.
  1620. The permissions of the link are irrelevant, as they are not used when
  1621. following the link. Ownership of the file is only checked in case of removal
  1622. or renaming of the link.
  1623. The function returns \var{True} if the call was succesfull, \var{False} if the call
  1624. failed.
  1625. }
  1626. { Errors are returned in \var{LinuxError}.
  1627. \begin{description}
  1628. \item[sys\_eperm] The filesystem containing oldpath and newpath doesn't
  1629. support linking files.
  1630. \item[sys\_eaccess] Write access for the directory containing \var{Newpath}
  1631. is disallowed, or one of the directories in \var{OldPath} or {NewPath} has no
  1632. search (=execute) permission.
  1633. \item[sys\_enoent] A directory entry in \var{OldPath} or \var{NewPath} does
  1634. not exist or is a symbolic link pointing to a non-existent directory.
  1635. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  1636. nor a directory.
  1637. \item[sys\_enomem] Insufficient kernel memory.
  1638. \item[sys\_erofs] The files are on a read-only filesystem.
  1639. \item[sys\_eexist] \var{NewPath} already exists.
  1640. \item[sys\_eloop] \var{OldPath} or \var{NewPath} has a reference to a circular
  1641. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  1642. \item[sys\_enospc] The device containing \var{NewPath} has no room for anothe
  1643. entry.
  1644. \end{description}
  1645. }
  1646. {\seef{Link}, \seef{UnLink}, \seem{Symlink}{2} }
  1647. \latex{\inputlisting{linuxex/ex22.pp}}
  1648. \html{\input{linuxex/ex22.tex}}
  1649. \function{TCDrain}{(Fd:longint)}{Boolean}
  1650. { \var{TCDrain}
  1651. waits until all data to file descriptor \var{Fd} is transmitted.
  1652. The function returns \var{True} if the call was succesfull, \var{False}
  1653. otherwise.
  1654. }
  1655. {Errors are reported in LinuxError}
  1656. {\seem{termios}{2}}
  1657. \function {TCFlow}{(Fd,Act:longint)}{Boolean}
  1658. { \var{TCFlow}
  1659. suspends/resumes transmission or reception of data to or from the file
  1660. descriptor \var{Fd}, depending
  1661. on the action \var {Act}. This can be one of the following pre-defined
  1662. values:
  1663. \begin{description}
  1664. \item [TCOOFF\ ] suspend reception/transmission,
  1665. \item [TCOON\ ] resume reception/transmission,
  1666. \item [TCIOFF\ ] transmit a stop character to stop input from the terminal,
  1667. \item [TCION\ ] transmit start to resume input from the terminal.
  1668. \end{description}
  1669. The function returns \var{True} if the call was succesfull, \var{False}
  1670. otherwise.
  1671. }
  1672. {Errors are reported in LinuxError.}
  1673. {\seem{termios}{2}}
  1674. \function{TCFlush}{(Fd,QSel:longint)}{Boolean}
  1675. { \var{TCFlush}
  1676. discards all data sent or received to/from file descriptor \var{fd}.
  1677. \var{QSel} indicates which queue
  1678. should be discard. It can be one of the following pre-defined values :
  1679. \begin{description}
  1680. \item [TCIFLUSH\ ] input,
  1681. \item [TCOFLUSH\ ] output,
  1682. \item [TCIOFLUSH\ ] both input and output.
  1683. \end{description}
  1684. The function returns \var{True} if the call was succesfull, \var{False}
  1685. otherwise.
  1686. }
  1687. {Errors are reported in LinuxError.}
  1688. {\seem{termios}{2}}
  1689. \function{TCGetAttr}{(fd:longint;var tios:TermIOS)}{Boolean}
  1690. { \var{TCGetAttr}
  1691. gets the terminal parameters from the terminal referred to by the file
  1692. descriptor \var{fd} and returns them in a \var{TermIOS} structure \var{tios}.
  1693. The function returns \var{True} if the call was succesfull, \var{False}
  1694. otherwise.
  1695. }
  1696. {Errors are reported in LinuxError}
  1697. {\seef{TCSetAttr}, \seem{termios}{2} }
  1698. \latex{\inputlisting{linuxex/ex55.pp}}
  1699. \html{\input{linuxex/ex55.tex}}
  1700. \function{TCGetPGrp}{(Fd:longint;var Id:longint)}{boolean}
  1701. { \var{TCGetPGrp}
  1702. returns the process group ID of a foreground process group in \var{Id}
  1703. The function returns \var{True} if the call was succesfull, \var{False}
  1704. otherwise
  1705. }
  1706. {Errors are reported in LinuxError}
  1707. {\seem{termios}{2}}
  1708. \function{TCSendBreak}{(Fd,Duration:longint)}{Boolean}
  1709. { \var{TCSendBreak}
  1710. Sends zero-valued bits on an asynchrone serial connection decsribed by
  1711. file-descriptor \var{Fd}, for duration \var{Duration}.
  1712. The function returns \var{True} if the action was performed successfully,
  1713. \var{False} otherwise.
  1714. }
  1715. {Errors are reported in LinuxError.}
  1716. {\seem{termios}{2}}
  1717. \function{TCSetAttr}{(Fd:longint;OptAct:longint;var Tios:TermIOS)}{Boolean}
  1718. { \var{TCSetAttr}
  1719. Sets the terminal parameters you specify in a \var{TermIOS} structure
  1720. \var{Tios} for the terminal
  1721. referred to by the file descriptor \var{Fd}. \var{OptAct} specifies an
  1722. optional action when the set need to be done,
  1723. this could be one of the following pre-defined values:
  1724. \begin{description}
  1725. \item [TCSANOW\ ] set immediately.
  1726. \item [TCSADRAIN\ ] wait for output.
  1727. \item [TCSAFLUSH\ ] wait for output and discard all input not yet read.
  1728. \end{description}
  1729. The function Returns \var{True} if the call was succesfull, \var{False}
  1730. otherwise.
  1731. }
  1732. {Errors are reported in LinuxError.}
  1733. {\seef{TCGetAttr}, \seem{termios}{2}}
  1734. For an example, see \seef{TCGetAttr}.
  1735. \function{TCSetPGrp}{(Fd,Id:longint)}{boolean};
  1736. { \var{TCSetPGrp} Sets the Process Group Id to \var{Id}.
  1737. The function returns \var{True} if the call was successful, \var{False}
  1738. otherwise.
  1739. }
  1740. {Errors are returned in LinuxError.}
  1741. {\seef{TCGetPGrp}, \seem{termios}{2}}
  1742. For an example, see \seef{TCGetPGrp}.
  1743. \function{TTYName}{(var f)}{String}
  1744. {
  1745. Returns the name of the terminal pointed to by \var{f}. \var{f}
  1746. must be a terminal. \var{f} can be of type:
  1747. \begin{enumerate}
  1748. \item \var{longint} for file handles;
  1749. \item \var{Text} for \var{text} variables such as \var{input} etc.
  1750. \end{enumerate}
  1751. }
  1752. { Returns an empty string in case of an error. \var{Linuxerror} may be set
  1753. to indicate what error occurred, but this is uncertain.}
  1754. {\seef{IsATTY},\seep{IOCtl}}
  1755. \function{TellDir}{(p:pdir)}{longint}
  1756. { \var{TellDir} returns the current location in the directory structure
  1757. pointed to by \var{p}. It returns -1 on failure.}
  1758. {Errors are returned in LinuxError.}
  1759. {\seef{CloseDir}, \seef{ReadDir}, \seep{SeekDir}, \seef{OpenDir},
  1760. \seem{telldir}{3}}
  1761. For an example, see \seef{OpenDir}.
  1762. \function{Umask}{(Mask : Integer)}{Integer}
  1763. {
  1764. Change the file creation mask for the current user to \var{Mask}. The
  1765. current mask is returned.
  1766. }
  1767. {None}
  1768. {\seef{Chmod}, \seem{Umask}{2}}
  1769. \latex{\inputlisting{linuxex/ex27.pp}}
  1770. \html{\input{linuxex/ex27.tex}}
  1771. \procedure{Uname}{(var unamerec:utsname)}
  1772. {\var{Uname} gets the name and configuration of the current \linux kernel,
  1773. and returns it in \var{unamerec}.
  1774. }
  1775. {\var{LinuxError} is used to report errors.}
  1776. {\seef{GetHostName}, \seef{GetDomainName}, \seem{uname}{2}}
  1777. \function{UnLink}{(Var Path)}{Boolean}
  1778. {
  1779. \var{UnLink} decreases the link count on file \var{Path}. \var{Path} can be
  1780. of type \var{PathStr} or \var{PChar}. If the link count is zero, the
  1781. file is removed from the disk.
  1782. The function returns \var{True} if the call was succesfull, \var{False} if the call
  1783. failed.
  1784. }
  1785. { Errors are returned in \var{LinuxError}.
  1786. \begin{description}
  1787. \item[sys\_eaccess] You have no write access right in the directory
  1788. containing \var{Path}, or you have no search permission in one of the
  1789. directory components of \var{Path}.
  1790. \item[sys\_eperm] The directory containing pathname has the sticky-bit
  1791. set and the process's effective uid is neither the uid of the
  1792. file to be deleted nor that of the directory containing it.
  1793. \item[sys\_enoent] A component of the path doesn't exist.
  1794. \item[sys\_enotdir] A directory component of the path is not a directory.
  1795. \item[sys\_eisdir] \var{Path} refers to a directory.
  1796. \item[sys\_enomem] Insufficient kernel memory.
  1797. \item[sys\_erofs] \var{Path} is on a read-only filesystem.
  1798. \end{description}
  1799. }
  1800. {\seef{Link}, \seef{SymLink}, \seem{Unlink}{2} }
  1801. For an example, see \seef{Link}.
  1802. \function{Utime}{(path : pathstr; utim : utimbuf)}{Boolean}
  1803. {
  1804. \var{Utime} sets the access and modification times of a file.
  1805. the \var{utimbuf} record contains 2 fields, \var{actime}, and \var{modtime},
  1806. both of type Longint. They should be filled with an epoch-like time,
  1807. specifying, respectively, the last access time, and the last modification
  1808. time.
  1809. For some filesystem (most notably, FAT), these times are the same.
  1810. }
  1811. {Errors are returned in \var{LinuxError}.
  1812. \begin{description}
  1813. \item[sys\_eaccess] One of the directories in \var{Path} has no
  1814. search (=execute) permission.
  1815. \item[sys\_enoent] A directory entry in \var{Path} does
  1816. not exist or is a symbolic link pointing to a non-existent directory.
  1817. \end{description}
  1818. Other errors may occur, but aren't documented.
  1819. }
  1820. {\seef{GetEpochTime}, \seef{Chown}, \seef{Access}, \seem{utime}(2)}
  1821. \latex{\inputlisting{linuxex/ex25.pp}}
  1822. \html{\input{linuxex/ex25.tex}}
  1823. \function{WaitPid}{(Pid : longint; Status : pointer; Options : Integer)}{Longint}
  1824. { \var{WaitPid} waits for a child process with process ID \var{Pid} to exit. The
  1825. value of \var{Pid} can be one of the following:
  1826. \begin{description}
  1827. \item[Pid < -1] Causes \var{WaitPid} to wait for any child process whose
  1828. process group ID equals the absolute value of \var{pid}.
  1829. \item[Pid = -1] Causes \var{WaitPid} to wait for any child process.
  1830. \item[Pid = 0] Causes \var{WaitPid} to wait for any child process whose
  1831. process group ID equals the one of the calling
  1832. process.
  1833. \item[Pid > 0] Causes \var{WaitPid} to wait for the child whose process ID
  1834. equals the value of \var{Pid}.
  1835. \end{description}
  1836. The \var{Options} parameter can be used to specify further how \var{WaitPid}
  1837. behaves:
  1838. \begin{description}
  1839. \item [WNOHANG] Causes \var{Waitpid} to return immediately if no child has
  1840. exited.
  1841. \item [WUNTRACED] Causes \var{WaitPid} to return also for children which are
  1842. stopped, but whose status has not yet been reported.
  1843. \end{description}
  1844. Upon return, it returns the exit status of the process, or -1 in case of
  1845. failure.
  1846. }
  1847. {Errors are returned in LinuxError.}
  1848. {\seef{Fork}, \seep{Execve}, \seem{waitpid}{2}}
  1849. for an example, see \seef{Fork}.