linux.tex 94 KB

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