posix_other.nim 27 KB

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