posix_other.nim 29 KB

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