1{
2    This file is part of the Free Pascal run time library.
3    Copyright (c) 2001 by Free Pascal development team
4
5    Types and structures for the BaseUnix unit.
6
7    See the file COPYING.FPC, included in this distribution,
8    for details about the copyright.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ***********************************************************************}
15
16{***********************************************************************}
17{                         Base Unix Structures                          }
18{***********************************************************************}
19
20{$IFDEF FPC_IS_SYSTEM}
21  {$i ptypes.inc}
22{$ENDIF}
23
24{ note: all constants/types are taken from the case that the headers are parsed
25  with:
26    -D_LARGE_FILES
27    -U_POSIX_SOURCE
28    -U_ANSI_C_SOURCE
29}
30
31CONST
32   FD_MAXFDSET     = 65534;
33   BITSINWORD      = 8*sizeof(clong);
34   wordsinsigset   = (SIG_MAXSIG+1+BITSINWORD-1) DIV BITSINWORD;         // words in sigset_t
35   wordsinfdset    = (FD_MAXFDSET+1+BITSINWORD-1) DIV BITSINWORD;        // words in fdset_t
36{$ifdef cpu64}
37   ln2bitsinword   = 6;         { 64bit : ln(64)/ln(2)=5 }
38{$else}
39   ln2bitsinword   = 5;         { 32bit : ln(32)/ln(2)=5 }
40{$endif}
41   ln2bitmask      = 1 shl ln2bitsinword - 1;
42
43    UTSNAME_LENGTH = 31;
44    UTSNAME_NODENAME_LENGTH = 31;
45
46TYPE
47    blksize_t = {$ifdef cpu64}clong{$else}cint{$endif};
48    blkcnt_t = {$ifdef cpu64}clong{$else}cint{$endif};
49
50   { file characteristics services }
51   stat = record
52     st_dev : dev_t;
53     st_ino : ino_t;
54     st_mode : mode_t;
55     st_nlink : nlink_t;
56     st_flag : cushort;
57     st_uid : uid_t;
58     st_gid : gid_t;
59     st_rdev : dev_t;
60     st_ssize : cint;
61     st_atime : time_t;
62     st_atimens : cint;    { access time nanosecond field         }
63
64     st_mtime : time_t;
65     st_mtimens : cint;    { modification time nanosecond field   }
66     st_ctime : time_t;
67     st_ctimens : cint;    { modification time nanosecond field   }
68     st_blksize : blksize_t;
69     st_blocks : blkcnt_t;
70     st_vfstype: cint;     { Type of fs (see vnode.h) }
71     st_vfs    : cuint;    { Vfs number }
72     st_type   : cuint;    { Vnode type }
73     st_gen    : cuint;    { Inode generation number }
74     st_reserved : array [0..9] of cuint;
75     st_size   : off_t;    { 64 bit file size in bytes }
76   end;
77   TStat             = Stat;
78   PStat             = ^Stat;
79
80   flock    = record
81                l_type  : cshort;       { lock type: read/write, etc. }
82                l_whence: cshort;       { type of l_start }
83                l_sysid : cuint;
84                l_pid   : pid_t;        { lock owner }
85                l_vfs   : cint;
86                l_start : off_t;
87                l_len   : off_t;
88                end;
89   TFlock   = flock;
90   pFlock   = ^flock;
91
92   TFDSetEl = culong;
93   TFDSet    = array[0..wordsinfdset-1] of TFDSetEl;
94   pFDSet    = ^TFDSet;
95
96   timezone = record
97     tz_minuteswest,tz_dsttime:cint;
98   end;
99   ptimezone =^timezone;
100   TTimeZone = timezone;
101
102   { system information services }
103   utsname = record
104     sysname : array[0..UTSNAME_LENGTH] of char;
105     nodename : array[0..UTSNAME_LENGTH] of char;
106     release : array[0..UTSNAME_LENGTH] of char;
107     version : array[0..UTSNAME_LENGTH] of char;
108     machine : array[0..UTSNAME_LENGTH] of char;
109   end;
110
111   UTimBuf   = Record
112                 actime  : time_t;
113                 modtime : time_t;
114                end;
115   TUtimBuf  = UtimBuf;
116   pUtimBuf  = ^UtimBuf;
117
118   { directory services }
119   pdirent = ^dirent;
120   { actually dirent64 }
121   dirent = record    { directory entry record }
122     case integer of
123       1 : (
124             d_off : cuint64;                  {* offset of disk directory entry *}
125             d_ino : ino64_t;                  {* "inode number" of entry *}
126             d_reclen : cushort;             {* length of this record *}
127             d_namelen : cushort;
128             d_name : array[0..255] of char; { name of file            }
129            );
130       { overlay with alias }
131       2 : (
132            dummy    : cuint64;
133            d_fileno : ino64_t;
134           );
135   end;
136
137
138   pdir = ^dir;
139   dir = record
140    case integer of
141      1 : (
142           d_fd : cint;               {* file descriptor *}
143           d_loc : cint;              {* offset in block *}
144           d_size : cint;             {* amount of valid data *}
145           d_buf : pchar;             { directory block   }
146          );
147      { overlay for posix compatibility }
148      2 : (
149           dd_fd : cint;               {* file descriptor *}
150           dd_loc : cint;              {* offset in block *}
151           dd_size : cint;             {* amount of valid data *}
152           dd_buf : pchar;             { directory block   }
153          );
154   end;
155
156
157
158{***********************************************************************}
159{                  POSIX CONSTANT ROUTINE DEFINITIONS                   }
160{***********************************************************************}
161CONST
162    { access routine - these maybe OR'ed together }
163    F_OK        = 0;   { test for existence of file }
164    R_OK        = 4;   { test for read permission on file }
165    W_OK        = 2;   { test for write permission on file }
166    X_OK        = 1;   { test for execute or search permission }
167    { seek routine }
168    SEEK_SET    = 0;    { seek from beginning of file }
169    SEEK_CUR    = 1;    { seek from current position  }
170    SEEK_END    = 2;    { seek from end of file       }
171    { open routine                                 }
172    { File access modes for `open' and `fcntl'.    }
173    O_RDONLY    = 0;    { Open read-only.  }
174    O_WRONLY    = 1;    { Open write-only. }
175    O_RDWR      = 2;    { Open read/write. }
176    { Bits OR'd into the second argument to open.  }
177    O_CREAT     = $100; { Create file if it doesn't exist.  }
178    O_EXCL      = $400; { Fail if file already ??????.      }
179    O_TRUNC     = $200; { Truncate file to zero length.     }
180    O_NOCTTY    = $800; { Don't assign a controlling terminal. }
181    { File status flags for `open' and `fcntl'.  }
182    O_APPEND    =  $08; { Writes append to the file.        }
183    O_NONBLOCK  =  $04; { Non-blocking I/O.                 }
184
185
186    { mode_t possible values                                 }
187    S_IRUSR = $100;           { Read permission for owner   }
188    S_IWUSR = $080;           { Write permission for owner  }
189    S_IXUSR = $040;           { Exec  permission for owner  }
190    S_IRGRP = $020;           { Read permission for group   }
191    S_IWGRP = $010;           { Write permission for group  }
192    S_IXGRP = $008;           { Exec permission for group   }
193    S_IROTH = $004;           { Read permission for world   }
194    S_IWOTH = $002;           { Write permission for world  }
195    S_IXOTH = $001;           { Exec permission for world   }
196
197    { Used for waitpid }
198    WNOHANG   = $01;            { don't block waiting               }
199    WUNTRACED = $02;            { report status of stopped children }
200
201Const
202  S_IFMT  = $F000;
203  S_IFIFO = $1000;
204  S_IFCHR = $2000;
205  S_IFDIR = $4000;
206  S_IFBLK = $6000;
207  S_IFREG = $8000;
208  S_IFLNK = $A000;
209  S_IFSOCK= $C000;
210//  S_IFWHT = 57344;
211  S_ISVTX = $200;
212
213  { For File control mechanism }
214  F_GetFd  = 1;
215  F_SetFd  = 2;
216  F_GetFl  = 3;
217  F_SetFl  = 4;
218  F_GetLk  = 5;
219  F_SetLk  = 6;
220  F_SetLkW = 7;
221  F_SetOwn = 9;
222  F_GetOwn = 8;
223
224Const
225 { Constansts for MMAP }
226 {$ifdef FPC_IS_SYSTEM}
227  MAP_PRIVATE   =2;
228 {$endif}
229  MAP_ANONYMOUS =$10;
230
231type
232  rlim_t = cULong;
233  PRLimit = ^TRLimit;
234  TRLimit = record
235    rlim_cur : rlim_t;
236    rlim_max : rlim_t;
237  end;
238
239{$i signal.inc}
240
241  iovec = record
242            iov_base : pointer;
243	    iov_len  : size_t;
244	   end;
245  tiovec=iovec;
246  piovec=^tiovec;
247
248 tms = packed record
249         tms_utime  : clock_t;  { User CPU time }
250         tms_stime  : clock_t;  { System CPU time }
251         tms_cutime : clock_t;  { User CPU time of terminated child procs }
252         tms_cstime : clock_t;  { System CPU time of terminated child procs }
253         end;
254 TTms= tms;
255 pTms= ^tms;
256
257const
258  POLLIN      = $0001;
259  POLLPRI     = $0004;
260  POLLOUT     = $0002;
261  POLLERR     = $4000;
262  POLLHUP     = $2000;
263  POLLNVAL    = $8000;
264
265  { XOpen, XPG 4.2 }
266  POLLRDNORM  = $0010;
267  POLLRDBAND  = $0020;
268  POLLWRNORM  = POLLOUT;
269  POLLWRBAND  = $0040;
270
271type
272  pollfd = record
273    { int on 64 bit = long on 32 bit, but this is how the C header does it }
274{$ifdef cpu64}
275    fd: cint;
276{$else}
277    fd: clong;
278{$endif}
279    events: cshort;
280    revents: cshort;
281  end;
282  tpollfd = pollfd;
283  ppollfd = ^pollfd;
284
285
286