posix_macos_amd64.nim 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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 StatHasNanoseconds:
  200. st_atim*: Timespec ## Time of last access.
  201. st_mtim*: Timespec ## Time of last data modification.
  202. st_ctim*: Timespec ## Time of last status change.
  203. else:
  204. st_atime*: Time ## Time of last access.
  205. st_mtime*: Time ## Time of last data modification.
  206. st_ctime*: Time ## Time of last status change.
  207. st_blksize*: Blksize ## A file system-specific preferred I/O block size
  208. ## for this object. In some file system types, this
  209. ## may vary from file to file.
  210. st_blocks*: Blkcnt ## Number of blocks allocated for this object.
  211. Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
  212. final, pure.} = object ## struct statvfs
  213. f_bsize*: int ## File system block size.
  214. f_frsize*: int ## Fundamental file system block size.
  215. f_blocks*: Fsblkcnt ## Total number of blocks on file system
  216. ## in units of f_frsize.
  217. f_bfree*: Fsblkcnt ## Total number of free blocks.
  218. f_bavail*: Fsblkcnt ## Number of free blocks available to
  219. ## non-privileged process.
  220. f_files*: Fsfilcnt ## Total number of file serial numbers.
  221. f_ffree*: Fsfilcnt ## Total number of free file serial numbers.
  222. f_favail*: Fsfilcnt ## Number of file serial numbers available to
  223. ## non-privileged process.
  224. f_fsid*: int ## File system ID.
  225. f_flag*: int ## Bit mask of f_flag values.
  226. f_namemax*: int ## Maximum filename length.
  227. Posix_typed_mem_info* {.importc: "struct posix_typed_mem_info",
  228. header: "<sys/mman.h>", final, pure.} = object
  229. posix_tmi_length*: int
  230. Tm* {.importc: "struct tm", header: "<time.h>",
  231. final, pure.} = object ## struct tm
  232. tm_sec*: cint ## Seconds [0,60].
  233. tm_min*: cint ## Minutes [0,59].
  234. tm_hour*: cint ## Hour [0,23].
  235. tm_mday*: cint ## Day of month [1,31].
  236. tm_mon*: cint ## Month of year [0,11].
  237. tm_year*: cint ## Years since 1900.
  238. tm_wday*: cint ## Day of week [0,6] (Sunday =0).
  239. tm_yday*: cint ## Day of year [0,365].
  240. tm_isdst*: cint ## Daylight Savings flag.
  241. Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
  242. final, pure.} = object ## struct itimerspec
  243. it_interval*: Timespec ## Timer period.
  244. it_value*: Timespec ## Timer expiration.
  245. Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
  246. ## Possibly volatile-qualified integer type of an object that can be
  247. ## accessed as an atomic entity, even in the presence of asynchronous
  248. ## interrupts.
  249. Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
  250. SigEvent* {.importc: "struct sigevent",
  251. header: "<signal.h>", final, pure.} = object ## struct sigevent
  252. sigev_notify*: cint ## Notification type.
  253. sigev_signo*: cint ## Signal number.
  254. sigev_value*: SigVal ## Signal value.
  255. sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
  256. sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
  257. SigVal* {.importc: "union sigval",
  258. header: "<signal.h>", final, pure.} = object ## struct sigval
  259. sival_ptr*: pointer ## pointer signal value;
  260. ## integer signal value not defined!
  261. Sigaction* {.importc: "struct sigaction",
  262. header: "<signal.h>", final, pure.} = object ## struct sigaction
  263. sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching
  264. ## function or one of the macros
  265. ## SIG_IGN or SIG_DFL.
  266. sa_mask*: Sigset ## Set of signals to be blocked during execution of
  267. ## the signal handling function.
  268. sa_flags*: cint ## Special flags.
  269. sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
  270. Stack* {.importc: "stack_t",
  271. header: "<signal.h>", final, pure.} = object ## stack_t
  272. ss_sp*: pointer ## Stack base or pointer.
  273. ss_size*: int ## Stack size.
  274. ss_flags*: cint ## Flags.
  275. SigStack* {.importc: "struct sigstack",
  276. header: "<signal.h>", final, pure.} = object ## struct sigstack
  277. ss_onstack*: cint ## Non-zero when signal stack is in use.
  278. ss_sp*: pointer ## Signal stack pointer.
  279. SigInfo* {.importc: "siginfo_t",
  280. header: "<signal.h>", final, pure.} = object ## siginfo_t
  281. si_signo*: cint ## Signal number.
  282. si_code*: cint ## Signal code.
  283. si_errno*: cint ## If non-zero, an errno value associated with
  284. ## this signal, as defined in <errno.h>.
  285. si_pid*: Pid ## Sending process ID.
  286. si_uid*: Uid ## Real user ID of sending process.
  287. si_addr*: pointer ## Address of faulting instruction.
  288. si_status*: cint ## Exit value or signal.
  289. si_band*: int ## Band event for SIGPOLL.
  290. si_value*: SigVal ## Signal value.
  291. Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
  292. Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
  293. Sched_param* {.importc: "struct sched_param",
  294. header: "<sched.h>",
  295. final, pure.} = object ## struct sched_param
  296. sched_priority*: cint
  297. sched_ss_low_priority*: cint ## Low scheduling priority for
  298. ## sporadic server.
  299. sched_ss_repl_period*: Timespec ## Replenishment period for
  300. ## sporadic server.
  301. sched_ss_init_budget*: Timespec ## Initial budget for sporadic server.
  302. sched_ss_max_repl*: cint ## Maximum pending replenishments for
  303. ## sporadic server.
  304. Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
  305. final, pure.} = object ## struct timeval
  306. tv_sec*: Time ## Seconds.
  307. tv_usec*: Suseconds ## Microseconds.
  308. TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
  309. final, pure.} = object
  310. Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
  311. final, pure.} = object
  312. Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
  313. final, pure.} = object ## ucontext_t
  314. uc_link*: ptr Ucontext ## Pointer to the context that is resumed
  315. ## when this context returns.
  316. uc_sigmask*: Sigset ## The set of signals that are blocked when this
  317. ## context is active.
  318. uc_stack*: Stack ## The stack used by this context.
  319. uc_mcontext*: Mcontext ## A machine-specific representation of the saved
  320. ## context.
  321. when hasAioH:
  322. type
  323. Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
  324. final, pure.} = object ## struct aiocb
  325. aio_fildes*: cint ## File descriptor.
  326. aio_offset*: Off ## File offset.
  327. aio_buf*: pointer ## Location of buffer.
  328. aio_nbytes*: int ## Length of transfer.
  329. aio_reqprio*: cint ## Request priority offset.
  330. aio_sigevent*: SigEvent ## Signal number and value.
  331. aio_lio_opcode: cint ## Operation to be performed.
  332. when hasSpawnH:
  333. type
  334. Tposix_spawnattr* {.importc: "posix_spawnattr_t",
  335. header: "<spawn.h>", final, pure.} = object
  336. Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
  337. header: "<spawn.h>", final, pure.} = object
  338. when defined(linux):
  339. # from sys/un.h
  340. const Sockaddr_un_path_length* = 108
  341. else:
  342. # according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html
  343. # this is >=92
  344. const Sockaddr_un_path_length* = 92
  345. type
  346. SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
  347. TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8
  348. SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
  349. pure, final.} = object ## struct sockaddr
  350. sa_family*: TSa_Family ## Address family.
  351. sa_data*: array[0..255, char] ## Socket address (variable-length data).
  352. Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
  353. pure, final.} = object ## struct sockaddr_un
  354. sun_family*: TSa_Family ## Address family.
  355. sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path
  356. Sockaddr_storage* {.importc: "struct sockaddr_storage",
  357. header: "<sys/socket.h>",
  358. pure, final.} = object ## struct sockaddr_storage
  359. ss_family*: TSa_Family ## Address family.
  360. Tif_nameindex* {.importc: "struct if_nameindex", final,
  361. pure, header: "<net/if.h>".} = object ## struct if_nameindex
  362. if_index*: cint ## Numeric index of the interface.
  363. if_name*: cstring ## Null-terminated name of the interface.
  364. IOVec* {.importc: "struct iovec", pure, final,
  365. header: "<sys/uio.h>".} = object ## struct iovec
  366. iov_base*: pointer ## Base address of a memory region for input or output.
  367. iov_len*: int ## The size of the memory pointed to by iov_base.
  368. Tmsghdr* {.importc: "struct msghdr", pure, final,
  369. header: "<sys/socket.h>".} = object ## struct msghdr
  370. msg_name*: pointer ## Optional address.
  371. msg_namelen*: SockLen ## Size of address.
  372. msg_iov*: ptr IOVec ## Scatter/gather array.
  373. msg_iovlen*: cint ## Members in msg_iov.
  374. msg_control*: pointer ## Ancillary data; see below.
  375. msg_controllen*: SockLen ## Ancillary data buffer len.
  376. msg_flags*: cint ## Flags on received message.
  377. Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
  378. header: "<sys/socket.h>".} = object ## struct cmsghdr
  379. cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
  380. cmsg_level*: cint ## Originating protocol.
  381. cmsg_type*: cint ## Protocol-specific type.
  382. TLinger* {.importc: "struct linger", pure, final,
  383. header: "<sys/socket.h>".} = object ## struct linger
  384. l_onoff*: cint ## Indicates whether linger option is enabled.
  385. l_linger*: cint ## Linger time, in seconds.
  386. InPort* = uint16
  387. InAddrScalar* = uint32
  388. InAddrT* {.importc: "in_addr_t", pure, final,
  389. header: "<netinet/in.h>".} = uint32
  390. InAddr* {.importc: "struct in_addr", pure, final,
  391. header: "<netinet/in.h>".} = object ## struct in_addr
  392. s_addr*: InAddrScalar
  393. Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
  394. header: "<netinet/in.h>".} = object ## struct sockaddr_in
  395. sin_family*: TSa_Family ## AF_INET.
  396. sin_port*: InPort ## Port number.
  397. sin_addr*: InAddr ## IP address.
  398. In6Addr* {.importc: "struct in6_addr", pure, final,
  399. header: "<netinet/in.h>".} = object ## struct in6_addr
  400. s6_addr*: array[0..15, char]
  401. Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
  402. header: "<netinet/in.h>".} = object ## struct sockaddr_in6
  403. sin6_family*: TSa_Family ## AF_INET6.
  404. sin6_port*: InPort ## Port number.
  405. sin6_flowinfo*: int32 ## IPv6 traffic class and flow information.
  406. sin6_addr*: In6Addr ## IPv6 address.
  407. sin6_scope_id*: int32 ## Set of interfaces for a scope.
  408. Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
  409. header: "<netinet/in.h>".} = object ## struct ipv6_mreq
  410. ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
  411. ipv6mr_interface*: cint ## Interface index.
  412. Hostent* {.importc: "struct hostent", pure, final,
  413. header: "<netdb.h>".} = object ## struct hostent
  414. h_name*: cstring ## Official name of the host.
  415. h_aliases*: cstringArray ## A pointer to an array of pointers to
  416. ## alternative host names, terminated by a
  417. ## null pointer.
  418. h_addrtype*: cint ## Address type.
  419. h_length*: cint ## The length, in bytes, of the address.
  420. h_addr_list*: cstringArray ## A pointer to an array of pointers to network
  421. ## addresses (in network byte order) for the
  422. ## host, terminated by a null pointer.
  423. Tnetent* {.importc: "struct netent", pure, final,
  424. header: "<netdb.h>".} = object ## struct netent
  425. n_name*: cstring ## Official, fully-qualified (including the
  426. ## domain) name of the host.
  427. n_aliases*: cstringArray ## A pointer to an array of pointers to
  428. ## alternative network names, terminated by a
  429. ## null pointer.
  430. n_addrtype*: cint ## The address type of the network.
  431. n_net*: int32 ## The network number, in host byte order.
  432. Protoent* {.importc: "struct protoent", pure, final,
  433. header: "<netdb.h>".} = object ## struct protoent
  434. p_name*: cstring ## Official name of the protocol.
  435. p_aliases*: cstringArray ## A pointer to an array of pointers to
  436. ## alternative protocol names, terminated by
  437. ## a null pointer.
  438. p_proto*: cint ## The protocol number.
  439. Servent* {.importc: "struct servent", pure, final,
  440. header: "<netdb.h>".} = object ## struct servent
  441. s_name*: cstring ## Official name of the service.
  442. s_aliases*: cstringArray ## A pointer to an array of pointers to
  443. ## alternative service names, terminated by
  444. ## a null pointer.
  445. s_port*: cint ## The port number at which the service
  446. ## resides, in network byte order.
  447. s_proto*: cstring ## The name of the protocol to use when
  448. ## contacting the service.
  449. AddrInfo* {.importc: "struct addrinfo", pure, final,
  450. header: "<netdb.h>".} = object ## struct addrinfo
  451. ai_flags*: cint ## Input flags.
  452. ai_family*: cint ## Address family of socket.
  453. ai_socktype*: cint ## Socket type.
  454. ai_protocol*: cint ## Protocol of socket.
  455. ai_addrlen*: SockLen ## Length of socket address.
  456. ai_addr*: ptr SockAddr ## Socket address of socket.
  457. ai_canonname*: cstring ## Canonical name of service location.
  458. ai_next*: ptr AddrInfo ## Pointer to next in list.
  459. TPollfd* {.importc: "struct pollfd", pure, final,
  460. header: "<poll.h>".} = object ## struct pollfd
  461. fd*: cint ## The following descriptor being polled.
  462. events*: cshort ## The input event flags (see below).
  463. revents*: cshort ## The output event flags (see below).
  464. Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint
  465. var
  466. errno* {.importc, header: "<errno.h>".}: cint ## error variable
  467. h_errno* {.importc, header: "<netdb.h>".}: cint
  468. daylight* {.importc, header: "<time.h>".}: cint
  469. timezone* {.importc, header: "<time.h>".}: int
  470. # Regenerate using detect.nim!
  471. include posix_other_consts
  472. when defined(linux):
  473. var
  474. MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
  475. ## Populate (prefault) page tables for a mapping.
  476. else:
  477. var
  478. MAP_POPULATE*: cint = 0
  479. when defined(linux) or defined(nimdoc):
  480. when defined(alpha) or defined(mips) or defined(mipsel) or
  481. defined(mips64) or defined(mips64el) or defined(parisc) or
  482. defined(sparc) or defined(sparc64) or defined(nimdoc):
  483. const SO_REUSEPORT* = cint(0x0200)
  484. ## Multiple binding: load balancing on incoming TCP connections
  485. ## or UDP packets. (Requires Linux kernel > 3.9)
  486. else:
  487. const SO_REUSEPORT* = cint(15)
  488. else:
  489. var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint
  490. when defined(macosx):
  491. # We can't use the NOSIGNAL flag in the ``send`` function, it has no effect
  492. # Instead we should use SO_NOSIGPIPE in setsockopt
  493. const
  494. MSG_NOSIGNAL* = 0'i32
  495. var
  496. SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
  497. elif defined(solaris):
  498. # Solaris doesn't have MSG_NOSIGNAL
  499. const
  500. MSG_NOSIGNAL* = 0'i32
  501. else:
  502. var
  503. MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
  504. ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected.
  505. when defined(haiku):
  506. const
  507. SIGKILLTHR* = 21 ## BeOS specific: Kill just the thread, not team
  508. when hasSpawnH:
  509. when defined(linux):
  510. # better be safe than sorry; Linux has this flag, macosx doesn't, don't
  511. # know about the other OSes
  512. # Non-GNU systems like TCC and musl-libc don't define __USE_GNU, so we
  513. # can't get the magic number from spawn.h
  514. const POSIX_SPAWN_USEVFORK* = cint(0x40)
  515. else:
  516. # macosx lacks this, so we define the constant to be 0 to not affect
  517. # OR'ing of flags:
  518. const POSIX_SPAWN_USEVFORK* = cint(0)
  519. # <sys/wait.h>
  520. proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".}
  521. ## Exit code, iff WIFEXITED(s)
  522. proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
  523. ## Termination signal, iff WIFSIGNALED(s)
  524. proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
  525. ## Stop signal, iff WIFSTOPPED(s)
  526. proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  527. ## True if child exited normally.
  528. proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  529. ## True if child exited due to uncaught signal.
  530. proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  531. ## True if child is currently stopped.
  532. proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
  533. ## True if child has been continued.
  534. when defined(nimHasStyleChecks):
  535. {.pop.}