ptypes.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 = cint32; { 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_once_t_rec = record end;
  88. pthread_rwlock_t_rec = record end;
  89. pthread_rwlockattr_t_rec = record end;
  90. pthread_t = ^pthread_t_rec;
  91. pthread_attr_t = ^pthread_attr_t_rec;
  92. pthread_mutex_t = {$i pmutext.inc}
  93. pthread_mutexattr_t = ^pthread_mutexattr_t_rec;
  94. pthread_cond_t = ^pthread_cond_t_rec;
  95. pthread_condattr_t = ^pthread_condattr_t_rec;
  96. pthread_key_t = cint;
  97. pthread_once_t = ^pthread_once_t_rec;
  98. pthread_rwlock_t = ^pthread_rwlock_t_rec;
  99. pthread_rwlockattr_t = ^pthread_rwlockattr_t_rec;
  100. sem_t = pointer;
  101. rlim_t = int64;
  102. TRlim = rlim_t;
  103. {
  104. Mutex types (Single UNIX Specification, Version 2, 1997).
  105. Note that a mutex attribute with one of the following types:
  106. PTHREAD_MUTEX_NORMAL
  107. PTHREAD_MUTEX_RECURSIVE
  108. MUTEX_TYPE_FAST (deprecated)
  109. MUTEX_TYPE_COUNTING_FAST (deprecated)
  110. will deviate from POSIX specified semantics.
  111. }
  112. pthread_mutextype = (
  113. { Default POSIX mutex }
  114. _PTHREAD_MUTEX_ERRORCHECK := 1,
  115. { Recursive mutex }
  116. _PTHREAD_MUTEX_RECURSIVE := 2,
  117. { No error checking }
  118. _PTHREAD_MUTEX_NORMAL := 3,
  119. _MUTEX_TYPE_MAX
  120. );
  121. Const
  122. MFSNAMELEN = 16; // length of fs type name, including nul
  123. MNAMELEN = 90; // length of buffer for returned name
  124. type
  125. fsid_t = array[0..1] of cint32;
  126. ufs_args_rec = record end;
  127. mfs_args_rec = record end;
  128. nfs_args_rec = record end;
  129. isofs_args_rec = record end;
  130. procfs_args_rec = record end;
  131. msdosfs_args_rec = record end;
  132. ntfs_args_rec = record end;
  133. mountinfo = record
  134. case byte of
  135. 0: (ufs_args: ^ufs_args_rec);
  136. 1: (mfs_args: ^mfs_args_rec);
  137. 2: (nfs_args: ^nfs_args_rec);
  138. 3: (isofs_args: ^isofs_args_rec);
  139. 4: (procfs_args: ^procfs_args_rec);
  140. 5: (msdosfs_args: ^msdosfs_args_rec);
  141. 6: (ntfs_args: ^ntfs_args_rec);
  142. 7: (__align: array[0..159] of char); { 64-bit alignment and room to grow }
  143. end;
  144. // kernel statfs from mount.h
  145. { new statfs structure with mount options and statvfs fields }
  146. TStatfs = record
  147. flags, { copy of mount flags }
  148. bsize, { filesystem block size }
  149. iosize : cuint32; { optimal transfer block size }
  150. { unit is f_bsize }
  151. blocks, { total data block in file system }
  152. bfree : cuint64; { free blocks in fs }
  153. bavail : cint64; { free blocks avail to non-superuser }
  154. files, { total file nodes in file system }
  155. ffree : cuint64; { free files nodes in fs }
  156. favail : cint64; { free file nodes avail to non-root }
  157. fsyncwrites, { count of sync writes since mount }
  158. fsyncreads, { count of sync reads since mount }
  159. fasyncwrites, { count of async writes since mount }
  160. fasyncreads : cuint64; { count of async reads since mount }
  161. fsid : fsid_t; { file system id }
  162. namemax : cuint32; { maximum filename length }
  163. owner : tuid; { user that mounted the fileystem }
  164. ctime : cuint64; { last mount [-u] time }
  165. fstypename : array[0..MFSNAMELEN-1] of char; { fs type name }
  166. mntonname : array[0..MNAMELEN-1] of char; { directory on which mounted }
  167. mntfromname: array[0..MNAMELEN-1] of char; { mounted file system }
  168. mntfromspec: array[0..MNAMELEN-1] of char; { special for mount request }
  169. mount_info: mountinfo; { per-filesystem mount options }
  170. end;
  171. PStatFS=^TStatFS;
  172. mbstate_t = record
  173. case byte of
  174. 0: (__mbstate8: array[0..127] of char);
  175. 1: (_mbstateL: cint64); { for alignment }
  176. end;
  177. pmbstate_t = ^mbstate_t;
  178. ITimerVal= Record
  179. It_Interval,
  180. It_Value : TimeVal;
  181. end;
  182. const
  183. _PTHREAD_MUTEX_DEFAULT = _PTHREAD_MUTEX_ERRORCHECK;
  184. _MUTEX_TYPE_FAST = _PTHREAD_MUTEX_NORMAL;
  185. _MUTEX_TYPE_COUNTING_FAST = _PTHREAD_MUTEX_RECURSIVE;
  186. _PTHREAD_KEYS_MAX = 256;
  187. _PTHREAD_STACK_MIN = 1024;
  188. { System limits, POSIX value in parentheses, used for buffer and stack allocation }
  189. ARG_MAX = 256*1024; {4096} { Maximum number of argument size }
  190. NAME_MAX = 255; {14} { Maximum number of bytes in filename }
  191. PATH_MAX = 1024; {255} { Maximum number of bytes in pathname }
  192. SYS_NMLN = 256; {BSD utsname struct limit}
  193. SIG_MAXSIG = 33; // highest signal version
  194. // set in ostypes.inc wordsinsigset = 4; // words in sigset_t
  195. { For getting/setting priority }
  196. Prio_Process = 0;
  197. Prio_PGrp = 1;
  198. Prio_User = 2;
  199. { OpenBSD 5.5 specific variants }
  200. { file characteristics services }
  201. type
  202. stat_55 = record { the types are real}
  203. st_mode : mode_t; // inode protection mode
  204. st_dev : dev_t; // inode's device
  205. st_ino : ino_t; // inode's number
  206. st_nlink : nlink_t; // number of hard links
  207. st_uid : uid_t; // user ID of the file's owner
  208. st_gid : gid_t; // group ID of the file's group
  209. st_rdev : dev_t; // device type
  210. st_atime : time_t; // time of last access
  211. st_atimensec : clong; // nsec of last access
  212. st_mtime : time_t; // time of last data modification
  213. st_mtimensec : clong; // nsec of last data modification
  214. st_ctime : time_t; // time of last file status change
  215. st_ctimensec : clong; // nsec of last file status change
  216. st_size : off_t; // file size, in bytes
  217. st_blocks : cint64; // blocks allocated for file
  218. st_blksize : cuint32; // optimal blocksize for I/O
  219. st_flags : cuint32; // user defined flags for file
  220. st_gen : cuint32; // file generation number
  221. st_birthtime : time_t; // File creation time
  222. st_birthtimensec : clong; // nsec of file creation time
  223. st_qspare : array[0..1] Of cint64;
  224. end;
  225. TStat_55 = stat_55;
  226. pStat_55 = ^stat_55;
  227. { directory services }
  228. dirent_55 = record
  229. d_fileno : ino_t;
  230. d_off : off_t;
  231. d_reclen : cuint16; // length of this record
  232. d_type : cuint8; // file type, see below
  233. d_namlen : cuint8; // length of string in d_name
  234. d_padding : array[1..4] of cuint8;
  235. d_name : array[0..(255 + 1)-1] of char; // name must be no longer than this
  236. end;
  237. TDirent_55 = dirent_55;
  238. pDirent_55 = ^dirent_55;
  239. dir_55 = record
  240. dd_fd : cint; // file descriptor associated with directory
  241. dd_loc : clong; // offset in current buffer
  242. dd_size : clong; // amount of data returned by getdirentries
  243. dd_buf : pchar; // data buffer
  244. dd_len : cint; // size of data buffer
  245. dd_curpos : off_t;
  246. dd_lock : pointer;
  247. dd_rewind : clong;
  248. end;
  249. TDir_55 = dir_55;
  250. pDir_55 = ^dir_55;