linux.tex 111 KB

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