ptypes.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 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. const
  19. SEM_SAFE=255;
  20. type
  21. dev_t = cuint64; { used for device numbers }
  22. TDev = dev_t;
  23. pDev = ^dev_t;
  24. gid_t = cuint32; { used for group IDs }
  25. TGid = gid_t;
  26. pGid = ^gid_t;
  27. TIOCtlRequest = cuLong;
  28. ino_t = cuint64; { used for file serial numbers }
  29. TIno = ino_t;
  30. pIno = ^ino_t;
  31. mode_t = cuint16; { used for file attributes }
  32. TMode = mode_t;
  33. pMode = ^mode_t;
  34. nlink_t = cuint64; { used for link counts }
  35. TnLink = nlink_t;
  36. pnLink = ^nlink_t;
  37. off_t = cint64; { used for file sizes }
  38. TOff = off_t;
  39. pOff = ^off_t;
  40. pid_t = cint32; { used as process identifier }
  41. TPid = pid_t;
  42. pPid = ^pid_t;
  43. {$ifdef CPU64}
  44. size_t = cuint64;
  45. {$else}
  46. size_t = cuint32; { as definied in the C standard}
  47. {$endif}
  48. TSize = size_t;
  49. pSize = ^size_t;
  50. pSize_t = ^size_t;
  51. {$ifdef CPU64}
  52. ssize_t = cint64; { used by function for returning number of bytes }
  53. {$else}
  54. ssize_t = cint32; { used by function for returning number of bytes}
  55. {$endif}
  56. TsSize = ssize_t;
  57. psSize = ^ssize_t;
  58. uid_t = cuint32; { used for user ID type }
  59. TUid = Uid_t;
  60. pUid = ^Uid_t;
  61. wint_t = cint32;
  62. wchar_t = cint32;
  63. pwchar_t = ^wchar_t;
  64. {$ifdef CPU64}
  65. clock_t = cuint32; // 32-bit even on Athlon64
  66. {$else}
  67. clock_t = culong;
  68. {$endif}
  69. TClock = clock_t;
  70. pClock = ^clock_t;
  71. time_t = clong; { used for returning the time, clong
  72. is 64-bit on AMD64}
  73. // TTime = time_t; // Not allowed in system unit, -> unixtype
  74. pTime = ^time_t;
  75. ptime_t = ^time_t;
  76. socklen_t= cuint32;
  77. TSocklen = socklen_t;
  78. pSocklen = ^socklen_t;
  79. timeval = packed record
  80. tv_sec,tv_usec:clong;
  81. end;
  82. ptimeval = ^timeval;
  83. TTimeVal = timeval;
  84. timespec = packed record
  85. tv_sec : time_t; // should be time_t, bug compability
  86. tv_nsec : clong;
  87. end;
  88. ptimespec= ^timespec;
  89. Ttimespec= timespec;
  90. pthread_t_rec = record end;
  91. pthread_attr_t_rec = record end;
  92. // pthread_mutex_t_rec = record end;
  93. pthread_mutexattr_t_rec = record end;
  94. pthread_cond_t_rec = record end;
  95. pthread_condattr_t_rec = record end;
  96. pthread_rwlock_t_rec = record end;
  97. pthread_rwlockattr_t_rec = record end;
  98. pthread_t = ^pthread_t_rec;
  99. pthread_attr_t = ^pthread_attr_t_rec;
  100. pthread_mutex_t = {$i pmutext.inc}
  101. pthread_mutexattr_t = ^pthread_mutexattr_t_rec;
  102. pthread_cond_t = ^pthread_cond_t_rec;
  103. pthread_condattr_t = ^pthread_condattr_t_rec;
  104. pthread_key_t = cint;
  105. pthread_rwlock_t = ^pthread_rwlock_t_rec;
  106. pthread_rwlockattr_t = ^pthread_rwlockattr_t_rec;
  107. psem_t = ^sem_t;
  108. ppsem_t= ^psem_t;
  109. semid_t= pointer;
  110. sem_t = record
  111. magic : cuint32;
  112. lock : pthread_mutex_t;
  113. gtzero : pthread_cond_t;
  114. count : cuint32;
  115. nwaiters: cuint32;
  116. semid : semid_t;
  117. sysse : cint;
  118. entry : psem_t;
  119. backpointer : ppsem_t;
  120. spare : array[0..SEM_SAFE] of char;
  121. end;
  122. rlim_t = int64;
  123. TRlim = rlim_t;
  124. {
  125. Mutex types (Single UNIX Specification, Version 2, 1997).
  126. Note that a mutex attribute with one of the following types:
  127. PTHREAD_MUTEX_NORMAL
  128. PTHREAD_MUTEX_RECURSIVE
  129. MUTEX_TYPE_FAST (deprecated)
  130. MUTEX_TYPE_COUNTING_FAST (deprecated)
  131. will deviate from POSIX specified semantics.
  132. }
  133. pthread_mutextype = (
  134. { Default POSIX mutex }
  135. _PTHREAD_MUTEX_ERRORCHECK := 1,
  136. { Recursive mutex }
  137. _PTHREAD_MUTEX_RECURSIVE := 2,
  138. { No error checking }
  139. _PTHREAD_MUTEX_NORMAL := 3,
  140. _MUTEX_TYPE_MAX
  141. );
  142. type
  143. fsid_t = array[0..1] of cint32;
  144. Const
  145. MNAMELEN = 88;
  146. MFSNamELen = 16;
  147. STATFS_VERSION = $20030518;
  148. OMNAMLEN = 88-2*sizeof(clong); // slightly machine specific.
  149. OMFSNamLen = 16;
  150. // fieldnames start with f_ in headers. Probably 1.0.x simplification that somehow
  151. // managed to escape the unix rewrite. Make an union+ deprecate after newstatfs is stable.
  152. Type TStatFS = {?} Record
  153. case boolean of
  154. 0 : ( // current FreeBSD
  155. version : cuint32; { structure version number }
  156. ftype : cuint32; { type of filesystem }
  157. fflags : cuint64; { copy of mount exported flags }
  158. bsize : cuint64; { filesystem fragment size }
  159. iosize : cuint64; { optimal transfer block size }
  160. blocks : cuint64; { total data blocks in filesystem }
  161. bfree : cuint64; { free blocks in filesystem }
  162. bavail : cint64; { free blocks avail to non-superuser }
  163. files : cuint64; { total file nodes in filesystem }
  164. ffree : cint64; { free nodes avail to non-superuser }
  165. fsyncwrites : cuint64; { count of sync writes since mount }
  166. fasyncwrites : cuint64; { count of async writes since mount }
  167. fsyncreads : cuint64; { count of sync reads since mount }
  168. fasyncreads : cuint64; { count of async reads since mount }
  169. spare : array[0..9] of cuint64; { unused spare }
  170. namemax : cuint32; { maximum filename length }
  171. owner : tuid; { user that mounted the filesystem }
  172. fsid : fsid_t; { filesystem id }
  173. charspare : array[0..80-1] of ansichar; { spare string space }
  174. fstypename : array[0..MFSNAMELEN-1] of ansichar; { filesystem type name }
  175. mnfromname : array[0..MNAMELEN-1] of ansichar; { mounted filesystem }
  176. mountpoint : array[0..MNAMELEN-1] of ansichar; { directory on which mounted }
  177. );
  178. 1:( // union for old fieldname's sake.
  179. f_version : cuint32; { structure version number }
  180. f_type : cuint32; { type of filesystem }
  181. f_flags : cuint64; { copy of mount exported flags }
  182. f_bsize : cuint64; { filesystem fragment size }
  183. f_iosize : cuint64; { optimal transfer block size }
  184. f_blocks : cuint64; { total data blocks in filesystem }
  185. f_bfree : cuint64; { free blocks in filesystem }
  186. f_bavail : cint64; { free blocks avail to non-superuser }
  187. f_files : cuint64; { total file nodes in filesystem }
  188. f_ffree : cint64; { free nodes avail to non-superuser }
  189. f_syncwrites : cuint64; { count of sync writes since mount }
  190. f_asyncwrites : cuint64; { count of async writes since mount }
  191. f_syncreads : cuint64; { count of sync reads since mount }
  192. f_asyncreads : cuint64; { count of async reads since mount }
  193. f_spare : array[0..9] of cuint64; { unused spare }
  194. f_namemax : cuint32; { maximum filename length }
  195. f_owner : tuid; { user that mounted the filesystem }
  196. f_fsid : fsid_t; { filesystem id }
  197. f_charspare : array[0..80-1] of ansichar; { spare string space }
  198. f_fstypename : array[0..MFSNAMELEN-1] of ansichar; { filesystem type name }
  199. f_mntfromname : array[0..MNAMELEN-1] of ansichar; { mounted filesystem }
  200. f_mntonname : array[0..MNAMELEN-1] of ansichar; { directory on which mounted }
  201. );
  202. end;
  203. PStatFS=^TStatFS;
  204. TStatFS4 = packed record
  205. spare2, { place holder}
  206. bsize, { fundamental block size}
  207. iosize, { optimal block size }
  208. blocks, { total blocks}
  209. bfree, { blocks free}
  210. bavail, { block available for mortal users}
  211. files, { Total file nodes}
  212. ffree : clong ; { file nodes free}
  213. fsid : fsid_t;
  214. fowner : tuid; {mounter uid}
  215. ftype : cint;
  216. fflags : cint; {copy of mount flags}
  217. fsyncwrites,
  218. fasyncwrites : clong;
  219. fstypename : array[0..OMFSNamLen-1] of char;
  220. mountpoint : array[0..OMNAMLEN-1] of char;
  221. fsyncreads, { count of sync reads since mount }
  222. fasyncreads : clong;
  223. fspares1 : cshort;
  224. mnfromname : array[0..OMNAMLEN-1] of char;
  225. fspares2 : cshort;
  226. fspare3 : array[0..1] of clong;
  227. end;
  228. PStatFS4=^TStatFs4;
  229. mbstate_t = record
  230. case byte of
  231. 0: (__mbstate8: array[0..127] of char);
  232. 1: (_mbstateL: cint64); { for alignment }
  233. end;
  234. pmbstate_t = ^mbstate_t;
  235. ITimerVal= Record
  236. It_Interval,
  237. It_Value : TimeVal;
  238. end;
  239. const
  240. _PTHREAD_MUTEX_DEFAULT = _PTHREAD_MUTEX_ERRORCHECK;
  241. _MUTEX_TYPE_FAST = _PTHREAD_MUTEX_NORMAL;
  242. _MUTEX_TYPE_COUNTING_FAST = _PTHREAD_MUTEX_RECURSIVE;
  243. _PTHREAD_KEYS_MAX = 256;
  244. _PTHREAD_STACK_MIN = 1024;
  245. { System limits, POSIX value in parentheses, used for buffer and stack allocation }
  246. {$ifdef CPU64}
  247. ARG_MAX = 262144; {4096} { Maximum number of argument size }
  248. {$else}
  249. ARG_MAX = 65536; {4096} { Maximum number of argument size }
  250. {$endif}
  251. NAME_MAX = 255; {14} { Maximum number of bytes in filename }
  252. PATH_MAX = 1024; {255} { Maximum number of bytes in pathname }
  253. SYS_NMLN = 32; {BSD utsname struct limit, kernel mode}
  254. SIG_MAXSIG = 128; // highest signal version
  255. // wordsinsigset = 4; // words in sigset_t
  256. { For getting/setting priority }
  257. Prio_Process = 0;
  258. Prio_PGrp = 1;
  259. Prio_User = 2;