linux.tex 77 KB

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