linux.tex 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062
  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);
  46. PSignalHandler = ^SignalHandler;
  47. SignalRestorer = Procedure;
  48. PSignalrestorer = ^SignalRestorer;
  49. SigActionRec = Record
  50. Sa_Handler : PSignalhandler;
  51. Sa_Mask : Longint;
  52. Sa_flags : Integer;
  53. Sa_Restorer : PSignalRestorer;
  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{GetEpochTime}{}{longint}
  381. {
  382. returns the number of seconds since 00:00:00 gmt, january 1, 1970.
  383. it is adjusted to the local time zone, but not to DST.
  384. }
  385. {no errors}
  386. {\seep{EpochToLocal}, \seep{GetTime}, \seem{time}{2}}
  387. \input{linuxex/ex1.tex}
  388. \procedure
  389. {EpochToLocal}
  390. {(Epoch : Longint; var Year,Month,Day,Hour,Minute,Second : Word)}
  391. {
  392. Converts the epoch time (=Number of seconds since 00:00:00 , January 1,
  393. 1970, corrected for your time zone ) to local date and time.
  394. }
  395. {None}
  396. {\seef{GetEpochTime}, \seef{LocalToEpoch}, \seep{GetTime},\seep{GetDate} }
  397. \input{linuxex/ex3.tex}
  398. \function{LocalToEpoch}{(Year,Month,Day,Hour,Minute,Second : Word)}{longint}
  399. {
  400. Converts the Local time to epoch time (=Number of seconds since 00:00:00 , January 1,
  401. 1970 ).
  402. }
  403. {None}
  404. {\seef{GetEpochTime}, \seep{EpochToLocal}, \seep{GetTime},\seep{GetDate} }
  405. \input{linuxex/ex4.tex}
  406. \procedure{GetTime}
  407. { (Var Hour,Minute, Second : Word) }
  408. {
  409. Returns the current time of the day.
  410. }
  411. {None}
  412. {\seef{GetEpochTime}, \seep{GetDate}, \seep{EpochToLocal} }
  413. \input{linuxex/ex5.tex}
  414. \procedure{GetDate}
  415. { (Var Year, Month, Day : Word) }
  416. {
  417. Returns the current day.
  418. }
  419. {None}
  420. {\seef{GetEpochTime}, \seep{GetTime}, \seep{EpochToLocal} }
  421. \input{linuxex/ex6.tex}
  422. \procedure{Execve}
  423. {(Path : pathstr; args,ep : ppchar)}
  424. {
  425. Replaces the currently running program with the program, specified in
  426. \var{path}.
  427. It gives the program the options in \var{args}, and the environment in
  428. \var{ep}. They are pointers to an array of pointers to null-terminated
  429. strings. The last pointer in this array should be nil.
  430. On success, \var{execve} does not return.
  431. }
  432. {Errors are reported in \var{LinuxError}:
  433. \begin{description}
  434. \item[eacces] File is not a regular file, or has no execute permission.
  435. A compononent of the path has no search permission.
  436. \item[sys\_ eperm] The file system is mounted \textit{noexec}.
  437. \item[sys\_ e2big] Argument list too big.
  438. \item[sys\_ enoexec] The magic number in the file is incorrect.
  439. \item[sys\_ enoent] The file does not exist.
  440. \item[sys\_ enomem] Not enough memory for kernel.
  441. \item[sys\_ enotdir] A component of the path is not a directory.
  442. \item[sys\_ eloop] The path contains a circular reference (via symlinks).
  443. \end{description}}
  444. {\seep{Execve}, \seep{Execv}, \seep{Execvp} \seep{Execle},
  445. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execve}{2} }
  446. \input{linuxex/ex7.tex}
  447. \procedure{Execv}
  448. {(Path : pathstr; args : ppchar)}
  449. {
  450. Replaces the currently running program with the program, specified in
  451. \var{path}.
  452. It gives the program the options in \var{args}.
  453. This is a pointer to an array of pointers to null-terminated
  454. strings. The last pointer in this array should be nil.
  455. The current environment is passed to the program.
  456. On success, \var{execv} does not return.
  457. }
  458. {Errors are reported in \var{LinuxError}:
  459. \begin{description}
  460. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  461. A compononent of the path has no search permission.
  462. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  463. \item[sys\_e2big] Argument list too big.
  464. \item[sys\_enoexec] The magic number in the file is incorrect.
  465. \item[sys\_enoent] The file does not exist.
  466. \item[sys\_enomem] Not enough memory for kernel.
  467. \item[sys\_enotdir] A component of the path is not a directory.
  468. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  469. \end{description}}
  470. {\seep{Execve}, \seep{Execvp}, \seep{Execle},
  471. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execv}{3} }
  472. \input{linuxex/ex8.tex}
  473. \procedure{Execvp}
  474. {(Path : pathstr; args : ppchar)}
  475. {
  476. Replaces the currently running program with the program, specified in
  477. \var{path}. The executable in \var{path} is searched in the path, if it isn't
  478. an absolute filename.
  479. It gives the program the options in \var{args}. This is a pointer to an array of pointers to null-terminated
  480. strings. The last pointer in this array should be nil.
  481. The current environment is passed to the program.
  482. On success, \var{execvp} does not return.
  483. }
  484. {Errors are reported in \var{LinuxError}:
  485. \begin{description}
  486. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  487. A compononent of the path has no search permission.
  488. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  489. \item[sys\_e2big] Argument list too big.
  490. \item[sys\_enoexec] The magic number in the file is incorrect.
  491. \item[sys\_enoent] The file does not exist.
  492. \item[sys\_enomem] Not enough memory for kernel.
  493. \item[sys\_enotdir] A component of the path is not a directory.
  494. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  495. \end{description}}
  496. {\seep{Execve}, \seep{Execv}, \seep{Execle},
  497. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execvp}{3} }
  498. \input{linuxex/ex9.tex}
  499. \procedure{Execl}
  500. {(Path : pathstr)}
  501. {
  502. Replaces the currently running program with the program, specified in
  503. \var{path}. Path is split into a command and it's options.
  504. The executable in \var{path} is NOT searched in the path.
  505. The current environment is passed to the program.
  506. On success, \var{execl} does not return.
  507. }
  508. {Errors are reported in \var{LinuxError}:
  509. \begin{description}
  510. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  511. A compononent of the path has no search permission.
  512. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  513. \item[sys\_e2big] Argument list too big.
  514. \item[sys\_enoexec] The magic number in the file is incorrect.
  515. \item[sys\_enoent] The file does not exist.
  516. \item[sys\_enomem] Not enough memory for kernel, or to split command line.
  517. \item[sys\_enotdir] A component of the path is not a directory.
  518. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  519. \end{description}}
  520. {\seep{Execve}, \seep{Execv}, \seep{Execvp}, \seep{Execle},
  521. \seep{Execlp}, \seef {Fork}, \seem{execvp}{3} }
  522. \input{linuxex/ex10.tex}
  523. \procedure{Execle}
  524. {(Path : pathstr, Ep : ppchar)}
  525. {
  526. Replaces the currently running program with the program, specified in
  527. \var{path}. Path is split into a command and it's options.
  528. The executable in \var{path} is searched in the path, if it isn't
  529. an absolute filename.
  530. The environment in \var{ep} is passed to the program.
  531. On success, \var{execle} does not return.
  532. }
  533. {Errors are reported in \var{LinuxError}:
  534. \begin{description}
  535. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  536. A compononent of the path has no search permission.
  537. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  538. \item[sys\_e2big] Argument list too big.
  539. \item[sys\_enoexec] The magic number in the file is incorrect.
  540. \item[sys\_enoent] The file does not exist.
  541. \item[sys\_enomem] Not enough memory for kernel, or to split command line.
  542. \item[sys\_enotdir] A component of the path is not a directory.
  543. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  544. \end{description}}
  545. {\seep{Execve}, \seep{Execv}, \seep{Execvp},
  546. \seep{Execl}, \seep{Execlp}, \seef {Fork}, \seem{execvp}{3} }
  547. \input{linuxex/ex11.tex}
  548. \procedure{Execlp}
  549. {(Path : pathstr)}
  550. {
  551. Replaces the currently running program with the program, specified in
  552. \var{path}. Path is split into a command and it's options.
  553. The executable in \var{path} is searched in the path, if it isn't
  554. an absolute filename.
  555. The current environment is passed to the program.
  556. On success, \var{execlp} does not return.
  557. }
  558. {Errors are reported in \var{LinuxError}:
  559. \begin{description}
  560. \item[sys\_eacces] File is not a regular file, or has no execute permission.
  561. A compononent of the path has no search permission.
  562. \item[sys\_eperm] The file system is mounted \textit{noexec}.
  563. \item[sys\_e2big] Argument list too big.
  564. \item[sys\_enoexec] The magic number in the file is incorrect.
  565. \item[sys\_enoent] The file does not exist.
  566. \item[sys\_enomem] Not enough memory for kernel, or to split command line.
  567. \item[sys\_enotdir] A component of the path is not a directory.
  568. \item[sys\_eloop] The path contains a circular reference (via symlinks).
  569. \end{description}}
  570. {\seep{Execve}, \seep{Execv}, \seep{Execvp}, \seep{Execle},
  571. \seep{Execl}, \seef {Fork}, \seem{execvp}{3} }
  572. \input{linuxex/ex12.tex}
  573. \function{Fork}{}{Longint}
  574. {
  575. Fork creates a child process which is a copy of the parent process.
  576. Fork returns the process ID in the parent process, and zero in the child's
  577. process. (you can get the parent's PID with \seef{GetPPid}).
  578. }
  579. {On error, -1 is returned to the parent, and no child is created.
  580. \begin{description}
  581. \item [sys\_eagain] Not enough memory to create child process.
  582. \end{description}
  583. }
  584. {\seep{Execve}, \seem{fork}{2}}
  585. \input{linuxex/ex14.tex}
  586. \function{Shell}{(Command : String)}{Longint}
  587. {\var{Shell} invokes the bash shell (\file{/bin/sh}), and feeds it the
  588. command \var{Command} (using the \var{-c} option). The function then waits
  589. for the command to complete, and then returns the exit
  590. status of the command, or 127 if it could not complete the \seef{Fork}
  591. or \seep{Execve} calls.
  592. }
  593. {Errors are reported in LinuxError.}
  594. {\seep{POpen}, \seef{Fork}, \seep{Execve}, \seem{system}{3}}
  595. \input{linuxex/ex56.tex}
  596. \procedure{Nice}{( N : Integer)}
  597. {Nice adds \var{-N} to the priority of the running process. The lower the
  598. priority numerically, the less the process is favored.
  599. Only the superuser can specify a negative \var{N}, i.e. increase the rate at
  600. which the process is run.
  601. }
  602. { Errors are returned in \var{LinuxError}
  603. \begin{description}
  604. \item [sys\_eperm] A non-superuser tried to specify a negative \var{N}, i.e.
  605. do a priority increase.
  606. \end{description}
  607. }{\seef{GetPriority}, \seef{SetPriority}, \seem{Nice}{2}}
  608. \input{linuxex/ex15.tex}
  609. \function{GetPriority}{(Which,Who : Integer)}{Integer}
  610. {
  611. GetPriority returns the priority with which a process is running.
  612. Which process(es) is determined by the \var{Which} and \var{Who} variables.
  613. \var{Which} can be one of the pre-defined \var{Prio\_Process, Prio\_PGrp,
  614. Prio\_User}, in which case \var{Who} is the process ID, Process group ID or
  615. User ID, respectively.
  616. }
  617. {
  618. Error checking must be done on LinuxError, since a priority can be negative.
  619. \begin{description}
  620. \item[sys\_esrch] No process found using \var{which} and \var{who}.
  621. \item[sys\_einval] \var{Which} was not one of \var{Prio\_Process, Prio\_Grp
  622. or Prio\_User}.
  623. \end{description}
  624. }
  625. {\seef{SetPriority}, \seep{Nice}, \seem{Getpriority}{2}}
  626. For an example, see \seep{Nice}.
  627. \function{SetPriority}{(Which,Who,Prio : Integer)}{Integer}
  628. {
  629. SetPriority sets the priority with which a process is running.
  630. Which process(es) is determined by the \var{Which} and \var{Who} variables.
  631. \var{Which} can be one of the pre-defined \var{Prio\_Process, Prio\_PGrp,
  632. Prio\_User}, in which case \var{Who} is the process ID, Process group ID or
  633. User ID, respectively.
  634. \var{Prio} is a value in the range -20 to 20.
  635. }
  636. {
  637. Error checking must be done on LinuxError, since a priority can be negative.
  638. \begin{description}
  639. \item[sys\_esrch] No process found using \var{which} and \var{who}.
  640. \item[sys\_einval] \var{Which} was not one of \var{Prio\_Process, Prio\_Grp
  641. or Prio\_User}.
  642. \item[sys\_eperm] A process was found, but neither its effective or real
  643. user ID match the effective user ID of the caller.
  644. \item [sys\_eacces] A non-superuser tried to a priority increase.
  645. \end{description}
  646. }
  647. {\seef{GetPriority}, \seep{Nice}, \seem{Setpriority}{2}}
  648. For an example, see \seep{Nice}.
  649. \function{GetPid}{}{Longint}
  650. { Get the Process ID of the currently running process.}
  651. {None.}
  652. {\seef{GetPPid}, \seem{getpid}{2}}
  653. \input{linuxex/ex16.tex}
  654. \function{GetPPid}{}{Longint}
  655. { Get the Process ID of the parent process.}
  656. {None.}
  657. {\seef{GetPid}, \seem{getppid}{2}}
  658. \input{linuxex/ex16.tex}
  659. \function{GetUid}{}{Longint}
  660. { Get the real user ID of the currently running process.}
  661. {None.}
  662. {\seef{GetEUid}, \seem{getuid}{2} }
  663. \input{linuxex/ex17.tex}
  664. \function{GetEUid}{}{Longint}
  665. { Get the effective user ID of the currently running process.}
  666. {None.}
  667. {\seef{GetEUid}, \seem{geteuid}{2} }
  668. \input{linuxex/ex17.tex}
  669. \function{GetGid}{}{Longint}
  670. { Get the real group ID of the currently running process.}
  671. {None.}
  672. {\seef{GetEGid}, \seem{getgid}{2} }
  673. \input{linuxex/ex18.tex}
  674. \function{GetEGid}{}{Longint}
  675. { Get the effective group ID of the currently running process.}
  676. {None.}
  677. {\seef{GetGid}, \seem{getegid}{2} }
  678. \input{linuxex/ex18.tex}
  679. \function{IOperm}{(From,Num : Cadinal; Value : Longint)}{boolean}
  680. {\var{IOperm}
  681. sets permissions on \var{Num} ports starting with port \var{From} to
  682. \var{Value}. The function returns \var{True} if the call was successfull,
  683. \var{False} otherwise. \var{Value} is as in \var{}
  684. {\em Remark:}
  685. \begin{itemize}
  686. \item This works ONLY as root.
  687. \item Only the first \var{$03ff} ports can be set.
  688. \item When doing a \seef{Fork}, the permissions are reset. When doing a
  689. \seep{Execve} they are kept.
  690. \end{itemize}
  691. }
  692. {Errors are returned in \var{LinuxError}}{\seem{ioperm}{2}}
  693. \function{Link}{(OldPath,NewPath : pathstr)}{Boolean}
  694. {\var{Link} makes \var{NewPath} point to the same file als \var{OldPath}. The two files
  695. then have the same inode number. This is known as a 'hard' link.
  696. The function returns \var{True} if the call was succesfull, \var{False} if the call
  697. failed.
  698. }
  699. { Errors are returned in \var{LinuxError}.
  700. \begin{description}
  701. \item[sys\_exdev] \var {OldPath} and \var {NewPath} are not on the same
  702. filesystem.
  703. \item[sys\_eperm] The filesystem containing oldpath and newpath doesn't
  704. support linking files.
  705. \item[sys\_eaccess] Write access for the directory containing \var{Newpath}
  706. is disallowed, or one of the directories in \var{OldPath} or {NewPath} has no
  707. search (=execute) permission.
  708. \item[sys\_enoent] A directory entry in \var{OldPath} or \var{NewPath} does
  709. not exist or is a symbolic link pointing to a non-existent directory.
  710. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  711. nor a directory.
  712. \item[sys\_enomem] Insufficient kernel memory.
  713. \item[sys\_erofs] The files are on a read-only filesystem.
  714. \item[sys\_eexist] \var{NewPath} already exists.
  715. \item[sys\_emlink] \var{OldPath} has reached maximal link count.
  716. \item[sys\_eloop] \var{OldPath} or \var{NewPath} has a reference to a circular
  717. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  718. \item[sys\_enospc] The device containing \var{NewPath} has no room for anothe
  719. entry.
  720. \item[sys\_eperm] \var{OldPath} points to . or .. of a directory.
  721. \end{description}
  722. }
  723. {\seef{SymLink}, \seef{UnLink}, \seem{Link}{2} }
  724. \input{linuxex/ex21.tex}
  725. \function{SymLink}{(OldPath,NewPath : pathstr)}{Boolean}
  726. {\var{SymLink} makes \var{Newpath} point to the file in \var{OldPath}, which doesn't
  727. necessarily exist. The two files DO NOT have the same inode number.
  728. This is known as a 'soft' link.
  729. The permissions of the link are irrelevant, as they are not used when
  730. following the link. Ownership of the file is only checked in case of removal
  731. or renaming of the link.
  732. The function returns \var{True} if the call was succesfull, \var{False} if the call
  733. failed.
  734. }
  735. { Errors are returned in \var{LinuxError}.
  736. \begin{description}
  737. \item[sys\_eperm] The filesystem containing oldpath and newpath doesn't
  738. support linking files.
  739. \item[sys\_eaccess] Write access for the directory containing \var{Newpath}
  740. is disallowed, or one of the directories in \var{OldPath} or {NewPath} has no
  741. search (=execute) permission.
  742. \item[sys\_enoent] A directory entry in \var{OldPath} or \var{NewPath} does
  743. not exist or is a symbolic link pointing to a non-existent directory.
  744. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  745. nor a directory.
  746. \item[sys\_enomem] Insufficient kernel memory.
  747. \item[sys\_erofs] The files are on a read-only filesystem.
  748. \item[sys\_eexist] \var{NewPath} already exists.
  749. \item[sys\_eloop] \var{OldPath} or \var{NewPath} has a reference to a circular
  750. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  751. \item[sys\_enospc] The device containing \var{NewPath} has no room for anothe
  752. entry.
  753. \end{description}
  754. }
  755. {\seef{Link}, \seef{UnLink}, \seem{Symlink}{2} }
  756. \input{linuxex/ex22.tex}
  757. \function{UnLink}{(Var Path)}{Boolean}
  758. {
  759. \var{UnLink} decreases the link count on file \var{Path}. \var{Path} can be
  760. of type \var{PathStr} or \var{PChar}. If the link count is zero, the
  761. file is removed from the disk.
  762. The function returns \var{True} if the call was succesfull, \var{False} if the call
  763. failed.
  764. }
  765. { Errors are returned in \var{LinuxError}.
  766. \begin{description}
  767. \item[sys\_eaccess] You have no write access right in the directory
  768. containing \var{Path}, or you have no search permission in one of the
  769. directory components of \var{Path}.
  770. \item[sys\_eperm] The directory containing pathname has the sticky-bit
  771. set and the process's effective uid is neither the uid of the
  772. file to be deleted nor that of the directory containing it.
  773. \item[sys\_enoent] A component of the path doesn't exist.
  774. \item[sys\_enotdir] A directory component of the path is not a directory.
  775. \item[sys\_eisdir] \var{Path} refers to a directory.
  776. \item[sys\_enomem] Insufficient kernel memory.
  777. \item[sys\_erofs] \var{Path} is on a read-only filesystem.
  778. \end{description}
  779. }
  780. {\seef{Link}, \seef{SymLink}, \seem{Unlink}{2} }
  781. For an example, see \seef{Link}.
  782. \function{Chown}{(Path : Pathstr;NewUid,NewGid : Longint)}{Boolean}
  783. { \var{Chown} sets the User ID and Group ID of the file in \var{Path} to \var{NewUid,
  784. NewGid}.
  785. The function returns \var{True} if the call was succesfull, \var{False} if the call
  786. failed.
  787. }
  788. {
  789. Errors are returned in \var{LinuxError}.
  790. \begin{description}
  791. \item[sys\_eperm] The effective UID doesn't match the ownership of the file,
  792. and is not zero. Owner or group were not specified correctly.
  793. \item[sys\_eaccess] One of the directories in \var{Path} has no
  794. search (=execute) permission.
  795. \item[sys\_enoent] A directory entry in \var{Path} does
  796. not exist or is a symbolic link pointing to a non-existent directory.
  797. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  798. nor a directory.
  799. \item[sys\_enomem] Insufficient kernel memory.
  800. \item[sys\_erofs] The file is on a read-only filesystem.
  801. \item[sys\_eloop] \var{Path} has a reference to a circular
  802. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  803. \end{description}
  804. }
  805. {\seef{Chmod}, \seef{Access}, \seem{Chown}(2)}
  806. \input{linuxex/ex24.tex}
  807. \function{Chmod}{(Path : Pathstr;NewMode : Longint)}{Boolean}
  808. { \var{Chmod}
  809. Sets the Mode bits of the file in \var{Path} to \var{NewMode}. Newmode can be
  810. specified by 'or'-ing the following:
  811. \begin{description}
  812. \item[S\_ISUID] Set user ID on execution.
  813. \item[S\_ISGID] Set Group ID on execution.
  814. \item[S\_ISVTX] Set sticky bit.
  815. \item[S\_IRUSR] Read by owner.
  816. \item[S\_IWUSR] Write by owner.
  817. \item[S\_IXUSR] Execute by owner.
  818. \item[S\_IRGRP] Read by group.
  819. \item[S\_IWGRP] Write by group.
  820. \item[S\_IXGRP] Execute by group.
  821. \item[S\_IROTH] Read by others.
  822. \item[S\_IWOTH] Write by others.
  823. \item[S\_IXOTH] Execute by others.
  824. \item[S\_IRWXO] Read, write, execute by others.
  825. \item[S\_IRWXG] Read, write, execute by groups.
  826. \item[S\_IRWXU] Read, write, execute by user.
  827. \end{description}
  828. }
  829. {
  830. Errors are returned in \var{LinuxError}.
  831. \begin{description}
  832. \item[sys\_eperm] The effective UID doesn't match the ownership of the file,
  833. and is not zero. Owner or group were not specified correctly.
  834. \item[sys\_eaccess] One of the directories in \var{Path} has no
  835. search (=execute) permission.
  836. \item[sys\_enoent] A directory entry in \var{Path} does
  837. not exist or is a symbolic link pointing to a non-existent directory.
  838. \item[sys\_enotdir] A directory entry in \var{OldPath} or \var{NewPath} is
  839. nor a directory.
  840. \item[sys\_enomem] Insufficient kernel memory.
  841. \item[sys\_erofs] The file is on a read-only filesystem.
  842. \item[sys\_eloop] \var{Path} has a reference to a circular
  843. symbolic link, i.e. a symbolic link, whose expansion points to itself.
  844. \end{description}
  845. }
  846. {\seef{Chown}, \seef{Access}, \seem{Chmod}(2)}
  847. \input{linuxex/ex23.tex}
  848. \function{Utime}{(path : pathstr; utim : utimbuf)}{Boolean}
  849. {
  850. \var{Utime} sets the access and modification times of a file.
  851. the \var{utimbuf} record contains 2 fields, \var{actime}, and \var{modtime},
  852. both of type Longint. They should be filled with an epoch-like time,
  853. specifying, respectively, the last access time, and the last modification
  854. time.
  855. For some filesystem (most notably, FAT), these times are the same.
  856. }
  857. {Errors are returned in \var{LinuxError}.
  858. \begin{description}
  859. \item[sys\_eaccess] One of the directories in \var{Path} has no
  860. search (=execute) permission.
  861. \item[sys\_enoent] A directory entry in \var{Path} does
  862. not exist or is a symbolic link pointing to a non-existent directory.
  863. \end{description}
  864. Other errors may occur, but aren't documented.
  865. }
  866. {\seef{GetEpochTime}, \seef{Chown}, \seef{Access}, \seem{utime}(2)}
  867. \input{linuxex/ex25.tex}
  868. \function{Umask}{(Mask : Integer)}{Integer}
  869. {
  870. Change the file creation mask for the current user to \var{Mask}. The
  871. current mask is returned.
  872. }
  873. {None}
  874. {\seef{Chmod}, \seem{Umask}{2}}
  875. \input{linuxex/ex27.tex}
  876. \function{Access}{(Path : Pathstr; Mode : integer)}{Boolean}
  877. {
  878. Tests user's access rights on the specified file. Mode is a mask existing of
  879. one or more of
  880. \begin{description}
  881. \item[R\_OK] User has read rights.
  882. \item[W\_OK] User has write rights.
  883. \item[X\_OK] User has execute rights.
  884. \item[F\_OK] User has search rights in the directory where the file is.
  885. \end{description}
  886. The test is done with the real user ID, instead of the effective user ID.
  887. If access is denied, or an error occurred, false is returned.
  888. }
  889. { \var{LinuxError} is used to report errors:
  890. \begin{description}
  891. \item[sys\_eaccess] The requested access is denied, either to the file or one
  892. of the directories in its path.
  893. \item[sys\_einval] \var{Mode} was incorrect.
  894. \item[sys\_enoent] A directory component in \var{Path} doesn't exist or is a
  895. dangling symbolic link.
  896. \item[sys\_enotdir] A directory component in \var{Path} is not a directory.
  897. \item[sys\_enomem] Insufficient kernel memory.
  898. \item[sys\_eloop] \var{Path} has a circular symbolic link.
  899. \end{description}
  900. }
  901. {\seef{Chown}, \seef{Chmod}, \seem{Access}{2} }
  902. \input{linuxex/ex26.tex}
  903. \function{FStat}{(Path : Pathstr; Var Info : stat)}{Boolean}
  904. {
  905. \var{FStat} gets information about the file specified in \var{Path}, and stores it in
  906. \var{Info}, which is of type \var{stat}.
  907. The function returns \var{True} if the call was succesfull, \var{False} if the call
  908. failed.
  909. }
  910. { \var{LinuxError} is used to report errors.
  911. \begin{description}
  912. \item[sys\_enoent] \var{Path} does not exist.
  913. \end{description}
  914. }
  915. {\seef{FSStat}, \seef{LStat}, \seem{stat}{2}}
  916. \input{linuxex/ex28.tex}
  917. \function{LStat}{(Path : Pathstr; Var Info : stat)}{Boolean}
  918. {
  919. \var{LStat} gets information about the link specified in \var{Path}, and stores it in
  920. \var{Info}, which is of type \var{stat}. Contrary to \var{FStat}, it stores
  921. information about the link, not about the file the link points to.
  922. The function returns \var{True} if the call was succesfull, \var{False} if the call
  923. failed.
  924. }
  925. { \var{LinuxError} is used to report errors.
  926. \begin{description}
  927. \item[sys\_enoent] \var{Path} does not exist.
  928. \end{description}
  929. }
  930. {\seef{FStat}, \seef{FSStat}, \seem{stat}{2}}
  931. \input{linuxex/ex29.tex}
  932. \function{FSStat}{(Path : Pathstr; Var Info : statfs)}{Boolean}
  933. { Return in \var{Info} information about the filesystem on which the file
  934. \var{Path} resides. Info is of type \var{statfs}.
  935. The function returns \var{True} if the call was succesfull, \var{False} if the call
  936. failed.
  937. }
  938. { \var{LinuxError} is used to report errors.
  939. \begin{description}
  940. \item[sys\_enotdir] A component of \var{Path} is not a directory.
  941. \item[sys\_einval] Invalid character in \var{Path}.
  942. \item[sys\_enoent] \var{Path} does not exist.
  943. \item[sys\_eaccess] Search permission is denied for component in
  944. \var{Path}.
  945. \item[sys\_eloop] A circular symbolic link was encountered in \var{Path}.
  946. \item[sys\_eio] An error occurred while reading from the filesystem.
  947. \end{description}
  948. }
  949. {\seef{FStat}, \seef{LStat}, \seem{statfs}{2}}
  950. \input{linuxex/ex30.tex}
  951. \procedure{IOCtl}{(Handle,Ndx: Longint; Data: Pointer)}
  952. {
  953. This is a general interface to the Unix/ \linux ioctl call.
  954. It performs various operations on the filedescriptor \var{Handle}.
  955. \var{Ndx} describes the operation to perform.
  956. \var{Data} points to data needed for the \var{Ndx} function.
  957. The structure of this data is function-dependent, so we don't elaborate on
  958. this here.
  959. For more information on this, see various manual pages under linux.
  960. }
  961. {
  962. Errors are reported in LinuxError. They are very dependent on the used
  963. function, that's why we don't list them here
  964. }
  965. {\seem{ioctl}{2}}
  966. \input{linuxex/ex54.tex}
  967. \function{IsATTY}{(var f)}{Boolean};
  968. {
  969. Check if the filehandle described by \var{f} is a terminal.
  970. f can be of type
  971. \begin{enumerate}
  972. \item \var{longint} for file handles;
  973. \item \var{Text} for \var{text} variables such as \var{input} etc.
  974. \end{enumerate}
  975. Returns \var{True} if \var{f} is a terminal, \var{False} otherwise.
  976. }
  977. {No errors are reported}
  978. {\seep{IOCtl},\seef{TTYName}}
  979. \function{TTYName}{(var f)}{String}
  980. {
  981. Returns the name of the terminal pointed to by \var{f}. \var{f}
  982. must be a terminal. \var{f} can be of type:
  983. \begin{enumerate}
  984. \item \var{longint} for file handles;
  985. \item \var{Text} for \var{text} variables such as \var{input} etc.
  986. \end{enumerate}
  987. }
  988. { Returns an empty string in case of an error. \var{Linuxerror} may be set
  989. to indicate what error occurred, but this is uncertain.}
  990. {\seef{IsATTY},\seep{IOCtl}}
  991. \function{FExpand}{(Const Path: Pathstr)}{pathstr}
  992. { Expands \var {Path} to a full path, starting from root,
  993. eliminating directory references such as . and .. from the result.
  994. }
  995. {None}
  996. {\seef{BaseName},\seef{DirName} }
  997. \input{linuxex/ex45.tex}
  998. \function{FSearch}{(Path : pathstr;DirList : string)}{Pathstr}
  999. { Searches in \var{DirList}, a colon separated list of directories,
  1000. for a file named \var{Path}. It then returns a path to the found file.}
  1001. {An empty string if no such file was found.}
  1002. {\seef{BaseName}, \seef{DirName}, \seef{FExpand} }
  1003. \input{linuxex/ex46.tex}
  1004. \function{BaseName}{(Const Path;Suf : Pathstr)}{Pathstr}
  1005. {Returns the filename part of \var{Path}, stripping off \var{Suf} if it
  1006. exists.
  1007. The filename part is the whole name if \var{Path} contains no slash,
  1008. or the part of \var{Path} after the last slash.
  1009. The last character of the result is not a slash, unless the directory is the
  1010. root directory.
  1011. }
  1012. {None.}
  1013. {\seef{DirName}, \seef{FExpand}, \seem{Basename}{1}}
  1014. \input{linuxex/ex48.tex}
  1015. \function{DirName}{(Const Path : Pathstr)}{Pathstr}
  1016. {Returns the directory part of \var{Path}.
  1017. The directory is the part of \var{Path} before the last slash,
  1018. or empty if there is no slash.
  1019. The last character of the result is not a slash, unless the directory is the
  1020. root directory.
  1021. }
  1022. {None.}
  1023. {\seef{BaseName}, \seef{FExpand}, \seem{Dirname}{1}}
  1024. \input{linuxex/ex47.tex}
  1025. \function{Glob}{(Const Path : Pathstr)}{PGlob}
  1026. {
  1027. Glob returns a pointer to a glob structure which contains all filenames which
  1028. exist and match the pattern in \var{Path}.
  1029. The pattern can contain wildcard characters, which have their
  1030. usual meaning.
  1031. The pglob structure is defined as :
  1032. Some more text.
  1033. }
  1034. { Returns nil on error, and \var{LinuxError} is set.
  1035. \begin{description}
  1036. \item[sys\_enomem] No memory on heap for glob structure.
  1037. \item[others] As returned by the opendir call, and sys\_readdir.
  1038. \end{description}
  1039. }
  1040. {\seep{GlobFree}, \seem{Glob}{3} }
  1041. \input{linuxex/ex49.tex}
  1042. \procedure{GlobFree}{(Var P : Pglob)}
  1043. {Releases the memory, occupied by a pglob structure. \var{P} is set to nil.}{None}
  1044. { \seef{Glob} }
  1045. For an example, see \seef{Glob}.
  1046. \procedure{AssignPipe}{(Pipe\_in, Pipe\_out : Text)}
  1047. {\var{AssignePipe} creates a pipe, i.e. two file objects, one for input, one for output.
  1048. What is written to \var{Pipe\_out}, can be read from \var{Pipe\_in}.
  1049. Reading and writing happens through the usual \var{Readln(Pipe\_in,...)} and
  1050. \var{Writeln (Pipe\_out,...)} procedures.
  1051. }
  1052. { \var{LinuxError} is used to report errors:
  1053. \begin{description}
  1054. \item[sys\_emfile] Too many file descriptors for this process.
  1055. \item[sys\_enfile] The system file table is full.
  1056. \end{description}
  1057. }
  1058. {\seep{POpen}, \seef{MkFifo}, \seem{pipe}{2}}
  1059. \input{linuxex/ex36.tex}
  1060. \function{MkFifo}{(PathName: String; Mode : Longint)}{Boolean}
  1061. {\var{MkFifo} creates named a named pipe in the filesystem, with name
  1062. \var{PathName} and mode {Mode}.
  1063. }
  1064. { \var{LinuxError} is used to report errors:
  1065. \begin{description}
  1066. \item[sys\_emfile] Too many file descriptors for this process.
  1067. \item[sys\_enfile] The system file table is full.
  1068. \end{description}
  1069. }
  1070. {\seep{POpen}, \seef{MkFifo}, \seem{mkfifo}{4}}
  1071. \procedure{AssignStream}{(StreamIn,StreamOut : Text; Const prog : String)}
  1072. {\var{AssignStream} creates a 2 pipes, i.e. two file objects, one for input, one for
  1073. output, the other ends of these pipes are connected to standard input and and
  1074. output of \var{Prog}. \var{Prog} is the name of a program (including path)
  1075. with options, which will be executed.
  1076. What is written to \var{StreamOut}, will go to the standard input of
  1077. \var{Prog}. Whatever is written by \var{Prog} to it's standard output be read from
  1078. \var{StreamIn}.
  1079. Reading and writing happens through the usual \var{Readln(StreamIn,...)} and
  1080. \var{Writeln (StreamOut,...)} procedures.
  1081. }
  1082. { \var{LinuxError} is used to report errors:
  1083. \begin{description}
  1084. \item[sys\_emfile] Too many file descriptors for this process.
  1085. \item[sys\_enfile] The system file table is full.
  1086. \end{description}
  1087. Other errors include the ones by the fork and exec programs
  1088. }
  1089. {\seep{AssignPipe}, \seep{POpen},\seem{pipe}{2}}
  1090. \input{linuxex/ex38.tex}
  1091. \procedure {POpen}{(Var F : FileType; Cmd : pathstr; rw : char)}
  1092. { Popen runs the command specified in \var{Cmd},
  1093. and redirects the standard in or output of the
  1094. command to the other end of the pipe \var{F}. The parameter \var{rw}
  1095. indicates the direction of the pipe. If it is set to \var{'W'}, then F can
  1096. be used to write data, which will then be read by the command from stdinput.
  1097. If it is set to \var{'R'}, then the standard output of the command can be
  1098. read from \var{F}. \var{F} should be reset or rewritten prior to using it.
  1099. \var{F} can be of type \var{Text} or \var{File}.
  1100. A file opened with \var {POpen} can be closed with \var{Close}, but also
  1101. with \seef{PClose}. The result is the same, but \var{PClose} returns the
  1102. exit status of the command \var{Cmd}.}
  1103. {Errors are reported in \var{LinuxError} and are essentially those of the
  1104. Execve, Dup and AssignPipe commands.
  1105. }
  1106. {\seep{AssignPipe}, \seem{popen}{3}, \seef{PClose}}
  1107. \input{linuxex/ex37.tex}
  1108. \function{PClose}{(Var F : FileType)}{longint}
  1109. { \var{PClose} closes a file opened with \var{POpen}. It waits for the
  1110. command to complete, and then returns the exit status of the command.
  1111. }
  1112. {\var{LinuxError} is used to report errors. If it is different from zero,
  1113. the exit status is not valid.}
  1114. {\seep{POpen}}
  1115. For an example, see \seep{POpen}
  1116. \function{Fcntl}{(Fd : text, Cmd : Integer)}{Integer}
  1117. {
  1118. Read a file's attributes. \var{Fd} is an assigned file.
  1119. \var{Cmd} speciefies what to do, and is one of the following:
  1120. \begin{description}
  1121. \item[F\_GetFd] Read the close\_on\_exec flag. If the low-order bit is 0, then
  1122. the file will remain open across execve calls.
  1123. \item[F\_GetFl] Read the descriptor's flags.
  1124. \item[F\_GetOwn] Get the Process ID of the owner of a socket.
  1125. \end{description}
  1126. }
  1127. {
  1128. \var{LinuxError} is used to report errors.
  1129. \begin{description}
  1130. \item[sys\_ebadf] \var{Fd} has a bad file descriptor.
  1131. \end{description}
  1132. }
  1133. {\seep{Fcntl}, \seem{Fcntl}{2} }
  1134. \procedure{Fcntl}{(Fd : text, Cmd : Integer; Arg : longint)}
  1135. {
  1136. Read or Set a file's attributes. \var{Fd} is an assigned file.
  1137. \var{Cmd} speciefies what to do, and is one of the following:
  1138. \begin{description}
  1139. \item[F\_SetFd] Set the close\_on\_exec flag of \var{Fd}. (only the least
  1140. siginificant bit is used).
  1141. \item[F\_GetLk] Return the \var{flock} record that prevents this process from
  1142. obtaining the lock, or set the \var{l\_type} field of the lock of there is no
  1143. obstruction. Arg is a pointer to a flock record.
  1144. \item[F\_SetLk] Set the lock or clear it (depending on \var{l\_type} in the
  1145. \var{flock} structure). if the lock is held by another process, an error
  1146. occurs.
  1147. \item[F\_GetLkw] Same as for \textbf{F\_Setlk}, but wait until the lock is
  1148. released.
  1149. \item[F\_SetOwn] Set the Process or process group that owns a socket.
  1150. \end{description}
  1151. }
  1152. {
  1153. \var{LinuxError} is used to report errors.
  1154. \begin{description}
  1155. \item[sys\_ebadf] \var{Fd} has a bad file descriptor.
  1156. \item[sys\_eagain or sys\_eaccess] For \textbf{F\_SetLk}, if the lock is
  1157. held by another process.
  1158. \end{description}
  1159. }
  1160. {\seef{Fcntl}, \seem{Fcntl}{2} }
  1161. \procedure{Dup}{(Var OldFile, NewFile : Text)}
  1162. {
  1163. Makes \var{NewFile} an exact copy of \var{OldFile}, after having flushed the
  1164. buffer of \var{OldFile}. Due to the buffering mechanism of Pascal, this has not
  1165. the same functionality as the \seem{dup}{2} call in C. The internal Pascal
  1166. buffers are not the same after this call, but when the buffers are flushed
  1167. (e.g. after output), the output is sent to the same file.
  1168. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the
  1169. fileposition in both files.
  1170. }
  1171. { \var{Linuxerror} is used to report errors.
  1172. \begin{description}
  1173. \item[sys\_ebadf] \var{OldFile} hasn't been assigned.
  1174. \item[sys\_emfile] Maximum number of open files for the process is reached.
  1175. \end{description}
  1176. }
  1177. {\seep{Dup2}, \seem{Dup}{2} }
  1178. \input{linuxex/ex31.tex}
  1179. \procedure{Dup2}{(Var OldFile, NewFile : Text)}
  1180. {
  1181. Makes \var{NewFile} an exact copy of \var{OldFile}, after having flushed the
  1182. buffer of \var{OldFile}. \var{NewFile} can be an assigned file.
  1183. If \var{newfile} was open, it is closed first.
  1184. Due to the buffering mechanism of Pascal, this has not
  1185. the same functionality as the \seem{dup2}{2} call in C. The internal Pascal
  1186. buffers are not the same after this call, but when the buffers are flushed
  1187. (e.g. after output), the output is sent to the same file.
  1188. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the
  1189. fileposition in both files.
  1190. }
  1191. { \var{Linuxerror} is used to report errors.
  1192. \begin{description}
  1193. \item[sys\_ebadf] \var{OldFile} hasn't been assigned.
  1194. \item[sys\_emfile] Maximum number of open files for the process is reached.
  1195. \end{description}
  1196. }
  1197. { \seep{Dup}, \seem{Dup2}{2} }
  1198. \input{linuxex/ex32.tex}
  1199. \procedure{SigAction}{(Signum : Integer; Var Act,OldAct : PSigActionRec)}
  1200. { Changes the action to take upon receipt of a signal. \var{Act} and
  1201. \var{Oldact} are pointers to a \var{SigActionRec} record.
  1202. \var{SigNum} specifies the signal, and can be any signal except
  1203. \textbf{SIGKILL} or \textbf{SIGSTOP}.
  1204. If \var{Act} is non-nil, then the new action for signal \var{SigNum} is taken
  1205. from it. If \var{OldAct} is non-nil, the old action is stored there.
  1206. \var{Sa\_Handler} may be \var{SIG\_DFL} for the default action or
  1207. \var{SIG\_IGN} to ignore the signal.
  1208. \var{Sa\_Mask} Specifies which signals should be ignord during the execution
  1209. of the signal handler.
  1210. \var{Sa\_Flags} Speciefies a series of flags which modify the behaviour of
  1211. the signal handler. You can 'or' none or more of the following :
  1212. \begin{description}
  1213. \item[SA\_NOCLDSTOP] If signum is \textbf{SIGCHLD} do not receive
  1214. notification when child processes stop.
  1215. \item[SA\_ONESHOT or SA\_RESETHAND] Restore the signal action to the default
  1216. state once the signal handler has been called.
  1217. \item[SA\_RESTART] For compatibility with BSD signals.
  1218. \item[SA\_NOMASK or SA\_NODEFER] Do not prevent the signal from being received
  1219. from within its own signal handler.
  1220. \end{description}
  1221. }
  1222. {\var{LinuxError} is used to report errors.
  1223. \begin{description}
  1224. \item[sys\_einval] an invalid signal was specified, or it was
  1225. \textbf{SIGKILL} or \textbf{SIGSTOP}.
  1226. \item[sys\_efault] \var{Act,OldAct} point outside this process address space
  1227. \item[sys\_eintr] System call was interrupted.
  1228. \end{description}
  1229. }
  1230. {
  1231. \seep{SigProcMask}, \seef{SigPending}, \seep{SigSuspend}, \seef{Kill},
  1232. \seem{Sigaction}{2}
  1233. }
  1234. \procedure {SigProcMask}{(How : Integer; SSet,OldSSet : PSigSet)}
  1235. {
  1236. Changes the list of currently blocked signals. The behaviour of the call
  1237. depends on \var{How} :
  1238. \begin{description}
  1239. \item[SIG\_BLOCK] The set of blocked signals is the union of the current set
  1240. and the \var{SSet} argument.
  1241. \item[SIG\_UNBLOCK] The signals in \var{SSet} are removed from the set of
  1242. currently blocked signals.
  1243. \item[SIG\_SETMASK] The list of blocked signals is set so \var{SSet}.
  1244. \end{description}
  1245. If \var{OldSSet} is non-nil, then the old set is stored in it.
  1246. }
  1247. {\var{LinuxError} is used to report errors.
  1248. \begin{description}
  1249. \item[sys\_efault] \var{SSet} or \var{OldSSet} point to an adress outside
  1250. the range of the process.
  1251. \item[sys\_eintr] System call was interrupted.
  1252. \end{description}
  1253. }
  1254. {\seep{SigAction}, \seef{SigPending}, \seep{SigSuspend}, \seef{Kill},
  1255. \seem{Sigprocmask}{2} }
  1256. \function{SigPending}{}{SigSet}
  1257. {
  1258. Sigpending allows the examination of pending signals (which have been raised
  1259. while blocked.) The signal mask of pending signals is returned.
  1260. }
  1261. {None}
  1262. {\seep{SigAction}, \seep{SigProcMask}, \seep{SigSuspend}, \seef{Signal},
  1263. \seef{Kill}, \seem{Sigpending}{2} }
  1264. \procedure{SigSuspend}{(Mask : SigSet)}
  1265. {SigSuspend temporarily replaces the signal mask for the process with the one
  1266. given in \var{Mask}, and then suspends the process until a signal is received.
  1267. }
  1268. {None}
  1269. {\seep{SigAction}, \seep{SigProcMask}, \seef{SigPending}, \seef{Signal},
  1270. \seef{Kill}, \seem{SigSuspend}{2} }
  1271. \function{Signal}{(SigNum : Integer; Handler : PSignalHandler)}{PSignalHandler}
  1272. {
  1273. Signal installs a new signal handler for signal \var{SigNum}. This call has
  1274. the same functionality as the \textbf{SigAction} call.
  1275. The return value for Signal is the old signal handler, or nil on error.
  1276. }
  1277. {\var {LinuxError} is used to report errors :
  1278. \begin{description}
  1279. \item[SIG\_ERR] An error occurred.
  1280. \end{description}
  1281. }
  1282. {\seep{SigAction},\seef{Kill}, \seem{Signal}{2} }
  1283. \function{Kill}{Pid : Longint; Sig : Integer)}{Integer}
  1284. { Send a signal \var{Sig} to a process or process group. If \var{Pid}>0 then
  1285. the signal is sent to \var{Pid}, if it equals -1, then the signal is sent to
  1286. all processes except process 1. If \var{Pid}<-1 then the signal is sent to
  1287. process group -Pid.
  1288. The return value is zero, except in case three, where the return value is the
  1289. number of processes to which the signal was sent.
  1290. }
  1291. {\var{LinuxError} is used to report errors:
  1292. \begin{description}
  1293. \item[sys\_einval] An invalid signal is sent.
  1294. \item[sys\_esrch] The \var{Pid} or process group don't exist.
  1295. \item[sys\_eperm] The effective userid of the current process doesn't math
  1296. the one of process \var{Pid}.
  1297. \end{description}
  1298. }
  1299. {\seep{SigAction}, \seef{Signal}, \seem{Kill}{2} }
  1300. \function{GetHostName}{}{String}
  1301. {
  1302. Get the hostname of the machine on which the process is running.
  1303. An empty string is returned if hostname is not set.
  1304. }
  1305. {None.}
  1306. { \seef{GetDomainName},seem{Gethostname}{2} }
  1307. \input{linuxex/ex40.tex}
  1308. \function{GetDomainName}{}{String}
  1309. {
  1310. Get the domain name of the machine on which the process is running.
  1311. An empty string is returned if the domain is not set.
  1312. }
  1313. {None.}
  1314. { \seef{GetHostName},seem{Getdomainname}{2} }
  1315. \input{linuxex/ex39.tex}
  1316. \function{GetEnv}{(P : String)}{PChar}
  1317. {Returns the value of the environment variable in \var{P}. If the variable is
  1318. not defined, nil is returned. The value of the environment variable may be
  1319. the empty string.
  1320. A PChar is returned to accomodate for strings longer than 255 bytes,
  1321. \var{TERMCAP} and \var{LS\_COLORS}, for instance.
  1322. }
  1323. {None.}
  1324. {\seem{sh}{1}, \seem{csh}{1} }
  1325. \input{linuxex/ex41.tex}
  1326. \function{Select}{(N : Longint; \\ var readfds,writefds,exceptfds : PFDset;
  1327. Var Timeout)}{Longint}
  1328. {\var{Select} checks one of the file descriptors in the \var{FDSets} to see if its
  1329. status changed.
  1330. \var{readfds, writefds} and \var{exceptfds} are pointers to arrays of 256
  1331. bits. If you want a file descriptor to be checked, you set the
  1332. corresponding element in the array to 1. The other elements in the array
  1333. must be set to zero. Three arrays are passed : The entries in \var{readfds}
  1334. are checked to see if characters become available for reading. The entries
  1335. in \var{writefds} are checked to see if it is OK to write to them, while
  1336. entries in \var{exceptfds} are cheked to see if an exception occorred on
  1337. them.
  1338. You can use the functions \seepl{FD\_Clear}{FDClear}, \seepl{FD\_Clr}{FDClr},
  1339. \seepl{FD\_Set}{FDSet}, \seefl{FD\_IsSet}{FDIsSet} to manipulate the individual elements of a set.
  1340. The pointers can be nil.
  1341. \var{N} is the largest index of a nonzero entry plus 1. (= the largest
  1342. file-descriptor + 1).
  1343. \var{TimeOut} can be used to set a time limit.
  1344. If \var{TimeOut} can be two types :
  1345. \begin{enumerate}
  1346. \item \var{TimeOut} is of type \var{PTime} and contains a
  1347. zero time, the call returns immediately. If \var{TimeOut} is \var{Nil}, the
  1348. kernel will wait forever, or until a status changed.
  1349. \item \var{TimeOut} is of type \var{Longint}. If it is -1, this has the same
  1350. effect as a \var{Timeout} of type \var{PTime} which is \var{Nil}.
  1351. Otherwise, \var{TimeOut} contains a time in milliseconds.
  1352. \end{enumerate}
  1353. When the TimeOut is reached, or one of the file descriptors has changed,
  1354. the \var{Select} call returns. On return, it will have modified the entries
  1355. in the array which have actually changed, and it returns the number of
  1356. entries that have been changed. If the timout was reached, and no decsriptor
  1357. changed, zero is returned; The arrays of indexes are undefined after that.
  1358. On error, -1 is returned.}
  1359. {On error, the function returns -1, and Errors are reported in LinuxError :
  1360. \begin{description}
  1361. \item[SYS\_EBADF\ ] An invalid descriptot was specified in one of the sets.
  1362. \item[SYS\_EINTR\ ] A non blocked signal was caught.
  1363. \item[SYS\_EINVAL\ ] \var{N} is negative or too big.
  1364. \item[SYS\_ENOMEM\ ] \var{Select} was unable to allocate memory for its
  1365. internal tables.
  1366. \end{description}}
  1367. {\seef{SelectText}, \seef{GetFS},
  1368. \seepl{FD\_Clear}{FDClear},
  1369. \seepl{FD\_Clr}{FDClr},
  1370. \seepl{FD\_Set}{FDSet},
  1371. \seefl{FD\_IsSet}{FDIsSet}}
  1372. \input{linuxex/ex33.tex}
  1373. \function{SelectText}{( var T : Text; TimeOut :PTime)}{Longint}
  1374. {\var{SelectText} executes the \seef{Select} call on a file of type
  1375. \var{Text}. You can specify a timeout in \var{TimeOut}. The SelectText call
  1376. determines itself whether it should check for read or write, depending on
  1377. how the file was opened : With \var{Reset} it is checked for reading, with
  1378. \var{Rewrite} and \var{Append} it is checked for writing.}
  1379. {See \seef{Select}. \var{SYS\_EBADF} can also mean that the file wasn't
  1380. opened.}
  1381. {\seef{Select}, \seef{GetFS}}
  1382. \function{GetFS}{(Var F : Any File Type)}{Longint}
  1383. {\var{GetFS} returns the file selector that the kernel provided for your
  1384. file. In principle you don' need this file selector. Only for some calls
  1385. it is needed, such as the \seef{Select} call or so.}
  1386. {In case the file was not opened, then -1 is returned.}
  1387. {\seef{Select}}
  1388. \input{linuxex/ex34.tex}
  1389. \procedurel{FD\_Clear}{FDClear}{(var fds:fdSet)}
  1390. {\var{FD\_Clear} clears all the filedescriptors in the file descriptor
  1391. set \var{fds}.}
  1392. {None.}
  1393. {\seef{Select},
  1394. \seef{SelectText},
  1395. \seef{GetFS},
  1396. \seepl{FD\_Clr}{FDClr},
  1397. \seepl{FD\_Set}{FDSet},
  1398. \seefl{FD\_IsSet}{FDIsSet}
  1399. }
  1400. For an example, see \seef{Select}.
  1401. \procedurel{FD\_Clr}{FDClr}{(fd:longint;var fds:fdSet)}
  1402. { \var{FD\_Clr} clears file descriptor \var{fd} in filedescriptor s
  1403. et \var{fds}.}
  1404. {None.}
  1405. {\seef{Select},
  1406. \seef{SelectText},
  1407. \seef{GetFS},
  1408. \seepl{FD\_Clear}{FDClear},
  1409. \seepl{FD\_Set}{FDSet},
  1410. \seefl{FD\_IsSet}{FDIsSet}}
  1411. For an example, see \seef{Select}.
  1412. \procedurel{FD\_Set}{FDSet}{(fd:longint;var fds:fdSet)}
  1413. {\var{FD\_Set} sets file descriptor \var{fd} in filedescriptor set \var{fds}.}
  1414. {None.}
  1415. {\seef{Select}, \seef{SelectText}, \seef{GetFS},\seepl{FD\_Clear}{FDClear},
  1416. \seepl{FD\_Clr}{FDClr}, \seefl{FD\_IsSet}{FDIsSet}}
  1417. For an example, see \seef{Select}.
  1418. \functionl{FD\_IsSet}{FDIsSet}{(fd:longint;var fds:fdSet)}{boolean}
  1419. {\var{FD\_Set} Checks whether file descriptor \var{fd} in filedescriptor set \var{fds}
  1420. is set.}
  1421. {None.}
  1422. {\seef{Select}, \seef{SelectText}, \seef{GetFS},
  1423. \seepl{FD\_Clear}{FDClear},
  1424. \seepl{FD\_Clr}{FDClr},
  1425. \seepl{FD\_Set}{FDSet}}
  1426. For an example, see \seef{Select}.
  1427. \function{fdOpen}{(Var PathName;flags:longint[; Mode: longint])}{longint}
  1428. { \var{fdOpen} opens a file in \var{pathname} with flags \var{flags} a ORed combination of
  1429. \var{Open\_Accmode, Open\_RdOnly, Open\_WrOnly, Open\_RdWr, Open\_Creat,
  1430. Open\_Excl, Open\_NoCtty, Open\_Trunc, Open\_Append, Open\_NonBlock,
  1431. Open\_NDelay, Open\_Sync} \var{PathName} can be of type \var{PChar} or
  1432. \var{String}
  1433. The optional \var{mode} argument specifies the permissions to set when opening
  1434. the file. This is modified by the umask setting. The real permissions are
  1435. \var{Mode and not umask}.
  1436. The return value of the function is the filedescriptor, or a negative
  1437. value if there was an error.
  1438. }
  1439. {Errors are returned in LinuxError}
  1440. {\seef{fdClose}, \seef{fdRead}, \seef{fdWrite},\seef{fdTruncate},
  1441. \seef{fdFlush}, \seef{fdSeek}}
  1442. \input{linuxex/ex19.tex}
  1443. \function{fdClose}{(fd:longint)}{boolean}
  1444. {
  1445. \var{fdClose} closes a file with file descriptor \var{Fd}. The function
  1446. returns \var{True} if the file was closed successfully, \var{False}
  1447. otherwise.
  1448. }
  1449. {Errors are returned in LinuxError}
  1450. {\seef{fdOpen}, \seef{fdRead}, \seef{fdWrite},\seef{fdTruncate},
  1451. \seef{fdFlush}, seef{FdSeek}}
  1452. For an example, see \seef{fdOpen}.
  1453. \function{fdRead}{(fd:longint;var buf;size:longint}{longint}
  1454. { \var{fdRead} reads at most \var{size} bytes from the file descriptor
  1455. \var{fd}, and stores them in \var{buf}.
  1456. The function returns the number of bytes actually read, or -1 if
  1457. an error occurred.
  1458. No checking on the length of \var{buf} is done.
  1459. }
  1460. {Errors are returned in LinuxError.}
  1461. {\seef{fdOpen}, \seef{fdClose}, \seef{fdWrite},\seef{fdTruncate},
  1462. \seef{fdFlush}, \seef{fdSeek}}
  1463. \input{linuxex/ex20.tex}
  1464. \function{fdWrite}{(fd:longint;var buf;size:longint}{longint}
  1465. {\var{fdWrite} writes at most \var{size} bytes from \var{buf} to
  1466. file descriptor \var{fd}.
  1467. The function returns the number of bytes actually written, or -1 if an error
  1468. occurred.
  1469. }
  1470. {Errors are returned in LinuxError.}
  1471. {\seef{fdOpen}, \seef{fdClose}, \seef{fdRead},\seef{fdTruncate},
  1472. \seef{fdSeek}, \seef{fdFlush}}
  1473. \function{fdSeek}{(fd,Pos,SeekType:longint}{longint}
  1474. {\var{fdSeek} sets the current fileposition of file \var{fd} to
  1475. \var{Pos}, starting from \var{SeekType}, which can be one of the following:
  1476. \begin{description}
  1477. \item [Seek\_Set] \ \var{Pos} is the absolute position in the file.
  1478. \item [Seek\_Cur] \ \var{Pos} is relative to the current position.
  1479. \item [Seek\_end] \ \var{Pos} is relative to the end of the file.
  1480. \end{description}
  1481. The function returns the new fileposition, or -1 of an error occurred.
  1482. }
  1483. {Errors are returned in LinuxError.}
  1484. {\seef{fdOpen}, \seef{fdWrite}, \seef{fdClose},
  1485. \seef{fdRead},\seef{fdTruncate},
  1486. \seef{fdFlush}}
  1487. For an example, see \seef{fdOpen}.
  1488. \function{fdTruncate}{(fd,size:longint)}{boolean}
  1489. {\var{fdTruncate} sets the length of a file in \var{fd} on \var{size}
  1490. bytes, where \var{size} must be less than or equal to the current length of
  1491. the file in \var{fd}.
  1492. The function returns \var{True} if the call was successful, \var{false} if
  1493. an error occurred.}
  1494. {Errors are returned in LinuxError.}
  1495. {\seef{fdOpen}, \seef{fdClose}, \seef{fdRead},\seef{fdWrite},\seef{fdFlush},
  1496. \seef{fdSeek}}
  1497. \function{fdFlush}{(fd:Longint)}{boolean}
  1498. {\var{fdflush} flushes the Linux kernel file buffer, so the file is actually
  1499. written to disk. This is NOT the same as the internal buffer, maintained by
  1500. Free Pascal.
  1501. The function returns \var{True} if the call was successful, \var{false} if
  1502. an error occurred.}
  1503. {Errors are returned in LinuxError.}
  1504. {\seef{fdOpen}, \seef{fdClose}, \seef{fdRead},\seef{fdWrite},
  1505. \seef{fdTruncate}, \seef{fdSeek}}
  1506. For an example, see \seef{fdRead}.
  1507. \functionl{S\_ISLNK}{ISLNK}{(m:integer)}{boolean}
  1508. { \var{S\_ISLNK} checks the file mode \var{m} to see whether the file is a
  1509. symbolic link. If so it returns \var{True}
  1510. }
  1511. {\seef{FStat},
  1512. \seefl{S\_ISREG}{ISREG},
  1513. \seefl{S\_ISDIR}{ISDIR},
  1514. \seefl{S\_ISCHR}{ISCHR},
  1515. \seefl{S\_ISBLK}{ISBLK},
  1516. \seefl{S\_ISFIFO}{ISFIFO},
  1517. \seefl{S\_ISSOCK}{ISSOCK}
  1518. }
  1519. \input{linuxex/ex53.tex}
  1520. \functionl{S\_ISREG}{ISREG}{(m:integer)}{boolean}
  1521. { \var{S\_ISREG} checks the file mode \var{m} to see whether the file is a
  1522. regular file. If so it returns \var{True}
  1523. }
  1524. {\seef{FStat},
  1525. \seefl{S\_ISLNK}{ISLNK},
  1526. \seefl{S\_ISDIR}{ISDIR},
  1527. \seefl{S\_ISCHR}{ISCHR},
  1528. \seefl{S\_ISBLK}{ISBLK},
  1529. \seefl{S\_ISFIFO}{ISFIFO},
  1530. \seefl{S\_ISSOCK}{ISSOCK}
  1531. }
  1532. For an example, see \seef{ISLNK}.
  1533. \functionl{S\_ISDIR}{ISDIR}{(m:integer)}{boolean}
  1534. { \var{S\_ISDIR} checks the file mode \var{m} to see whether the file is a
  1535. directory. If so it returns \var{True}
  1536. }
  1537. {\seef{FStat},
  1538. \seefl{S\_ISLNK}{ISLNK},
  1539. \seefl{S\_ISREG}{ISREG},
  1540. \seefl{S\_ISCHR}{ISCHR},
  1541. \seefl{S\_ISBLK}{ISBLK},
  1542. \seefl{S\_ISFIFO}{ISFIFO},
  1543. \seefl{S\_ISSOCK}{ISSOCK}
  1544. }
  1545. For an example, see \seef{ISLNK}.
  1546. \functionl{S\_ISCHR}{ISCHR}{(m:integer)}{boolean}
  1547. { \var{S\_ISCHR} checks the file mode \var{m} to see whether the file is a
  1548. character device file. If so it returns \var{True}.
  1549. }
  1550. {\seef{FStat},
  1551. \seefl{S\_ISLNK}{ISLNK},
  1552. \seefl{S\_ISREG}{ISREG},
  1553. \seefl{S\_ISDIR}{ISDIR},
  1554. \seefl{S\_ISBLK}{ISBLK},
  1555. \seefl{S\_ISFIFO}{ISFIFO},
  1556. \seefl{S\_ISSOCK}{ISSOCK}
  1557. }
  1558. For an example, see \seef{ISLNK}.
  1559. \functionl{S\_ISBLK}{ISBLK}{(m:integer)}{boolean}
  1560. { \var{S\_ISBLK} checks the file mode \var{m} to see whether the file is a
  1561. block device file. If so it returns \var{True}.
  1562. }
  1563. {\seef{FStat},
  1564. \seefl{S\_ISLNK}{ISLNK},
  1565. \seefl{S\_ISREG}{ISREG},
  1566. \seefl{S\_ISDIR}{ISDIR},
  1567. \seefl{S\_ISCHR}{ISCHR},
  1568. \seefl{S\_ISFIFO}{ISFIFO},
  1569. \seefl{S\_ISSOCK}{ISSOCK}
  1570. }
  1571. For an example, see \seef{ISLNK}.
  1572. \functionl{S\_ISFIFO}{ISFIFO}{(m:integer)}{boolean}
  1573. { \var{S\_ISFIFO} checks the file mode \var{m} to see whether the file is a
  1574. fifo (a named pipe). If so it returns \var{True}.
  1575. }
  1576. {\seef{FStat},
  1577. \seefl{S\_ISLNK}{ISLNK},
  1578. \seefl{S\_ISREG}{ISREG},
  1579. \seefl{S\_ISDIR}{ISDIR},
  1580. \seefl{S\_ISCHR}{ISCHR},
  1581. \seefl{S\_ISBLK}{ISBLK},
  1582. \seefl{S\_ISSOCK}{ISSOCK}
  1583. }
  1584. For an example, see \seef{ISLNK}.
  1585. \functionl{S\_ISSOCK}{ISSOCK}{(m:integer)}{boolean}
  1586. { \var{S\_ISSOCK} checks the file mode \var{m} to see whether the file is a
  1587. socket. If so it returns \var{True}.
  1588. }
  1589. {\seef{FStat},
  1590. \seefl{S\_ISLNK}{ISLNK},
  1591. \seefl{S\_ISREG}{ISREG},
  1592. \seefl{S\_ISDIR}{ISDIR},
  1593. \seefl{S\_ISCHR}{ISCHR},
  1594. \seefl{S\_ISBLK}{ISBLK},
  1595. \seefl{S\_ISFIFO}{ISFIFO}
  1596. }
  1597. For an example, see \seef{ISLNK}.
  1598. \function{OpenDir}{(f:pchar)}{pdir}
  1599. { \var{OpenDir} opens the directory \var{f}, and returns a \var{pdir}
  1600. pointer to a \var{Dir} record, which can be used to read the directory
  1601. structure. If the directory cannot be opened, \var{nil} is returned.}
  1602. {Errors are returned in LinuxError.}
  1603. {\seef{CloseDir}, \seef{ReadDir}, \seep{SeekDir}, \seef{TellDir},
  1604. \seem{opendir}{3}}
  1605. \input{linuxex/ex35.tex}
  1606. \function{CloseDir}{(p:pdir)}{integer}
  1607. { \var{CloseDir} closes the directory pointed to by \var{p}.
  1608. It returns zero if the directory was closed succesfully, -1 otherwise.}
  1609. {Errors are returned in LinuxError.}
  1610. {\seef{OpenDir}, \seef{ReadDir}, \seep{SeekDir}, \seef{TellDir},
  1611. \seem{closedir}{3}}
  1612. For an example, see \seef{OpenDir}.
  1613. \function{ReadDir}{(p:pdir)}{pdirent}
  1614. {\var{ReadDir} reads the next entry in the directory pointed to by \var{p}.
  1615. It returns a \var{pdirent} pointer to a structure describing the entry.
  1616. If the next entry can't be read, \var{Nil} is returned.
  1617. }
  1618. {Errors are returned in LinuxError.}
  1619. {\seef{CloseDir}, \seef{OpenDir}, \seep{SeekDir}, \seef{TellDir},
  1620. \seem{readdir}{3}}
  1621. For an example, see \seef{OpenDir}.
  1622. \procedure {SeekDir}{(p:pdir;off:longint)}
  1623. { \var{SeekDir} sets the directory pointer to the \var{off}-th entry in the
  1624. directory structure pointed to by \var{p}.}
  1625. {Errors are returned in LinuxError.}
  1626. {\seef{CloseDir}, \seef{ReadDir}, \seef{OpenDir}, \seef{TellDir},
  1627. \seem{seekdir}{3}}
  1628. For an example, see \seef{OpenDir}.
  1629. \function{TellDir}{(p:pdir)}{longint}
  1630. { \var{TellDir} returns the current location in the directory structure
  1631. pointed to by \var{p}. It returns -1 on failure.}
  1632. {Errors are returned in LinuxError.}
  1633. {\seef{CloseDir}, \seef{ReadDir}, \seep{SeekDir}, \seef{OpenDir},
  1634. \seem{telldir}{3}}
  1635. For an example, see \seef{OpenDir}.
  1636. \procedure{Uname}{(var unamerec:utsname)}
  1637. {\var{Uname} gets the name and configuration of the current \linux kernel,
  1638. and returns it in \var{unamerec}.
  1639. }
  1640. {\var{LinuxError} is used to report errors.}
  1641. {\seef{GetHostName}, \seef{GetDomainName}, \seem{uname}{2}}
  1642. \function{WaitPid}{(Pid : longint; Status : pointer; Options : Integer)}{Longint}
  1643. { \var{WaitPid} waits for a child process with process ID \var{Pid} to exit. The
  1644. value of \var{Pid} can be one of the following:
  1645. \begin{description}
  1646. \item[Pid < -1] Causes \var{WaitPid} to wait for any child process whose
  1647. process group ID equals the absolute value of \var{pid}.
  1648. \item[Pid = -1] Causes \var{WaitPid} to wait for any child process.
  1649. \item[Pid = 0] Causes \var{WaitPid} to wait for any child process whose
  1650. process group ID equals the one of the calling
  1651. process.
  1652. \item[Pid > 0] Causes \var{WaitPid} to wait for the child whose process ID
  1653. equals the value of \var{Pid}.
  1654. \end{description}
  1655. The \var{Options} parameter can be used to specify further how \var{WaitPid}
  1656. behaves:
  1657. \begin{description}
  1658. \item [WNOHANG] Causes \var{Waitpid} to return immediately if no child has
  1659. exited.
  1660. \item [WUNTRACED] Causes \var{WaitPid} to return also for children which are
  1661. stopped, but whose status has not yet been reported.
  1662. \end{description}
  1663. Upon return, it returns the exit status of the process, or -1 in case of
  1664. failure.
  1665. }
  1666. {Errors are returned in LinuxError.}
  1667. {\seef{Fork}, \seep{Execve}, \seem{waitpid}{2}}
  1668. for an example, see \seef{Fork}.
  1669. \function{TCGetAttr}{(fd:longint;var tios:TermIOS)}{Boolean}
  1670. { \var{TCGetAttr}
  1671. gets the terminal parameters from the terminal referred to by the file
  1672. descriptor \var{fd} and returns them in a \var{TermIOS} structure \var{tios}.
  1673. The function returns \var{True} if the call was succesfull, \var{False}
  1674. otherwise.
  1675. }
  1676. {Errors are reported in LinuxError}
  1677. {\seef{TCSetAttr}, \seem{termios}{2} }
  1678. \input{linuxex/ex55.tex}
  1679. \function{TCSetAttr}{(Fd:longint;OptAct:longint;var Tios:TermIOS)}{Boolean}
  1680. { \var{TCSetAttr}
  1681. Sets the terminal parameters you specify in a \var{TermIOS} structure
  1682. \var{Tios} for the terminal
  1683. referred to by the file descriptor \var{Fd}. \var{OptAct} specifies an
  1684. optional action when the set need to be done,
  1685. this could be one of the following pre-defined values:
  1686. \begin{description}
  1687. \item [TCSANOW\ ] set immediately.
  1688. \item [TCSADRAIN\ ] wait for output.
  1689. \item [TCSAFLUSH\ ] wait for output and discard all input not yet read.
  1690. \end{description}
  1691. The function Returns \var{True} if the call was succesfull, \var{False}
  1692. otherwise.
  1693. }
  1694. {Errors are reported in LinuxError.}
  1695. {\seef{TCGetAttr}, \seem{termios}{2}}
  1696. For an example, see \seef{TCGetAttr}.
  1697. \procedure{CFSetISpeed}{(var Tios:TermIOS;Speed:Longint)}
  1698. { \var{CFSetISpeed}
  1699. Sets the input baudrate in the \var{TermIOS} structure \var{Tios} to
  1700. \var{Speed}.
  1701. }
  1702. {None.}
  1703. {\seep{CFSetOSpeed}, \seep{CFMakeRaw}, \seem{termios}{2}}
  1704. \procedure{CFSetOSpeed}{(var Tios:TermIOS;Speed:Longint)}
  1705. { \var{CFSetOSpeed}
  1706. Sets the output baudrate in the \var{Termios} structure \var{Tios} to
  1707. \var{Speed}.
  1708. }
  1709. {None.}
  1710. {\seep{CFSetISpeed}, \seep{CFMakeRaw}, \seem{termios}{2}}
  1711. \procedure{CFMakeRaw}{(var Tios:TermIOS)}
  1712. { \var{CFMakeRaw}
  1713. Sets the flags in the \var{Termios} structure \var{Tios} to a state so that
  1714. the terminal will function in Raw Mode.
  1715. }
  1716. {None.}
  1717. { \seep{CFSetOSpeed}, \seep{CFSetISpeed}, \seem{termios}{2}}
  1718. For an example, see \seef{TCGetAttr}.
  1719. \function{TCSendBreak}{(Fd,Duration:longint)}{Boolean}
  1720. { \var{TCSendBreak}
  1721. Sends zero-valued bits on an asynchrone serial connection decsribed by
  1722. file-descriptor \var{Fd}, for duration \var{Duration}.
  1723. The function returns \var{True} if the action was performed successfully,
  1724. \var{False} otherwise.
  1725. }
  1726. {Errors are reported in LinuxError.}
  1727. {\seem{termios}{2}}
  1728. Function TCSetPGrp(Fd,Id:longint):boolean;
  1729. { \var{TCSetPGrp}
  1730. Sets the Process Group Id to \var{Id}.
  1731. The function returns \var{True} if the call was successful, \var{False}
  1732. otherwise.
  1733. }
  1734. {Errors are returned in LinuxError.}
  1735. {\seef{TCGetPGrp}\seem{termios}{2}}
  1736. \function{TCGetPGrp}{(Fd:longint;var Id:longint)}{boolean}
  1737. { \var{TCGetPGrp}
  1738. returns the process group ID of a foreground process group in \var{Id}
  1739. The function returns \var{True} if the call was succesfull, \var{False}
  1740. otherwise
  1741. }
  1742. {Errors are reported in LinuxError}
  1743. {\seem{termios}{2}}
  1744. \function{TCDrain}{(Fd:longint)}{Boolean}
  1745. { \var{TCDrain}
  1746. waits until all data to file descriptor \var{Fd} is transmitted.
  1747. The function returns \var{True} if the call was succesfull, \var{False}
  1748. otherwise.
  1749. }
  1750. {Errors are reported in LinuxError}
  1751. {\seem{termios}{2}}
  1752. \function {TCFlow}{(Fd,Act:longint)}{Boolean}
  1753. { \var{TCFlow}
  1754. suspends/resumes transmission or reception of data to or from the file
  1755. descriptor \var{Fd}, depending
  1756. on the action \var {Act}. This can be one of the following pre-defined
  1757. values:
  1758. \begin{description}
  1759. \item [TCOOFF\ ] suspend reception/transmission,
  1760. \item [TCOON\ ] resume reception/transmission,
  1761. \item [TCIOFF\ ] transmit a stop character to stop input from the terminal,
  1762. \item [TCION\ ] transmit start to resume input from the terminal.
  1763. \end{description}
  1764. The function returns \var{True} if the call was succesfull, \var{False}
  1765. otherwise.
  1766. }
  1767. {Errors are reported in LinuxError.}
  1768. {\seem{termios}{2}}
  1769. \function{TCFlush}{(Fd,QSel:longint)}{Boolean}
  1770. { \var{TCFlush}
  1771. discards all data sent or received to/from file descriptor \var{fd}.
  1772. \var{QSel} indicates which queue
  1773. should be discard. It can be one of the following pre-defined values :
  1774. \begin{description}
  1775. \item [TCIFLUSH\ ] input,
  1776. \item [TCOFLUSH\ ] output,
  1777. \item [TCIOFLUSH\ ] both input and output.
  1778. \end{description}
  1779. The function returns \var{True} if the call was succesfull, \var{False}
  1780. otherwise.
  1781. }
  1782. {Errors are reported in LinuxError.}
  1783. {\seem{termios}{2}}
  1784. \procedure{FLock}{(Var F; Mode : longint)}
  1785. {\var{FLock} implements file locking. it sets or removes a lock on the file
  1786. \var{F}. F can be of type \var{Text} or \var{File}, or it can be a \linux
  1787. filedescriptor (a longint)
  1788. \var{Mode} can be one of the following constants :
  1789. \begin{description}
  1790. \item [LOCK\_SH] \ sets a shared lock.
  1791. \item [LOCK\_EX] \ sets an exclusive lock.
  1792. \item [LOCK\_UN] \ unlocks the file.
  1793. \item [LOCK\_NB] \ This can be OR-ed together with the other. If this is done
  1794. the application doesn't block when locking.
  1795. \end{description}
  1796. }
  1797. {Errors are reported in \var{LinuxError}.}
  1798. {\seef{Fcntl}, \seem{flock}{2}}