linux.tex 68 KB

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