linux.tex 76 KB

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