ptypes.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001,2010 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {***********************************************************************}
  14. { POSIX TYPE DEFINITIONS }
  15. {***********************************************************************}
  16. {$I ctypes.inc}
  17. {$packrecords c}
  18. type
  19. dev_t = cint32; { used for device numbers }
  20. TDev = dev_t;
  21. pDev = ^dev_t;
  22. gid_t = cuint32; { used for group IDs }
  23. TGid = gid_t;
  24. pGid = ^gid_t;
  25. TIOCtlRequest = cuLong;
  26. ino_t = cuint64; { used for file serial numbers }
  27. TIno = ino_t;
  28. pIno = ^ino_t;
  29. mode_t = cuint32; { used for file attributes }
  30. TMode = mode_t;
  31. pMode = ^mode_t;
  32. nlink_t = cuint32; { used for link counts }
  33. TnLink = nlink_t;
  34. pnLink = ^nlink_t;
  35. off_t = cint64; { used for file sizes }
  36. TOff = off_t;
  37. pOff = ^off_t;
  38. pid_t = cint32; { used as process identifier }
  39. TPid = pid_t;
  40. pPid = ^pid_t;
  41. {$ifdef CPU64}
  42. size_t = cuint64;
  43. {$else}
  44. size_t = cuint32; { as definied in the C standard}
  45. {$endif}
  46. TSize = size_t;
  47. pSize = ^size_t;
  48. pSize_t = ^size_t;
  49. ssize_t = clong; { used by function for returning number of bytes }
  50. TsSize = ssize_t;
  51. psSize = ^ssize_t;
  52. uid_t = cuint32; { used for user ID type }
  53. TUid = Uid_t;
  54. pUid = ^Uid_t;
  55. wint_t = cint32;
  56. wchar_t = cint32;
  57. pwchar_t = ^wchar_t;
  58. clock_t = cint64;
  59. TClock = clock_t;
  60. pClock = ^clock_t;
  61. time_t = cint64; { used for returning the time }
  62. // TTime = time_t; // Not allowed in system unit, -> unixtype
  63. pTime = ^time_t;
  64. ptime_t = ^time_t;
  65. socklen_t= cuint32;
  66. TSocklen = socklen_t;
  67. pSocklen = ^socklen_t;
  68. timeval = packed record
  69. tv_sec : time_t;
  70. tv_usec : clong;
  71. end;
  72. ptimeval= ^timeval;
  73. TTimeval= timeval;
  74. timespec = packed record
  75. tv_sec : time_t;
  76. tv_nsec : clong;
  77. end;
  78. ptimespec= ^timespec;
  79. Ttimespec= timespec;
  80. pthread_t_rec = record end;
  81. pthread_attr_t_rec = record end;
  82. // See pmutext.inc
  83. // pthread_mutex_t_rec = record end;
  84. pthread_mutexattr_t_rec = record end;
  85. pthread_cond_t_rec = record end;
  86. pthread_condattr_t_rec = record end;
  87. pthread_rwlock_t_rec = record end;
  88. pthread_rwlockattr_t_rec = record end;
  89. pthread_t = ^pthread_t_rec;
  90. pthread_attr_t = ^pthread_attr_t_rec;
  91. pthread_mutex_t = {$i pmutext.inc}
  92. pthread_mutexattr_t = ^pthread_mutexattr_t_rec;
  93. pthread_cond_t = ^pthread_cond_t_rec;
  94. pthread_condattr_t = ^pthread_condattr_t_rec;
  95. pthread_key_t = cint;
  96. pthread_once_t_rec = record
  97. state : cint;
  98. mutex : pthread_mutex_t;
  99. end;
  100. pthread_once_t = pthread_once_t_rec;
  101. pthread_rwlock_t = ^pthread_rwlock_t_rec;
  102. pthread_rwlockattr_t = ^pthread_rwlockattr_t_rec;
  103. sem_t = pointer;
  104. rlim_t = int64;
  105. TRlim = rlim_t;
  106. {
  107. Mutex types (Single UNIX Specification, Version 2, 1997).
  108. Note that a mutex attribute with one of the following types:
  109. PTHREAD_MUTEX_NORMAL
  110. PTHREAD_MUTEX_RECURSIVE
  111. MUTEX_TYPE_FAST (deprecated)
  112. MUTEX_TYPE_COUNTING_FAST (deprecated)
  113. will deviate from POSIX specified semantics.
  114. }
  115. pthread_mutextype = (
  116. { Default POSIX mutex }
  117. _PTHREAD_MUTEX_ERRORCHECK := 1,
  118. { Recursive mutex }
  119. _PTHREAD_MUTEX_RECURSIVE := 2,
  120. { No error checking }
  121. _PTHREAD_MUTEX_NORMAL := 3,
  122. _MUTEX_TYPE_MAX
  123. );
  124. Const
  125. MFSNAMELEN = 16; // length of fs type name, including nul
  126. MNAMELEN = 90; // length of buffer for returned name
  127. type
  128. fsid_t = array[0..1] of cint32;
  129. ufs_args_rec = record end;
  130. mfs_args_rec = record end;
  131. nfs_args_rec = record end;
  132. isofs_args_rec = record end;
  133. procfs_args_rec = record end;
  134. msdosfs_args_rec = record end;
  135. ntfs_args_rec = record end;
  136. mountinfo = record
  137. case byte of
  138. 0: (ufs_args: ^ufs_args_rec);
  139. 1: (mfs_args: ^mfs_args_rec);
  140. 2: (nfs_args: ^nfs_args_rec);
  141. 3: (isofs_args: ^isofs_args_rec);
  142. 4: (procfs_args: ^procfs_args_rec);
  143. 5: (msdosfs_args: ^msdosfs_args_rec);
  144. 6: (ntfs_args: ^ntfs_args_rec);
  145. 7: (__align: array[0..159] of AnsiChar); { 64-bit alignment and room to grow }
  146. end;
  147. // kernel statfs from mount.h
  148. { new statfs structure with mount options and statvfs fields }
  149. TStatfs = record
  150. flags, { copy of mount flags }
  151. bsize, { filesystem block size }
  152. iosize : cuint32; { optimal transfer block size }
  153. { unit is f_bsize }
  154. blocks, { total data block in file system }
  155. bfree : cuint64; { free blocks in fs }
  156. bavail : cint64; { free blocks avail to non-superuser }
  157. files, { total file nodes in file system }
  158. ffree : cuint64; { free files nodes in fs }
  159. favail : cint64; { free file nodes avail to non-root }
  160. fsyncwrites, { count of sync writes since mount }
  161. fsyncreads, { count of sync reads since mount }
  162. fasyncwrites, { count of async writes since mount }
  163. fasyncreads : cuint64; { count of async reads since mount }
  164. fsid : fsid_t; { file system id }
  165. namemax : cuint32; { maximum filename length }
  166. owner : tuid; { user that mounted the fileystem }
  167. ctime : cuint64; { last mount [-u] time }
  168. fstypename : array[0..MFSNAMELEN-1] of AnsiChar; { fs type name }
  169. mntonname : array[0..MNAMELEN-1] of AnsiChar; { directory on which mounted }
  170. mntfromname: array[0..MNAMELEN-1] of AnsiChar; { mounted file system }
  171. mntfromspec: array[0..MNAMELEN-1] of AnsiChar; { special for mount request }
  172. mount_info: mountinfo; { per-filesystem mount options }
  173. end;
  174. PStatFS=^TStatFS;
  175. mbstate_t = record
  176. case byte of
  177. 0: (__mbstate8: array[0..127] of AnsiChar);
  178. 1: (_mbstateL: cint64); { for alignment }
  179. end;
  180. pmbstate_t = ^mbstate_t;
  181. ITimerVal= Record
  182. It_Interval,
  183. It_Value : TimeVal;
  184. end;
  185. const
  186. _PTHREAD_MUTEX_DEFAULT = _PTHREAD_MUTEX_ERRORCHECK;
  187. _MUTEX_TYPE_FAST = _PTHREAD_MUTEX_NORMAL;
  188. _MUTEX_TYPE_COUNTING_FAST = _PTHREAD_MUTEX_RECURSIVE;
  189. _PTHREAD_KEYS_MAX = 256;
  190. _PTHREAD_STACK_MIN = 1024;
  191. { System limits, POSIX value in parentheses, used for buffer and stack allocation }
  192. ARG_MAX = 256*1024; {4096} { Maximum number of argument size }
  193. NAME_MAX = 255; {14} { Maximum number of bytes in filename }
  194. PATH_MAX = 1024; {255} { Maximum number of bytes in pathname }
  195. SYS_NMLN = 256; {BSD utsname struct limit}
  196. SIG_MAXSIG = 33; // highest signal version
  197. // set in ostypes.inc wordsinsigset = 4; // words in sigset_t
  198. { For getting/setting priority }
  199. Prio_Process = 0;
  200. Prio_PGrp = 1;
  201. Prio_User = 2;
  202. { OpenBSD 5.5 specific variants }
  203. { file characteristics services }
  204. type
  205. stat_55 = record { the types are real}
  206. st_mode : mode_t; // inode protection mode
  207. st_dev : dev_t; // inode's device
  208. st_ino : ino_t; // inode's number
  209. st_nlink : nlink_t; // number of hard links
  210. st_uid : uid_t; // user ID of the file's owner
  211. st_gid : gid_t; // group ID of the file's group
  212. st_rdev : dev_t; // device type
  213. st_atime : time_t; // time of last access
  214. st_atimensec : clong; // nsec of last access
  215. st_mtime : time_t; // time of last data modification
  216. st_mtimensec : clong; // nsec of last data modification
  217. st_ctime : time_t; // time of last file status change
  218. st_ctimensec : clong; // nsec of last file status change
  219. st_size : off_t; // file size, in bytes
  220. st_blocks : cint64; // blocks allocated for file
  221. st_blksize : cuint32; // optimal blocksize for I/O
  222. st_flags : cuint32; // user defined flags for file
  223. st_gen : cuint32; // file generation number
  224. st_birthtime : time_t; // File creation time
  225. st_birthtimensec : clong; // nsec of file creation time
  226. st_qspare : array[0..1] Of cint64;
  227. end;
  228. TStat_55 = stat_55;
  229. pStat_55 = ^stat_55;
  230. { directory services }
  231. dirent_55 = record
  232. d_fileno : ino_t;
  233. d_off : off_t;
  234. d_reclen : cuint16; // length of this record
  235. d_type : cuint8; // file type, see below
  236. d_namlen : cuint8; // length of string in d_name
  237. d_padding : array[1..4] of cuint8;
  238. d_name : array[0..(255 + 1)-1] of AnsiChar; // name must be no longer than this
  239. end;
  240. TDirent_55 = dirent_55;
  241. pDirent_55 = ^dirent_55;
  242. dir_55 = record
  243. dd_fd : cint; // file descriptor associated with directory
  244. dd_loc : clong; // offset in current buffer
  245. dd_size : clong; // amount of data returned by getdirentries
  246. dd_buf : PAnsiChar; // data buffer
  247. dd_len : cint; // size of data buffer
  248. dd_curpos : off_t;
  249. dd_lock : pointer;
  250. dd_rewind : clong;
  251. end;
  252. TDir_55 = dir_55;
  253. pDir_55 = ^dir_55;