linux.tex 77 KB

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