posix_macos_amd64.nim 27 KB

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