linux.tex 110 KB

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