bunxtype.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2001 by Free Pascal development team
  5. Types and structures for baseunix unit, also used in system.
  6. This file implements all the types/constants which must
  7. be defined to port FPC to a new POSIX compliant OS.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  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. { POSIX STRUCTURES }
  16. {***********************************************************************}
  17. {$ifdef FPC_IS_SYSTEM}
  18. {$i ptypes.inc}
  19. {$ENDIF}
  20. {$ifdef cpupowerpc}
  21. {$ifdef netbsd}
  22. {$define netbsdpowerpc}
  23. {$endif}
  24. {$endif}
  25. // CONST SYS_NMLN=65;
  26. // Can't find these two in Posix and in FreeBSD
  27. //CONST
  28. // _UTSNAME_LENGTH = ;
  29. // _UTSNAME_NODENAME_LENGTH = ;
  30. CONST // OS specific parameters for general<fd,sig>set behaviour
  31. BITSINWORD = 8*sizeof(longint);
  32. FD_MAXFDSET = 1024;
  33. ln2bitsinword = 5; { 32bit : ln(32)/ln(2)=5 }
  34. ln2bitmask = 1 shl ln2bitsinword - 1;
  35. wordsinfdset = FD_MAXFDSET DIV BITSINWORD; // words in fdset_t
  36. wordsinsigset = SIG_MAXSIG DIV BITSINWORD;
  37. TYPE
  38. { system information services }
  39. utsname = record
  40. sysname : Array[0..SYS_NMLN-1] OF Char; // Name of this OS
  41. nodename: Array[0..SYS_NMLN-1] OF Char; // Name of this network node.
  42. release : Array[0..SYS_NMLN-1] OF Char; // Release level.
  43. version : Array[0..SYS_NMLN-1] OF Char; // Version level.
  44. machine : Array[0..SYS_NMLN-1] OF Char; // Hardware type.
  45. end;
  46. TUtsName= utsname;
  47. pUtsName= ^utsname;
  48. { file characteristics services }
  49. stat = record { the types are real}
  50. st_dev : dev_t; // inode's device
  51. st_ino : ino_t; // inode's number
  52. st_mode : mode_t; // inode protection mode
  53. st_nlink : nlink_t; // number of hard links
  54. st_uid : uid_t; // user ID of the file's owner
  55. st_gid : gid_t; // group ID of the file's group
  56. st_rdev : dev_t; // device type
  57. st_atime : time_t; // time of last access
  58. st_atimensec : clong; // nsec of last access
  59. st_mtime : time_t; // time of last data modification
  60. st_mtimensec : clong; // nsec of last data modification
  61. st_ctime : time_t; // time of last file status change
  62. st_ctimensec : clong; // nsec of last file status change
  63. {$ifdef netbsdPowerpc}
  64. st_padd1 : cint;
  65. {$endif}
  66. st_size : off_t; // file size, in bytes
  67. st_blocks : cint64; // blocks allocated for file
  68. st_blksize : cuint32; // optimal blocksize for I/O
  69. st_flags : cuint32; // user defined flags for file
  70. st_gen : cuint32; // file generation number
  71. {$ifdef netbsdPowerpc}
  72. st_padd2 : cint;
  73. {$endif}
  74. {$ifndef NetBSD}
  75. st_lspare : cint32;
  76. {$endif}
  77. st_qspare : array[0..1] Of cint64;
  78. end;
  79. TStat = stat;
  80. pStat = ^stat;
  81. { directory services }
  82. dirent = record
  83. d_fileno : cuint32; // file number of entry
  84. d_reclen : cuint16; // length of this record
  85. d_type : cuint8; // file type, see below
  86. d_namlen : cuint8; // length of string in d_name
  87. d_name : array[0..(255 + 1)-1] of char; // name must be no longer than this
  88. end;
  89. TDirent = dirent;
  90. pDirent = ^dirent;
  91. dir = packed record
  92. dd_fd : cint; // file descriptor associated with directory
  93. dd_loc : clong; // offset in current buffer
  94. dd_size : clong; // amount of data returned by getdirentries
  95. dd_buf : pchar; // data buffer
  96. dd_len : cint; // size of data buffer
  97. {$ifdef netbsdpowerpc}
  98. dd_pad1 : cint;
  99. dd_seek : cint64; // magic cookie returned by getdirentries
  100. {$else}
  101. dd_seek : clong; // magic cookie returned by getdirentries
  102. {$endif}
  103. dd_rewind : clong; // magic cookie for rewinding
  104. dd_flags : cint; // flags for readdir
  105. end;
  106. TDir = dir;
  107. pDir = ^dir;
  108. utimbuf = record
  109. actime : time_t;
  110. modtime : time_t;
  111. end;
  112. TUtimBuf = utimbuf;
  113. putimbuf = ^utimbuf;
  114. flock = record
  115. l_start : off_t; { starting offset }
  116. l_len : off_t; { len = 0 means until end of file }
  117. l_pid : pid_t; { lock owner }
  118. l_type : cshort; { lock type: read/write, etc. }
  119. l_whence: cshort; { type of l_start }
  120. end;
  121. TFlock = flock;
  122. pFlock = ^flock;
  123. tms = packed record
  124. tms_utime : clock_t; { User CPU time }
  125. tms_stime : clock_t; { System CPU time }
  126. tms_cutime : clock_t; { User CPU time of terminated child procs }
  127. tms_cstime : clock_t; { System CPU time of terminated child procs }
  128. end;
  129. TTms= tms;
  130. pTms= ^tms;
  131. TFDSet = ARRAY[0..(FD_MAXFDSET div 32)-1] of Cardinal;
  132. pFDSet = ^TFDSet;
  133. {***********************************************************************}
  134. { POSIX CONSTANT ROUTINE DEFINITIONS }
  135. {***********************************************************************}
  136. CONST
  137. { access routine - these maybe OR'ed together }
  138. F_OK = 0; { test for existence of file }
  139. R_OK = 4; { test for read permission on file }
  140. W_OK = 2; { test for write permission on file }
  141. X_OK = 1; { test for execute or search permission }
  142. { seek routine }
  143. SEEK_SET = 0; { seek from beginning of file }
  144. SEEK_CUR = 1; { seek from current position }
  145. SEEK_END = 2; { seek from end of file }
  146. { open routine }
  147. { File access modes for `open' and `fcntl'. }
  148. O_RDONLY = 0; { Open read-only. }
  149. O_WRONLY = 1; { Open write-only. }
  150. O_RDWR = 2; { Open read/write. }
  151. { Bits OR'd into the second argument to open. }
  152. O_CREAT = $200; { Create file if it doesn't exist. }
  153. O_EXCL = $800; { Fail if file already exists. }
  154. O_TRUNC = $400; { Truncate file to zero length. }
  155. O_NOCTTY = $8000; { Don't assign a controlling terminal. }
  156. { File status flags for `open' and `fcntl'. }
  157. O_APPEND = 8; { Writes append to the file. }
  158. O_NONBLOCK = 4; { Non-blocking I/O. }
  159. { mode_t possible values }
  160. S_IRUSR = %0100000000; { Read permission for owner }
  161. S_IWUSR = %0010000000; { Write permission for owner }
  162. S_IXUSR = %0001000000; { Exec permission for owner }
  163. S_IRGRP = %0000100000; { Read permission for group }
  164. S_IWGRP = %0000010000; { Write permission for group }
  165. S_IXGRP = %0000001000; { Exec permission for group }
  166. S_IROTH = %0000000100; { Read permission for world }
  167. S_IWOTH = %0000000010; { Write permission for world }
  168. S_IXOTH = %0000000001; { Exec permission for world }
  169. { Used for waitpid }
  170. WNOHANG = 1; { don't block waiting }
  171. WUNTRACED = 2; { report status of stopped children }
  172. { For File control mechanism }
  173. F_GetFd = 1;
  174. F_SetFd = 2;
  175. F_GetFl = 3;
  176. F_SetFl = 4;
  177. F_GetLk = 5;
  178. F_SetLk = 6;
  179. F_SetLkW = 7;
  180. F_SetOwn = 8;
  181. F_GetOwn = 9;
  182. {*************************************************************************}
  183. { SIGNALS }
  184. {*************************************************************************}
  185. {$i signal.inc}
  186. // function geterrno:longint;
  187. // procedure seterrno(i:longint);
  188. {
  189. $Log$
  190. Revision 1.9 2004-03-04 22:15:16 marco
  191. * UnixType changes. Please report problems to me.
  192. Revision 1.8 2004/02/29 13:46:52 marco
  193. * forgotten?
  194. Revision 1.7 2004/01/04 20:08:45 jonas
  195. * moved SIG_MAXSIG and wordsinsigset constants from bunxtype.inc to
  196. ptypes.inc (already there for Darwin)
  197. Revision 1.6 2003/11/30 12:40:29 marco
  198. * fix from sebastian
  199. Revision 1.5 2003/11/19 17:11:40 marco
  200. * termio unit
  201. Revision 1.4 2003/09/14 20:15:01 marco
  202. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  203. Revision 1.3 2003/08/21 22:23:34 olle
  204. - removed parameter from fpc_iocheck
  205. Revision 1.2 2003/06/01 16:35:27 marco
  206. * Several small fixes to harmonize the *BSD rtls and Linux.
  207. Revision 1.1 2003/01/03 15:45:21 marco
  208. * Renamed to bunxtype.inc (from osposixh.inc), some minor changes
  209. (as introduced going from posix unit to baseunix)
  210. Revision 1.6 2002/10/27 17:21:29 marco
  211. * Only "difficult" functions + execvp + termios + rewinddir left to do
  212. Revision 1.5 2002/10/27 11:58:30 marco
  213. * Modifications from Saturday.
  214. Revision 1.4 2002/09/07 16:01:17 peter
  215. * old logs removed and tabs fixed
  216. Revision 1.3 2002/08/21 07:03:16 marco
  217. * Fixes from Tuesday.
  218. Revision 1.2 2002/08/19 12:29:11 marco
  219. * First working POSIX *BSD system unit.
  220. Revision 1.1 2002/08/03 19:34:19 marco
  221. * Initial *BSD versions. Seems that OpenBSD doesn't need much change,
  222. NetBSD may need some fixes to stat record and ftruncate and lseek.
  223. It is all close together, and it should be doable to have just one copy
  224. of these for *BSD.
  225. }