posix_haiku.nim 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2020 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. when defined(nimHasStyleChecks):
  10. {.push styleChecks: off.}
  11. const
  12. hasSpawnH = true # should exist for every Posix system nowadays
  13. hasAioH = defined(linux)
  14. when defined(linux) and not defined(android):
  15. # On Linux:
  16. # timer_{create,delete,settime,gettime},
  17. # clock_{getcpuclockid, getres, gettime, nanosleep, settime} lives in librt
  18. {.passl: "-lrt".}
  19. when defined(solaris):
  20. # On Solaris hstrerror lives in libresolv
  21. {.passl: "-lresolv".}
  22. type
  23. DIR* {.importc: "DIR", header: "<dirent.h>",
  24. incompleteStruct.} = object
  25. ## A type representing a directory stream.
  26. type
  27. SocketHandle* = distinct cint # The type used to represent socket descriptors
  28. type
  29. Time* {.importc: "time_t", header: "<time.h>".} = distinct (
  30. when defined(i386):
  31. int32
  32. else:
  33. int64
  34. )
  35. Timespec* {.importc: "struct timespec",
  36. header: "<time.h>", final, pure.} = object ## struct timespec
  37. tv_sec*: Time ## Seconds.
  38. tv_nsec*: int ## Nanoseconds.
  39. Dirent* {.importc: "struct dirent",
  40. header: "<dirent.h>", final, pure.} = object ## dirent_t struct
  41. when defined(haiku):
  42. d_dev*: Dev ## Device (not POSIX)
  43. d_pdev*: Dev ## Parent device (only for queries) (not POSIX)
  44. d_ino*: Ino ## File serial number.
  45. when defined(dragonfly):
  46. # DragonflyBSD doesn't have `d_reclen` field.
  47. d_type*: uint8
  48. elif defined(linux) or defined(macosx) or defined(freebsd) or
  49. defined(netbsd) or defined(openbsd) or defined(genode):
  50. d_reclen*: cshort ## Length of this record. (not POSIX)
  51. d_type*: int8 ## Type of file; not supported by all filesystem types.
  52. ## (not POSIX)
  53. when defined(linux) or defined(openbsd):
  54. d_off*: Off ## Not an offset. Value that `telldir()` would return.
  55. elif defined(haiku):
  56. d_pino*: Ino ## Parent inode (only for queries) (not POSIX)
  57. d_reclen*: cushort ## Length of this record. (not POSIX)
  58. when not defined(haiku):
  59. d_name*: array[0..255, char] ## Name of entry.
  60. else:
  61. d_name*: UncheckedArray[char] ## Name of entry (NUL terminated).
  62. Tflock* {.importc: "struct flock", final, pure,
  63. header: "<fcntl.h>".} = object ## flock type
  64. l_type*: cshort ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
  65. l_whence*: cshort ## Flag for starting offset.
  66. l_start*: Off ## Relative offset in bytes.
  67. l_len*: Off ## Size; if 0 then until EOF.
  68. l_pid*: Pid ## Process ID of the process holding the lock;
  69. ## returned with F_GETLK.
  70. FTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
  71. base*: cint
  72. level*: cint
  73. Glob* {.importc: "glob_t", header: "<glob.h>",
  74. final, pure.} = object ## glob_t
  75. gl_pathc*: int ## Count of paths matched by pattern.
  76. gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
  77. gl_offs*: int ## Slots to reserve at the beginning of gl_pathv.
  78. Group* {.importc: "struct group", header: "<grp.h>",
  79. final, pure.} = object ## struct group
  80. gr_name*: cstring ## The name of the group.
  81. gr_gid*: Gid ## Numerical group ID.
  82. gr_mem*: cstringArray ## Pointer to a null-terminated array of character
  83. ## pointers to member names.
  84. Iconv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} =
  85. object ## Identifies the conversion from one codeset to another.
  86. Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
  87. pure.} = object
  88. currency_symbol*: cstring
  89. decimal_point*: cstring
  90. frac_digits*: char
  91. grouping*: cstring
  92. int_curr_symbol*: cstring
  93. int_frac_digits*: char
  94. int_n_cs_precedes*: char
  95. int_n_sep_by_space*: char
  96. int_n_sign_posn*: char
  97. int_p_cs_precedes*: char
  98. int_p_sep_by_space*: char
  99. int_p_sign_posn*: char
  100. mon_decimal_point*: cstring
  101. mon_grouping*: cstring
  102. mon_thousands_sep*: cstring
  103. negative_sign*: cstring
  104. n_cs_precedes*: char
  105. n_sep_by_space*: char
  106. n_sign_posn*: char
  107. positive_sign*: cstring
  108. p_cs_precedes*: char
  109. p_sep_by_space*: char
  110. p_sign_posn*: char
  111. thousands_sep*: cstring
  112. Mqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
  113. MqAttr* {.importc: "struct mq_attr",
  114. header: "<mqueue.h>",
  115. final, pure.} = object ## message queue attribute
  116. mq_flags*: int ## Message queue flags.
  117. mq_maxmsg*: int ## Maximum number of messages.
  118. mq_msgsize*: int ## Maximum message size.
  119. mq_curmsgs*: int ## Number of messages currently queued.
  120. Passwd* {.importc: "struct passwd", header: "<pwd.h>",
  121. final, pure.} = object ## struct passwd
  122. pw_name*: cstring ## User's login name.
  123. pw_uid*: Uid ## Numerical user ID.
  124. pw_gid*: Gid ## Numerical group ID.
  125. pw_dir*: cstring ## Initial working directory.
  126. pw_shell*: cstring ## Program to use as shell.
  127. Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int64
  128. ## used for file block counts
  129. Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int32
  130. ## used for block sizes
  131. Clock* {.importc: "clock_t", header: "<time.h>".} = int32
  132. ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int32
  133. Dev* {.importc: "dev_t", header: "<sys/types.h>".} = int32
  134. Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int64
  135. Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int64
  136. Gid* {.importc: "gid_t", header: "<sys/types.h>".} = uint32
  137. Id* {.importc: "id_t", header: "<sys/types.h>".} = int32
  138. Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int64
  139. Key* {.importc: "key_t", header: "<sys/types.h>".} = int32
  140. Mode* {.importc: "mode_t", header: "<sys/types.h>".} = (
  141. when defined(android) or defined(macos) or defined(macosx) or
  142. (defined(bsd) and not defined(openbsd) and not defined(netbsd)):
  143. uint16
  144. else:
  145. uint32
  146. )
  147. Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int32
  148. Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
  149. Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
  150. Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = object
  151. Pthread_barrier* {.importc: "pthread_barrier_t",
  152. header: "<sys/types.h>".} = object
  153. Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
  154. header: "<sys/types.h>".} = object
  155. Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = object
  156. Pthread_condattr* {.importc: "pthread_condattr_t",
  157. header: "<sys/types.h>".} = object
  158. Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = object
  159. Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = object
  160. Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
  161. header: "<sys/types.h>".} = object
  162. Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = object
  163. Pthread_rwlock* {.importc: "pthread_rwlock_t",
  164. header: "<sys/types.h>".} = object
  165. Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
  166. header: "<sys/types.h>".} = object
  167. Pthread_spinlock* {.importc: "pthread_spinlock_t",
  168. header: "<sys/types.h>".} = object
  169. Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = object
  170. Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int32
  171. #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
  172. Timer* {.importc: "timer_t", header: "<sys/types.h>".} = object
  173. Uid* {.importc: "uid_t", header: "<sys/types.h>".} = uint32
  174. Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = uint32
  175. Utsname* {.importc: "struct utsname",
  176. header: "<sys/utsname.h>",
  177. final, pure.} = object ## struct utsname
  178. sysname*, ## Name of this implementation of the operating system.
  179. nodename*, ## Name of this node within the communications
  180. ## network to which this node is attached, if any.
  181. release*, ## Current release level of this implementation.
  182. version*, ## Current version level of this release.
  183. machine*: array[32, char] ## Name of the hardware type on which the
  184. ## system is running.
  185. Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
  186. Ipc_perm* {.importc: "struct ipc_perm",
  187. header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
  188. uid*: Uid ## Owner's user ID.
  189. gid*: Gid ## Owner's group ID.
  190. cuid*: Uid ## Creator's user ID.
  191. cgid*: Gid ## Creator's group ID.
  192. mode*: Mode ## Read/write permission.
  193. Stat* {.importc: "struct stat",
  194. header: "<sys/stat.h>", final, pure.} = object ## struct stat
  195. st_dev*: Dev ## Device ID of device containing file.
  196. st_ino*: Ino ## File serial number.
  197. st_mode*: Mode ## Mode of file (see below).
  198. st_nlink*: Nlink ## Number of hard links to the file.
  199. st_uid*: Uid ## User ID of file.
  200. st_gid*: Gid ## Group ID of file.
  201. st_rdev*: Dev ## Device ID (if file is character or block special).
  202. st_size*: Off ## For regular files, the file size in bytes.
  203. ## For symbolic links, the length in bytes of the
  204. ## pathname contained in the symbolic link.
  205. ## For a shared memory object, the length in bytes.
  206. ## For a typed memory object, the length in bytes.
  207. ## For other file types, the use of this field is
  208. ## unspecified.
  209. when StatHasNanoseconds:
  210. st_atim*: Timespec ## Time of last access.
  211. st_mtim*: Timespec ## Time of last data modification.
  212. st_ctim*: Timespec ## Time of last status change.
  213. else:
  214. st_atime*: Time ## Time of last access.
  215. st_mtime*: Time ## Time of last data modification.
  216. st_ctime*: Time ## Time of last status change.
  217. st_blksize*: Blksize ## A file system-specific preferred I/O block size
  218. ## for this object. In some file system types, this
  219. ## may vary from file to file.
  220. st_blocks*: Blkcnt ## Number of blocks allocated for this object.
  221. Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
  222. final, pure.} = object ## struct statvfs
  223. f_bsize*: culong ## File system block size.
  224. f_frsize*: culong ## Fundamental file system block size.
  225. f_blocks*: Fsblkcnt ## Total number of blocks on file system
  226. ## in units of f_frsize.
  227. f_bfree*: Fsblkcnt ## Total number of free blocks.
  228. f_bavail*: Fsblkcnt ## Number of free blocks available to
  229. ## non-privileged process.
  230. f_files*: Fsfilcnt ## Total number of file serial numbers.
  231. f_ffree*: Fsfilcnt ## Total number of free file serial numbers.
  232. f_favail*: Fsfilcnt ## Number of file serial numbers available to
  233. ## non-privileged process.
  234. f_fsid*: culong ## File system ID.
  235. f_flag*: culong ## Bit mask of f_flag values.
  236. f_namemax*: culong ## Maximum filename length.
  237. Tm* {.importc: "struct tm", header: "<time.h>",
  238. final, pure.} = object ## struct tm
  239. tm_sec*: cint ## Seconds [0,60].
  240. tm_min*: cint ## Minutes [0,59].
  241. tm_hour*: cint ## Hour [0,23].
  242. tm_mday*: cint ## Day of month [1,31].
  243. tm_mon*: cint ## Month of year [0,11].
  244. tm_year*: cint ## Years since 1900.
  245. tm_wday*: cint ## Day of week [0,6] (Sunday =0).
  246. tm_yday*: cint ## Day of year [0,365].
  247. tm_isdst*: cint ## Daylight Savings flag.
  248. Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
  249. final, pure.} = object ## struct itimerspec
  250. it_interval*: Timespec ## Timer period.
  251. it_value*: Timespec ## Timer expiration.
  252. Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
  253. ## Possibly volatile-qualified integer type of an object that can be
  254. ## accessed as an atomic entity, even in the presence of asynchronous
  255. ## interrupts.
  256. Sigset* {.importc: "sigset_t", header: "<signal.h>".} = uint64
  257. SigEvent* {.importc: "struct sigevent",
  258. header: "<signal.h>", final, pure.} = object ## struct sigevent
  259. sigev_notify*: cint ## Notification type.
  260. sigev_signo*: cint ## Signal number.
  261. sigev_value*: SigVal ## Signal value.
  262. sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
  263. sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
  264. SigVal* {.importc: "union sigval",
  265. header: "<signal.h>", final, pure.} = object ## struct sigval
  266. sival_ptr*: pointer ## pointer signal value;
  267. ## integer signal value not defined!
  268. Sigaction* {.importc: "struct sigaction",
  269. header: "<signal.h>", final, pure.} = object ## struct sigaction
  270. sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching
  271. ## function or one of the macros
  272. ## SIG_IGN or SIG_DFL.
  273. sa_mask*: Sigset ## Set of signals to be blocked during execution of
  274. ## the signal handling function.
  275. sa_flags*: cint ## Special flags.
  276. sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
  277. Stack* {.importc: "stack_t",
  278. header: "<signal.h>", final, pure.} = object ## stack_t
  279. ss_sp*: pointer ## Stack base or pointer.
  280. ss_size*: csize_t ## Stack size.
  281. ss_flags*: cint ## Flags.
  282. SigInfo* {.importc: "siginfo_t",
  283. header: "<signal.h>", final, pure.} = object ## siginfo_t
  284. si_signo*: cint ## Signal number.
  285. si_code*: cint ## Signal code.
  286. si_errno*: cint ## If non-zero, an errno value associated with
  287. ## this signal, as defined in <errno.h>.
  288. si_pid*: Pid ## Sending process ID.
  289. si_uid*: Uid ## Real user ID of sending process.
  290. si_addr*: pointer ## Address of faulting instruction.
  291. si_status*: cint ## Exit value or signal.
  292. si_band*: int ## Band event for SIGPOLL.
  293. si_value*: SigVal ## Signal value.
  294. Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
  295. Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
  296. Sched_param* {.importc: "struct sched_param",
  297. header: "<sched.h>",
  298. final, pure.} = object ## struct sched_param
  299. sched_priority*: cint
  300. Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
  301. final, pure.} = object ## struct timeval
  302. tv_sec*: Time ## Seconds.
  303. tv_usec*: Suseconds ## Microseconds.
  304. TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
  305. final, pure.} = object
  306. Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
  307. final, pure.} = object
  308. Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
  309. final, pure.} = object ## ucontext_t
  310. uc_link*: ptr Ucontext ## Pointer to the context that is resumed
  311. ## when this context returns.
  312. uc_sigmask*: Sigset ## The set of signals that are blocked when this
  313. ## context is active.
  314. uc_stack*: Stack ## The stack used by this context.
  315. uc_mcontext*: Mcontext ## A machine-specific representation of the saved
  316. ## context.
  317. when hasAioH:
  318. type
  319. Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
  320. final, pure.} = object ## struct aiocb
  321. aio_fildes*: cint ## File descriptor.
  322. aio_offset*: Off ## File offset.
  323. aio_buf*: pointer ## Location of buffer.
  324. aio_nbytes*: int ## Length of transfer.
  325. aio_reqprio*: cint ## Request priority offset.
  326. aio_sigevent*: SigEvent ## Signal number and value.
  327. aio_lio_opcode: cint ## Operation to be performed.
  328. when hasSpawnH:
  329. type
  330. Tposix_spawnattr* {.importc: "posix_spawnattr_t",
  331. header: "<spawn.h>", final, pure.} = object
  332. Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
  333. header: "<spawn.h>", final, pure.} = object
  334. when defined(linux):
  335. # from sys/un.h
  336. const Sockaddr_un_path_length* = 108
  337. elif defined(haiku):
  338. # from sys/un.h
  339. const Sockaddr_un_path_length* = 126
  340. else:
  341. # according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html
  342. # this is >=92
  343. const Sockaddr_un_path_length* = 92
  344. type
  345. SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = uint32
  346. TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8
  347. SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
  348. pure, final.} = object ## struct sockaddr
  349. sa_family*: TSa_Family ## Address family.
  350. sa_data*: array[0..255, char] ## Socket address (variable-length data).
  351. Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
  352. pure, final.} = object ## struct sockaddr_un
  353. sun_family*: TSa_Family ## Address family.
  354. sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path
  355. Sockaddr_storage* {.importc: "struct sockaddr_storage",
  356. header: "<sys/socket.h>",
  357. pure, final.} = object ## struct sockaddr_storage
  358. ss_family*: TSa_Family ## Address family.
  359. Tif_nameindex* {.importc: "struct if_nameindex", final,
  360. pure, header: "<net/if.h>".} = object ## struct if_nameindex
  361. if_index*: cuint ## Numeric index of the interface.
  362. if_name*: cstring ## Null-terminated name of the interface.
  363. IOVec* {.importc: "struct iovec", pure, final,
  364. header: "<sys/uio.h>".} = object ## struct iovec
  365. iov_base*: pointer ## Base address of a memory region for input or output.
  366. iov_len*: csize_t ## The size of the memory pointed to by iov_base.
  367. Tmsghdr* {.importc: "struct msghdr", pure, final,
  368. header: "<sys/socket.h>".} = object ## struct msghdr
  369. msg_name*: pointer ## Optional address.
  370. msg_namelen*: SockLen ## Size of address.
  371. msg_iov*: ptr IOVec ## Scatter/gather array.
  372. msg_iovlen*: cint ## Members in msg_iov.
  373. msg_control*: pointer ## Ancillary data; see below.
  374. msg_controllen*: SockLen ## Ancillary data buffer len.
  375. msg_flags*: cint ## Flags on received message.
  376. Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
  377. header: "<sys/socket.h>".} = object ## struct cmsghdr
  378. cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
  379. cmsg_level*: cint ## Originating protocol.
  380. cmsg_type*: cint ## Protocol-specific type.
  381. TLinger* {.importc: "struct linger", pure, final,
  382. header: "<sys/socket.h>".} = object ## struct linger
  383. l_onoff*: cint ## Indicates whether linger option is enabled.
  384. l_linger*: cint ## Linger time, in seconds.
  385. InPort* = uint16
  386. InAddrScalar* = uint32
  387. InAddrT* {.importc: "in_addr_t", pure, final,
  388. header: "<netinet/in.h>".} = uint32
  389. InAddr* {.importc: "struct in_addr", pure, final,
  390. header: "<netinet/in.h>".} = object ## struct in_addr
  391. s_addr*: InAddrScalar
  392. Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
  393. header: "<netinet/in.h>".} = object ## struct sockaddr_in
  394. sin_family*: TSa_Family ## AF_INET.
  395. sin_port*: InPort ## Port number.
  396. sin_addr*: InAddr ## IP address.
  397. In6Addr* {.importc: "struct in6_addr", pure, final,
  398. header: "<netinet/in.h>".} = object ## struct in6_addr
  399. s6_addr*: array[0..15, char]
  400. Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
  401. header: "<netinet/in.h>".} = object ## struct sockaddr_in6
  402. sin6_family*: TSa_Family ## AF_INET6.
  403. sin6_port*: InPort ## Port number.
  404. sin6_flowinfo*: int32 ## IPv6 traffic class and flow information.
  405. sin6_addr*: In6Addr ## IPv6 address.
  406. sin6_scope_id*: int32 ## Set of interfaces for a scope.
  407. Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
  408. header: "<netinet/in.h>".} = object ## struct ipv6_mreq
  409. ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
  410. ipv6mr_interface*: cuint ## Interface index.
  411. Hostent* {.importc: "struct hostent", pure, final,
  412. header: "<netdb.h>".} = object ## struct hostent
  413. h_name*: cstring ## Official name of the host.
  414. h_aliases*: cstringArray ## A pointer to an array of pointers to
  415. ## alternative host names, terminated by a
  416. ## null pointer.
  417. h_addrtype*: cint ## Address type.
  418. h_length*: cint ## The length, in bytes, of the address.
  419. h_addr_list*: cstringArray ## A pointer to an array of pointers to network
  420. ## addresses (in network byte order) for the
  421. ## host, terminated by a null pointer.
  422. Tnetent* {.importc: "struct netent", pure, final,
  423. header: "<netdb.h>".} = object ## struct netent
  424. n_name*: cstring ## Official, fully-qualified (including the
  425. ## domain) name of the host.
  426. n_aliases*: cstringArray ## A pointer to an array of pointers to
  427. ## alternative network names, terminated by a
  428. ## null pointer.
  429. n_addrtype*: cint ## The address type of the network.
  430. n_net*: InAddrT ## The network number, in host byte order.
  431. Protoent* {.importc: "struct protoent", pure, final,
  432. header: "<netdb.h>".} = object ## struct protoent
  433. p_name*: cstring ## Official name of the protocol.
  434. p_aliases*: cstringArray ## A pointer to an array of pointers to
  435. ## alternative protocol names, terminated by
  436. ## a null pointer.
  437. p_proto*: cint ## The protocol number.
  438. Servent* {.importc: "struct servent", pure, final,
  439. header: "<netdb.h>".} = object ## struct servent
  440. s_name*: cstring ## Official name of the service.
  441. s_aliases*: cstringArray ## A pointer to an array of pointers to
  442. ## alternative service names, terminated by
  443. ## a null pointer.
  444. s_port*: cint ## The port number at which the service
  445. ## resides, in network byte order.
  446. s_proto*: cstring ## The name of the protocol to use when
  447. ## contacting the service.
  448. AddrInfo* {.importc: "struct addrinfo", pure, final,
  449. header: "<netdb.h>".} = object ## struct addrinfo
  450. ai_flags*: cint ## Input flags.
  451. ai_family*: cint ## Address family of socket.
  452. ai_socktype*: cint ## Socket type.
  453. ai_protocol*: cint ## Protocol of socket.
  454. ai_addrlen*: SockLen ## Length of socket address.
  455. ai_addr*: ptr SockAddr ## Socket address of socket.
  456. ai_canonname*: cstring ## Canonical name of service location.
  457. ai_next*: ptr AddrInfo ## Pointer to next in list.
  458. TPollfd* {.importc: "struct pollfd", pure, final,
  459. header: "<poll.h>".} = object ## struct pollfd
  460. fd*: cint ## The following descriptor being polled.
  461. events*: cshort ## The input event flags (see below).
  462. revents*: cshort ## The output event flags (see below).
  463. Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
  464. var
  465. errno* {.importc, header: "<errno.h>".}: cint ## error variable
  466. h_errno* {.importc, header: "<netdb.h>".}: cint
  467. daylight* {.importc, header: "<time.h>".}: cint
  468. timezone* {.importc, header: "<time.h>".}: int
  469. # Regenerate using detect.nim!
  470. include posix_other_consts
  471. when defined(linux):
  472. var
  473. MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
  474. ## Populate (prefault) page tables for a mapping.
  475. else:
  476. var
  477. MAP_POPULATE*: cint = 0
  478. when defined(linux) or defined(nimdoc):
  479. when defined(alpha) or defined(mips) or defined(mipsel) or
  480. defined(mips64) or defined(mips64el) or defined(parisc) or
  481. defined(sparc) or defined(sparc64) or defined(nimdoc):
  482. const SO_REUSEPORT* = cint(0x0200)
  483. ## Multiple binding: load balancing on incoming TCP connections
  484. ## or UDP packets. (Requires Linux kernel > 3.9)
  485. else:
  486. const SO_REUSEPORT* = cint(15)
  487. else:
  488. var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint
  489. when defined(macosx):
  490. # We can't use the NOSIGNAL flag in the `send` function, it has no effect
  491. # Instead we should use SO_NOSIGPIPE in setsockopt
  492. const
  493. MSG_NOSIGNAL* = 0'i32
  494. var
  495. SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
  496. elif defined(solaris):
  497. # Solaris doesn't have MSG_NOSIGNAL
  498. const
  499. MSG_NOSIGNAL* = 0'i32
  500. else:
  501. var
  502. MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
  503. ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected.
  504. when defined(haiku):
  505. const
  506. SIGKILLTHR* = 21 ## BeOS specific: Kill just the thread, not team
  507. when hasSpawnH:
  508. when defined(linux):
  509. # better be safe than sorry; Linux has this flag, macosx doesn't, don't
  510. # know about the other OSes
  511. # Non-GNU systems like TCC and musl-libc don't define __USE_GNU, so we
  512. # can't get the magic number from spawn.h
  513. const POSIX_SPAWN_USEVFORK* = cint(0x40)
  514. else:
  515. # macosx lacks this, so we define the constant to be 0 to not affect
  516. # OR'ing of flags:
  517. const POSIX_SPAWN_USEVFORK* = cint(0)
  518. # <sys/wait.h>
  519. proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".}
  520. ## Exit code, if WIFEXITED(s)
  521. proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
  522. ## Termination signal, if WIFSIGNALED(s)
  523. proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
  524. ## Stop signal, if WIFSTOPPED(s)
  525. proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  526. ## True if child exited normally.
  527. proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  528. ## True if child exited due to uncaught signal.
  529. proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  530. ## True if child is currently stopped.
  531. proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  532. ## True if child has been continued.
  533. when defined(nimHasStyleChecks):
  534. {.pop.}