posix_other.nim 29 KB

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