~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to docs/linux.tex

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

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