linux.tex 91 KB

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