posix.nim 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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. # Until std_arg!!
  10. # done: ipc, pwd, stat, semaphore, sys/types, sys/utsname, pthread, unistd,
  11. # statvfs, mman, time, wait, signal, nl_types, sched, spawn, select, ucontext,
  12. # net/if, sys/socket, sys/uio, netinet/in, netinet/tcp, netdb
  13. ## This is a raw POSIX interface module. It does not not provide any
  14. ## convenience: cstrings are used instead of proper Nim strings and
  15. ## return codes indicate errors. If you want exceptions
  16. ## and a proper Nim-like interface, use the OS module or write a wrapper.
  17. ##
  18. ## For high-level wrappers specialized for Linux and BSDs see:
  19. ## `posix_utils <posix_utils.html>`_
  20. ##
  21. ## Coding conventions:
  22. ## ALL types are named the same as in the POSIX standard except that they start
  23. ## with 'T' or 'P' (if they are pointers) and without the '_t' suffix to be
  24. ## consistent with Nim conventions. If an identifier is a Nim keyword
  25. ## the \`identifier\` notation is used.
  26. ##
  27. ## This library relies on the header files of your C compiler. The
  28. ## resulting C code will just `#include <XYZ.h>` and *not* define the
  29. ## symbols declared here.
  30. # Dead code elimination ensures that we don't accidentally generate #includes
  31. # for files that might not exist on a specific platform! The user will get an
  32. # error only if they actually try to use the missing declaration
  33. when defined(nimHasStyleChecks):
  34. {.push styleChecks: off.}
  35. when defined(nimPreviewSlimSystem):
  36. import std/syncio
  37. # TODO these constants don't seem to be fetched from a header file for unknown
  38. # platforms - where do they come from and why are they here?
  39. when false:
  40. const
  41. C_IRUSR = 0o000400 ## Read by owner.
  42. C_IWUSR = 0o000200 ## Write by owner.
  43. C_IXUSR = 0o000100 ## Execute by owner.
  44. C_IRGRP = 0o000040 ## Read by group.
  45. C_IWGRP = 0o000020 ## Write by group.
  46. C_IXGRP = 0o000010 ## Execute by group.
  47. C_IROTH = 0o000004 ## Read by others.
  48. C_IWOTH = 0o000002 ## Write by others.
  49. C_IXOTH = 0o000001 ## Execute by others.
  50. C_ISUID = 0o004000 ## Set user ID.
  51. C_ISGID = 0o002000 ## Set group ID.
  52. C_ISVTX = 0o001000 ## On directories, restricted deletion flag.
  53. C_ISDIR = 0o040000 ## Directory.
  54. C_ISFIFO = 0o010000 ##FIFO.
  55. C_ISREG = 0o100000 ## Regular file.
  56. C_ISBLK = 0o060000 ## Block special.
  57. C_ISCHR = 0o020000 ## Character special.
  58. C_ISCTG = 0o110000 ## Reserved.
  59. C_ISLNK = 0o120000 ## Symbolic link.</p>
  60. C_ISSOCK = 0o140000 ## Socket.
  61. const
  62. MM_NULLLBL* = nil
  63. MM_NULLSEV* = 0
  64. MM_NULLMC* = 0
  65. MM_NULLTXT* = nil
  66. MM_NULLACT* = nil
  67. MM_NULLTAG* = nil
  68. STDERR_FILENO* = 2 ## File number of stderr;
  69. STDIN_FILENO* = 0 ## File number of stdin;
  70. STDOUT_FILENO* = 1 ## File number of stdout;
  71. DT_UNKNOWN* = 0 ## Unknown file type.
  72. DT_FIFO* = 1 ## Named pipe, or FIFO.
  73. DT_CHR* = 2 ## Character device.
  74. DT_DIR* = 4 ## Directory.
  75. DT_BLK* = 6 ## Block device.
  76. DT_REG* = 8 ## Regular file.
  77. DT_LNK* = 10 ## Symbolic link.
  78. DT_SOCK* = 12 ## UNIX domain socket.
  79. DT_WHT* = 14
  80. # Special types
  81. type Sighandler = proc (a: cint) {.noconv.}
  82. const StatHasNanoseconds* = defined(linux) or defined(freebsd) or
  83. defined(osx) or defined(openbsd) or defined(dragonfly) or defined(haiku) ## \
  84. ## Boolean flag that indicates if the system supports nanosecond time
  85. ## resolution in the fields of `Stat`. Note that the nanosecond based fields
  86. ## (`Stat.st_atim`, `Stat.st_mtim` and `Stat.st_ctim`) can be accessed
  87. ## without checking this flag, because this module defines fallback procs
  88. ## when they are not available.
  89. # Platform specific stuff
  90. when (defined(linux) and not defined(android)) and defined(amd64):
  91. include posix_linux_amd64
  92. elif defined(openbsd) and defined(amd64):
  93. include posix_openbsd_amd64
  94. elif (defined(macos) or defined(macosx) or defined(bsd)) and defined(cpu64):
  95. include posix_macos_amd64
  96. elif defined(nintendoswitch):
  97. include posix_nintendoswitch
  98. elif defined(haiku):
  99. include posix_haiku
  100. else:
  101. include posix_other
  102. # There used to be this name in posix.nim a long time ago, not sure why!
  103. when StatHasNanoseconds:
  104. proc st_atime*(s: Stat): Time {.inline.} =
  105. ## Second-granularity time of last access.
  106. result = s.st_atim.tv_sec
  107. proc st_mtime*(s: Stat): Time {.inline.} =
  108. ## Second-granularity time of last data modification.
  109. result = s.st_mtim.tv_sec
  110. proc st_ctime*(s: Stat): Time {.inline.} =
  111. ## Second-granularity time of last status change.
  112. result = s.st_ctim.tv_sec
  113. else:
  114. proc st_atim*(s: Stat): Timespec {.inline.} =
  115. ## Nanosecond-granularity time of last access.
  116. result.tv_sec = s.st_atime
  117. proc st_mtim*(s: Stat): Timespec {.inline.} =
  118. ## Nanosecond-granularity time of last data modification.
  119. result.tv_sec = s.st_mtime
  120. proc st_ctim*(s: Stat): Timespec {.inline.} =
  121. ## Nanosecond-granularity time of last data modification.
  122. result.tv_sec = s.st_ctime
  123. when hasAioH:
  124. proc aio_cancel*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
  125. proc aio_error*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
  126. proc aio_fsync*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
  127. proc aio_read*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
  128. proc aio_return*(a1: ptr Taiocb): int {.importc, header: "<aio.h>".}
  129. proc aio_suspend*(a1: ptr ptr Taiocb, a2: cint, a3: ptr Timespec): cint {.
  130. importc, header: "<aio.h>".}
  131. proc aio_write*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
  132. proc lio_listio*(a1: cint, a2: ptr ptr Taiocb, a3: cint,
  133. a4: ptr SigEvent): cint {.importc, header: "<aio.h>".}
  134. # arpa/inet.h
  135. proc htonl*(a1: uint32): uint32 {.importc, header: "<arpa/inet.h>".}
  136. proc htons*(a1: uint16): uint16 {.importc, header: "<arpa/inet.h>".}
  137. proc ntohl*(a1: uint32): uint32 {.importc, header: "<arpa/inet.h>".}
  138. proc ntohs*(a1: uint16): uint16 {.importc, header: "<arpa/inet.h>".}
  139. when not defined(zephyr):
  140. proc inet_addr*(a1: cstring): InAddrT {.importc, header: "<arpa/inet.h>".}
  141. proc inet_ntoa*(a1: InAddr): cstring {.importc, header: "<arpa/inet.h>".}
  142. proc inet_ntop*(a1: cint, a2: pointer | ptr InAddr | ptr In6Addr, a3: cstring, a4: int32): cstring {.
  143. importc:"(char *)$1", header: "<arpa/inet.h>".}
  144. proc inet_pton*(a1: cint, a2: cstring, a3: pointer | ptr InAddr | ptr In6Addr): cint {.
  145. importc, header: "<arpa/inet.h>".}
  146. var
  147. in6addr_any* {.importc, header: "<netinet/in.h>".}: In6Addr
  148. in6addr_loopback* {.importc, header: "<netinet/in.h>".}: In6Addr
  149. proc IN6ADDR_ANY_INIT* (): In6Addr {.importc, header: "<netinet/in.h>".}
  150. proc IN6ADDR_LOOPBACK_INIT* (): In6Addr {.importc, header: "<netinet/in.h>".}
  151. # dirent.h
  152. proc closedir*(a1: ptr DIR): cint {.importc, header: "<dirent.h>".}
  153. proc opendir*(a1: cstring): ptr DIR {.importc, header: "<dirent.h>", sideEffect.}
  154. proc readdir*(a1: ptr DIR): ptr Dirent {.importc, header: "<dirent.h>", sideEffect.}
  155. proc readdir_r*(a1: ptr DIR, a2: ptr Dirent, a3: ptr ptr Dirent): cint {.
  156. importc, header: "<dirent.h>", sideEffect.}
  157. proc rewinddir*(a1: ptr DIR) {.importc, header: "<dirent.h>".}
  158. proc seekdir*(a1: ptr DIR, a2: int) {.importc, header: "<dirent.h>".}
  159. proc telldir*(a1: ptr DIR): int {.importc, header: "<dirent.h>".}
  160. # dlfcn.h
  161. proc dlclose*(a1: pointer): cint {.importc, header: "<dlfcn.h>", sideEffect.}
  162. proc dlerror*(): cstring {.importc, header: "<dlfcn.h>", sideEffect.}
  163. proc dlopen*(a1: cstring, a2: cint): pointer {.importc, header: "<dlfcn.h>", sideEffect.}
  164. proc dlsym*(a1: pointer, a2: cstring): pointer {.importc, header: "<dlfcn.h>", sideEffect.}
  165. proc creat*(a1: cstring, a2: Mode): cint {.importc, header: "<fcntl.h>", sideEffect.}
  166. proc fcntl*(a1: cint | SocketHandle, a2: cint): cint {.varargs, importc, header: "<fcntl.h>", sideEffect.}
  167. proc openImpl(a1: cstring, a2: cint): cint {.varargs, importc: "open", header: "<fcntl.h>", sideEffect.}
  168. proc open*(a1: cstring, a2: cint, mode: Mode | cint = 0.Mode): cint {.inline.} =
  169. # prevents bug #17888
  170. openImpl(a1, a2, mode)
  171. proc posix_fadvise*(a1: cint, a2, a3: Off, a4: cint): cint {.
  172. importc, header: "<fcntl.h>".}
  173. proc posix_fallocate*(a1: cint, a2, a3: Off): cint {.
  174. importc, header: "<fcntl.h>".}
  175. when not defined(haiku) and not defined(openbsd):
  176. proc fmtmsg*(a1: int, a2: cstring, a3: cint,
  177. a4, a5, a6: cstring): cint {.importc, header: "<fmtmsg.h>".}
  178. proc fnmatch*(a1, a2: cstring, a3: cint): cint {.importc, header: "<fnmatch.h>".}
  179. proc ftw*(a1: cstring,
  180. a2: proc (x1: cstring, x2: ptr Stat, x3: cint): cint {.noconv.},
  181. a3: cint): cint {.importc, header: "<ftw.h>".}
  182. when not (defined(linux) and defined(amd64)) and not defined(nintendoswitch):
  183. proc nftw*(a1: cstring,
  184. a2: proc (x1: cstring, x2: ptr Stat,
  185. x3: cint, x4: ptr FTW): cint {.noconv.},
  186. a3: cint,
  187. a4: cint): cint {.importc, header: "<ftw.h>".}
  188. proc glob*(a1: cstring, a2: cint,
  189. a3: proc (x1: cstring, x2: cint): cint {.noconv.},
  190. a4: ptr Glob): cint {.importc, header: "<glob.h>", sideEffect.}
  191. ## Filename globbing. Use `os.walkPattern() <os.html#glob_1>`_ and similar.
  192. proc globfree*(a1: ptr Glob) {.importc, header: "<glob.h>".}
  193. proc getgrgid*(a1: Gid): ptr Group {.importc, header: "<grp.h>".}
  194. proc getgrnam*(a1: cstring): ptr Group {.importc, header: "<grp.h>".}
  195. proc getgrgid_r*(a1: Gid, a2: ptr Group, a3: cstring, a4: int,
  196. a5: ptr ptr Group): cint {.importc, header: "<grp.h>".}
  197. proc getgrnam_r*(a1: cstring, a2: ptr Group, a3: cstring,
  198. a4: int, a5: ptr ptr Group): cint {.
  199. importc, header: "<grp.h>".}
  200. proc getgrent*(): ptr Group {.importc, header: "<grp.h>".}
  201. proc endgrent*() {.importc, header: "<grp.h>".}
  202. proc setgrent*() {.importc, header: "<grp.h>".}
  203. proc iconv_open*(a1, a2: cstring): Iconv {.importc, header: "<iconv.h>".}
  204. proc iconv*(a1: Iconv, a2: var cstring, a3: var int, a4: var cstring,
  205. a5: var int): int {.importc, header: "<iconv.h>".}
  206. proc iconv_close*(a1: Iconv): cint {.importc, header: "<iconv.h>".}
  207. proc nl_langinfo*(a1: Nl_item): cstring {.importc, header: "<langinfo.h>".}
  208. proc basename*(a1: cstring): cstring {.importc, header: "<libgen.h>".}
  209. proc dirname*(a1: cstring): cstring {.importc, header: "<libgen.h>".}
  210. proc localeconv*(): ptr Lconv {.importc, header: "<locale.h>".}
  211. proc setlocale*(a1: cint, a2: cstring): cstring {.
  212. importc, header: "<locale.h>", sideEffect.}
  213. proc strfmon*(a1: cstring, a2: int, a3: cstring): int {.varargs,
  214. importc, header: "<monetary.h>".}
  215. when not (defined(nintendoswitch) or defined(macos) or defined(macosx)):
  216. proc mq_notify*(mqdes: Mqd, event: ptr SigEvent): cint {.
  217. importc, header: "<mqueue.h>".}
  218. proc mq_open*(name: cstring, flags: cint): Mqd {.
  219. varargs, importc, header: "<mqueue.h>".}
  220. proc mq_close*(mqdes: Mqd): cint {.importc, header: "<mqueue.h>".}
  221. proc mq_receive*(
  222. mqdes: Mqd,
  223. buffer: cstring,
  224. length: csize_t,
  225. priority: var cuint
  226. ): int {.importc, header: "<mqueue.h>".}
  227. proc mq_timedreceive*(
  228. mqdes: Mqd,
  229. buffer: cstring,
  230. length: csize_t,
  231. priority: cuint,
  232. timeout: ptr Timespec
  233. ): int {.importc, header: "<mqueue.h>".}
  234. proc mq_send*(
  235. mqdes: Mqd,
  236. buffer: cstring,
  237. length: csize_t,
  238. priority: cuint
  239. ): cint {.importc, header: "<mqueue.h>".}
  240. proc mq_timedsend*(
  241. mqdes: Mqd,
  242. buffer: cstring,
  243. length: csize_t,
  244. priority: cuint,
  245. timeout: ptr Timespec
  246. ): cint {.importc, header: "<mqueue.h>".}
  247. proc mq_getattr*(mqdes: Mqd, attribute: ptr MqAttr): cint {.
  248. importc, header: "<mqueue.h>".}
  249. proc mq_setattr*(mqdes: Mqd, newAttribute, oldAttribute: ptr MqAttr): cint {.
  250. importc, header: "<mqueue.h>".}
  251. proc mq_unlink*(mqdes: cstring): cint {.importc, header: "<mqueue.h>".}
  252. proc getpwnam*(a1: cstring): ptr Passwd {.importc, header: "<pwd.h>".}
  253. proc getpwuid*(a1: Uid): ptr Passwd {.importc, header: "<pwd.h>".}
  254. proc getpwnam_r*(a1: cstring, a2: ptr Passwd, a3: cstring, a4: int,
  255. a5: ptr ptr Passwd): cint {.importc, header: "<pwd.h>".}
  256. proc getpwuid_r*(a1: Uid, a2: ptr Passwd, a3: cstring,
  257. a4: int, a5: ptr ptr Passwd): cint {.importc, header: "<pwd.h>".}
  258. proc endpwent*() {.importc, header: "<pwd.h>".}
  259. proc getpwent*(): ptr Passwd {.importc, header: "<pwd.h>".}
  260. proc setpwent*() {.importc, header: "<pwd.h>".}
  261. proc uname*(a1: var Utsname): cint {.importc, header: "<sys/utsname.h>".}
  262. proc strerror*(errnum: cint): cstring {.importc, header: "<string.h>".}
  263. proc pthread_atfork*(a1, a2, a3: proc () {.noconv.}): cint {.
  264. importc, header: "<pthread.h>".}
  265. proc pthread_attr_destroy*(a1: ptr Pthread_attr): cint {.
  266. importc, header: "<pthread.h>".}
  267. proc pthread_attr_getdetachstate*(a1: ptr Pthread_attr, a2: cint): cint {.
  268. importc, header: "<pthread.h>".}
  269. proc pthread_attr_getguardsize*(a1: ptr Pthread_attr, a2: var cint): cint {.
  270. importc, header: "<pthread.h>".}
  271. proc pthread_attr_getinheritsched*(a1: ptr Pthread_attr,
  272. a2: var cint): cint {.importc, header: "<pthread.h>".}
  273. proc pthread_attr_getschedparam*(a1: ptr Pthread_attr,
  274. a2: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
  275. proc pthread_attr_getschedpolicy*(a1: ptr Pthread_attr,
  276. a2: var cint): cint {.importc, header: "<pthread.h>".}
  277. proc pthread_attr_getscope*(a1: ptr Pthread_attr,
  278. a2: var cint): cint {.importc, header: "<pthread.h>".}
  279. proc pthread_attr_getstack*(a1: ptr Pthread_attr,
  280. a2: var pointer, a3: var int): cint {.importc, header: "<pthread.h>".}
  281. proc pthread_attr_getstackaddr*(a1: ptr Pthread_attr,
  282. a2: var pointer): cint {.importc, header: "<pthread.h>".}
  283. proc pthread_attr_getstacksize*(a1: ptr Pthread_attr,
  284. a2: var int): cint {.importc, header: "<pthread.h>".}
  285. proc pthread_attr_init*(a1: ptr Pthread_attr): cint {.
  286. importc, header: "<pthread.h>".}
  287. proc pthread_attr_setdetachstate*(a1: ptr Pthread_attr, a2: cint): cint {.
  288. importc, header: "<pthread.h>".}
  289. proc pthread_attr_setguardsize*(a1: ptr Pthread_attr, a2: int): cint {.
  290. importc, header: "<pthread.h>".}
  291. proc pthread_attr_setinheritsched*(a1: ptr Pthread_attr, a2: cint): cint {.
  292. importc, header: "<pthread.h>".}
  293. proc pthread_attr_setschedparam*(a1: ptr Pthread_attr,
  294. a2: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
  295. proc pthread_attr_setschedpolicy*(a1: ptr Pthread_attr, a2: cint): cint {.
  296. importc, header: "<pthread.h>".}
  297. proc pthread_attr_setscope*(a1: ptr Pthread_attr, a2: cint): cint {.importc,
  298. header: "<pthread.h>".}
  299. proc pthread_attr_setstack*(a1: ptr Pthread_attr, a2: pointer, a3: int): cint {.
  300. importc, header: "<pthread.h>".}
  301. proc pthread_attr_setstackaddr*(a1: ptr Pthread_attr, a2: pointer): cint {.
  302. importc, header: "<pthread.h>".}
  303. proc pthread_attr_setstacksize*(a1: ptr Pthread_attr, a2: int): cint {.
  304. importc, header: "<pthread.h>".}
  305. proc pthread_barrier_destroy*(a1: ptr Pthread_barrier): cint {.
  306. importc, header: "<pthread.h>".}
  307. proc pthread_barrier_init*(a1: ptr Pthread_barrier,
  308. a2: ptr Pthread_barrierattr, a3: cint): cint {.
  309. importc, header: "<pthread.h>".}
  310. proc pthread_barrier_wait*(a1: ptr Pthread_barrier): cint {.
  311. importc, header: "<pthread.h>".}
  312. proc pthread_barrierattr_destroy*(a1: ptr Pthread_barrierattr): cint {.
  313. importc, header: "<pthread.h>".}
  314. proc pthread_barrierattr_getpshared*(
  315. a1: ptr Pthread_barrierattr, a2: var cint): cint {.
  316. importc, header: "<pthread.h>".}
  317. proc pthread_barrierattr_init*(a1: ptr Pthread_barrierattr): cint {.
  318. importc, header: "<pthread.h>".}
  319. proc pthread_barrierattr_setpshared*(a1: ptr Pthread_barrierattr,
  320. a2: cint): cint {.importc, header: "<pthread.h>".}
  321. proc pthread_cancel*(a1: Pthread): cint {.importc, header: "<pthread.h>".}
  322. proc pthread_cleanup_push*(a1: proc (x: pointer) {.noconv.}, a2: pointer) {.
  323. importc, header: "<pthread.h>".}
  324. proc pthread_cleanup_pop*(a1: cint) {.importc, header: "<pthread.h>".}
  325. proc pthread_cond_broadcast*(a1: ptr Pthread_cond): cint {.
  326. importc, header: "<pthread.h>".}
  327. proc pthread_cond_destroy*(a1: ptr Pthread_cond): cint {.importc, header: "<pthread.h>".}
  328. proc pthread_cond_init*(a1: ptr Pthread_cond,
  329. a2: ptr Pthread_condattr): cint {.importc, header: "<pthread.h>".}
  330. proc pthread_cond_signal*(a1: ptr Pthread_cond): cint {.importc, header: "<pthread.h>".}
  331. proc pthread_cond_timedwait*(a1: ptr Pthread_cond,
  332. a2: ptr Pthread_mutex, a3: ptr Timespec): cint {.importc, header: "<pthread.h>".}
  333. proc pthread_cond_wait*(a1: ptr Pthread_cond,
  334. a2: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
  335. proc pthread_condattr_destroy*(a1: ptr Pthread_condattr): cint {.importc, header: "<pthread.h>".}
  336. proc pthread_condattr_getclock*(a1: ptr Pthread_condattr,
  337. a2: var ClockId): cint {.importc, header: "<pthread.h>".}
  338. proc pthread_condattr_getpshared*(a1: ptr Pthread_condattr,
  339. a2: var cint): cint {.importc, header: "<pthread.h>".}
  340. proc pthread_condattr_init*(a1: ptr Pthread_condattr): cint {.importc, header: "<pthread.h>".}
  341. proc pthread_condattr_setclock*(a1: ptr Pthread_condattr,a2: ClockId): cint {.importc, header: "<pthread.h>".}
  342. proc pthread_condattr_setpshared*(a1: ptr Pthread_condattr, a2: cint): cint {.importc, header: "<pthread.h>".}
  343. proc pthread_create*(a1: ptr Pthread, a2: ptr Pthread_attr,
  344. a3: proc (x: pointer): pointer {.noconv.}, a4: pointer): cint {.importc, header: "<pthread.h>".}
  345. proc pthread_detach*(a1: Pthread): cint {.importc, header: "<pthread.h>".}
  346. proc pthread_equal*(a1, a2: Pthread): cint {.importc, header: "<pthread.h>".}
  347. proc pthread_exit*(a1: pointer) {.importc, header: "<pthread.h>".}
  348. proc pthread_getconcurrency*(): cint {.importc, header: "<pthread.h>".}
  349. proc pthread_getcpuclockid*(a1: Pthread, a2: var ClockId): cint {.importc, header: "<pthread.h>".}
  350. proc pthread_getschedparam*(a1: Pthread, a2: var cint,
  351. a3: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
  352. proc pthread_getspecific*(a1: Pthread_key): pointer {.importc, header: "<pthread.h>".}
  353. proc pthread_join*(a1: Pthread, a2: ptr pointer): cint {.importc, header: "<pthread.h>".}
  354. proc pthread_key_create*(a1: ptr Pthread_key, a2: proc (x: pointer) {.noconv.}): cint {.importc, header: "<pthread.h>".}
  355. proc pthread_key_delete*(a1: Pthread_key): cint {.importc, header: "<pthread.h>".}
  356. proc pthread_mutex_destroy*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
  357. proc pthread_mutex_getprioceiling*(a1: ptr Pthread_mutex,
  358. a2: var cint): cint {.importc, header: "<pthread.h>".}
  359. proc pthread_mutex_init*(a1: ptr Pthread_mutex,
  360. a2: ptr Pthread_mutexattr): cint {.importc, header: "<pthread.h>".}
  361. proc pthread_mutex_lock*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
  362. proc pthread_mutex_setprioceiling*(a1: ptr Pthread_mutex,a2: cint,
  363. a3: var cint): cint {.importc, header: "<pthread.h>".}
  364. proc pthread_mutex_timedlock*(a1: ptr Pthread_mutex,
  365. a2: ptr Timespec): cint {.importc, header: "<pthread.h>".}
  366. proc pthread_mutex_trylock*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
  367. proc pthread_mutex_unlock*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
  368. proc pthread_mutexattr_destroy*(a1: ptr Pthread_mutexattr): cint {.importc, header: "<pthread.h>".}
  369. proc pthread_mutexattr_getprioceiling*(
  370. a1: ptr Pthread_mutexattr, a2: var cint): cint {.importc, header: "<pthread.h>".}
  371. proc pthread_mutexattr_getprotocol*(a1: ptr Pthread_mutexattr,
  372. a2: var cint): cint {.importc, header: "<pthread.h>".}
  373. proc pthread_mutexattr_getpshared*(a1: ptr Pthread_mutexattr,
  374. a2: var cint): cint {.importc, header: "<pthread.h>".}
  375. proc pthread_mutexattr_gettype*(a1: ptr Pthread_mutexattr,
  376. a2: var cint): cint {.importc, header: "<pthread.h>".}
  377. proc pthread_mutexattr_init*(a1: ptr Pthread_mutexattr): cint {.importc, header: "<pthread.h>".}
  378. proc pthread_mutexattr_setprioceiling*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
  379. proc pthread_mutexattr_setprotocol*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
  380. proc pthread_mutexattr_setpshared*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
  381. proc pthread_mutexattr_settype*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
  382. proc pthread_once*(a1: ptr Pthread_once, a2: proc () {.noconv.}): cint {.importc, header: "<pthread.h>".}
  383. proc pthread_rwlock_destroy*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
  384. proc pthread_rwlock_init*(a1: ptr Pthread_rwlock,
  385. a2: ptr Pthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
  386. proc pthread_rwlock_rdlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
  387. proc pthread_rwlock_timedrdlock*(a1: ptr Pthread_rwlock,
  388. a2: ptr Timespec): cint {.importc, header: "<pthread.h>".}
  389. proc pthread_rwlock_timedwrlock*(a1: ptr Pthread_rwlock,
  390. a2: ptr Timespec): cint {.importc, header: "<pthread.h>".}
  391. proc pthread_rwlock_tryrdlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
  392. proc pthread_rwlock_trywrlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
  393. proc pthread_rwlock_unlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
  394. proc pthread_rwlock_wrlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
  395. proc pthread_rwlockattr_destroy*(a1: ptr Pthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
  396. proc pthread_rwlockattr_getpshared*(
  397. a1: ptr Pthread_rwlockattr, a2: var cint): cint {.importc, header: "<pthread.h>".}
  398. proc pthread_rwlockattr_init*(a1: ptr Pthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
  399. proc pthread_rwlockattr_setpshared*(a1: ptr Pthread_rwlockattr, a2: cint): cint {.importc, header: "<pthread.h>".}
  400. proc pthread_self*(): Pthread {.importc, header: "<pthread.h>".}
  401. proc pthread_setcancelstate*(a1: cint, a2: var cint): cint {.importc, header: "<pthread.h>".}
  402. proc pthread_setcanceltype*(a1: cint, a2: var cint): cint {.importc, header: "<pthread.h>".}
  403. proc pthread_setconcurrency*(a1: cint): cint {.importc, header: "<pthread.h>".}
  404. proc pthread_setschedparam*(a1: Pthread, a2: cint,
  405. a3: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
  406. proc pthread_setschedprio*(a1: Pthread, a2: cint): cint {.
  407. importc, header: "<pthread.h>".}
  408. proc pthread_setspecific*(a1: Pthread_key, a2: pointer): cint {.
  409. importc, header: "<pthread.h>".}
  410. proc pthread_spin_destroy*(a1: ptr Pthread_spinlock): cint {.
  411. importc, header: "<pthread.h>".}
  412. proc pthread_spin_init*(a1: ptr Pthread_spinlock, a2: cint): cint {.
  413. importc, header: "<pthread.h>".}
  414. proc pthread_spin_lock*(a1: ptr Pthread_spinlock): cint {.
  415. importc, header: "<pthread.h>".}
  416. proc pthread_spin_trylock*(a1: ptr Pthread_spinlock): cint{.
  417. importc, header: "<pthread.h>".}
  418. proc pthread_spin_unlock*(a1: ptr Pthread_spinlock): cint {.
  419. importc, header: "<pthread.h>".}
  420. proc pthread_testcancel*() {.importc, header: "<pthread.h>".}
  421. proc exitnow*(code: int) {.importc: "_exit", header: "<unistd.h>".}
  422. proc access*(a1: cstring, a2: cint): cint {.importc, header: "<unistd.h>".}
  423. proc alarm*(a1: cint): cint {.importc, header: "<unistd.h>".}
  424. proc chdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
  425. proc chown*(a1: cstring, a2: Uid, a3: Gid): cint {.importc, header: "<unistd.h>".}
  426. proc close*(a1: cint | SocketHandle): cint {.importc, header: "<unistd.h>".}
  427. proc confstr*(a1: cint, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
  428. proc crypt*(a1, a2: cstring): cstring {.importc, header: "<unistd.h>".}
  429. proc ctermid*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
  430. proc dup*(a1: cint): cint {.importc, header: "<unistd.h>".}
  431. proc dup2*(a1, a2: cint): cint {.importc, header: "<unistd.h>".}
  432. proc encrypt*(a1: array[0..63, char], a2: cint) {.importc, header: "<unistd.h>".}
  433. proc execl*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>", sideEffect.}
  434. proc execle*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>", sideEffect.}
  435. proc execlp*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>", sideEffect.}
  436. proc execv*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>", sideEffect.}
  437. proc execve*(a1: cstring, a2, a3: cstringArray): cint {.
  438. importc, header: "<unistd.h>", sideEffect.}
  439. proc execvp*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>", sideEffect.}
  440. proc execvpe*(a1: cstring, a2: cstringArray, a3: cstringArray): cint {.importc, header: "<unistd.h>", sideEffect.}
  441. proc fchown*(a1: cint, a2: Uid, a3: Gid): cint {.importc, header: "<unistd.h>", sideEffect.}
  442. proc fchdir*(a1: cint): cint {.importc, header: "<unistd.h>", sideEffect.}
  443. proc fdatasync*(a1: cint): cint {.importc, header: "<unistd.h>".}
  444. proc fork*(): Pid {.importc, header: "<unistd.h>", sideEffect.}
  445. proc fpathconf*(a1, a2: cint): int {.importc, header: "<unistd.h>".}
  446. proc fsync*(a1: cint): cint {.importc, header: "<unistd.h>".}
  447. ## synchronize a file's buffer cache to the storage device
  448. proc ftruncate*(a1: cint, a2: Off): cint {.importc, header: "<unistd.h>".}
  449. proc getcwd*(a1: cstring, a2: int): cstring {.importc, header: "<unistd.h>", sideEffect.}
  450. proc getuid*(): Uid {.importc, header: "<unistd.h>", sideEffect.}
  451. ## returns the real user ID of the calling process
  452. proc geteuid*(): Uid {.importc, header: "<unistd.h>", sideEffect.}
  453. ## returns the effective user ID of the calling process
  454. proc getgid*(): Gid {.importc, header: "<unistd.h>", sideEffect.}
  455. ## returns the real group ID of the calling process
  456. proc getegid*(): Gid {.importc, header: "<unistd.h>", sideEffect.}
  457. ## returns the effective group ID of the calling process
  458. proc getgroups*(a1: cint, a2: ptr array[0..255, Gid]): cint {.
  459. importc, header: "<unistd.h>".}
  460. proc gethostid*(): int {.importc, header: "<unistd.h>", sideEffect.}
  461. proc gethostname*(a1: cstring, a2: int): cint {.importc, header: "<unistd.h>", sideEffect.}
  462. proc getlogin*(): cstring {.importc, header: "<unistd.h>", sideEffect.}
  463. proc getlogin_r*(a1: cstring, a2: int): cint {.importc, header: "<unistd.h>", sideEffect.}
  464. proc getopt*(a1: cint, a2: cstringArray, a3: cstring): cint {.
  465. importc, header: "<unistd.h>".}
  466. proc getpgid*(a1: Pid): Pid {.importc, header: "<unistd.h>".}
  467. proc getpgrp*(): Pid {.importc, header: "<unistd.h>".}
  468. proc getpid*(): Pid {.importc, header: "<unistd.h>", sideEffect.}
  469. ## returns the process ID (PID) of the calling process
  470. proc getppid*(): Pid {.importc, header: "<unistd.h>", sideEffect.}
  471. ## returns the process ID of the parent of the calling process
  472. proc getsid*(a1: Pid): Pid {.importc, header: "<unistd.h>", sideEffect.}
  473. ## returns the session ID of the calling process
  474. proc getwd*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
  475. proc isatty*(a1: cint): cint {.importc, header: "<unistd.h>".}
  476. proc lchown*(a1: cstring, a2: Uid, a3: Gid): cint {.importc, header: "<unistd.h>".}
  477. proc link*(a1, a2: cstring): cint {.importc, header: "<unistd.h>".}
  478. proc lockf*(a1, a2: cint, a3: Off): cint {.importc, header: "<unistd.h>".}
  479. proc lseek*(a1: cint, a2: Off, a3: cint): Off {.importc, header: "<unistd.h>".}
  480. proc nice*(a1: cint): cint {.importc, header: "<unistd.h>".}
  481. proc pathconf*(a1: cstring, a2: cint): int {.importc, header: "<unistd.h>".}
  482. proc pause*(): cint {.importc, header: "<unistd.h>".}
  483. proc pclose*(a: File): cint {.importc, header: "<stdio.h>".}
  484. proc pipe*(a: array[0..1, cint]): cint {.importc, header: "<unistd.h>".}
  485. proc popen*(a1, a2: cstring): File {.importc, header: "<stdio.h>".}
  486. proc pread*(a1: cint, a2: pointer, a3: int, a4: Off): int {.
  487. importc, header: "<unistd.h>".}
  488. proc pwrite*(a1: cint, a2: pointer, a3: int, a4: Off): int {.
  489. importc, header: "<unistd.h>".}
  490. proc read*(a1: cint, a2: pointer, a3: int): int {.importc, header: "<unistd.h>".}
  491. proc readlink*(a1, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
  492. proc ioctl*(f: FileHandle, device: uint): int {.importc: "ioctl",
  493. header: "<sys/ioctl.h>", varargs, tags: [WriteIOEffect].}
  494. ## A system call for device-specific input/output operations and other
  495. ## operations which cannot be expressed by regular system calls
  496. proc rmdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
  497. proc setegid*(a1: Gid): cint {.importc, header: "<unistd.h>".}
  498. proc seteuid*(a1: Uid): cint {.importc, header: "<unistd.h>".}
  499. proc setgid*(a1: Gid): cint {.importc, header: "<unistd.h>".}
  500. proc setpgid*(a1, a2: Pid): cint {.importc, header: "<unistd.h>".}
  501. proc setpgrp*(): Pid {.importc, header: "<unistd.h>".}
  502. proc setregid*(a1, a2: Gid): cint {.importc, header: "<unistd.h>".}
  503. proc setreuid*(a1, a2: Uid): cint {.importc, header: "<unistd.h>".}
  504. proc setsid*(): Pid {.importc, header: "<unistd.h>".}
  505. proc setuid*(a1: Uid): cint {.importc, header: "<unistd.h>".}
  506. proc sleep*(a1: cint): cint {.importc, header: "<unistd.h>".}
  507. proc swab*(a1, a2: pointer, a3: int) {.importc, header: "<unistd.h>".}
  508. proc symlink*(a1, a2: cstring): cint {.importc, header: "<unistd.h>".}
  509. proc sync*() {.importc, header: "<unistd.h>".}
  510. proc sysconf*(a1: cint): int {.importc, header: "<unistd.h>".}
  511. proc tcgetpgrp*(a1: cint): Pid {.importc, header: "<unistd.h>".}
  512. proc tcsetpgrp*(a1: cint, a2: Pid): cint {.importc, header: "<unistd.h>".}
  513. proc truncate*(a1: cstring, a2: Off): cint {.importc, header: "<unistd.h>".}
  514. proc ttyname*(a1: cint): cstring {.importc, header: "<unistd.h>".}
  515. proc ttyname_r*(a1: cint, a2: cstring, a3: int): cint {.
  516. importc, header: "<unistd.h>".}
  517. proc ualarm*(a1, a2: Useconds): Useconds {.importc, header: "<unistd.h>".}
  518. proc unlink*(a1: cstring): cint {.importc, header: "<unistd.h>".}
  519. proc usleep*(a1: Useconds): cint {.importc, header: "<unistd.h>".}
  520. proc vfork*(): Pid {.importc, header: "<unistd.h>".}
  521. proc write*(a1: cint, a2: pointer, a3: int): int {.importc, header: "<unistd.h>".}
  522. proc sem_close*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
  523. proc sem_destroy*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
  524. proc sem_getvalue*(a1: ptr Sem, a2: var cint): cint {.
  525. importc, header: "<semaphore.h>".}
  526. proc sem_init*(a1: ptr Sem, a2: cint, a3: cint): cint {.
  527. importc, header: "<semaphore.h>".}
  528. proc sem_open*(a1: cstring, a2: cint): ptr Sem {.
  529. varargs, importc, header: "<semaphore.h>".}
  530. proc sem_post*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
  531. proc sem_timedwait*(a1: ptr Sem, a2: ptr Timespec): cint {.
  532. importc, header: "<semaphore.h>".}
  533. proc sem_trywait*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
  534. proc sem_unlink*(a1: cstring): cint {.importc, header: "<semaphore.h>".}
  535. proc sem_wait*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
  536. proc ftok*(a1: cstring, a2: cint): Key {.importc, header: "<sys/ipc.h>".}
  537. proc statvfs*(a1: cstring, a2: var Statvfs): cint {.
  538. importc, header: "<sys/statvfs.h>".}
  539. proc fstatvfs*(a1: cint, a2: var Statvfs): cint {.
  540. importc, header: "<sys/statvfs.h>".}
  541. proc chmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
  542. when defined(osx) or defined(freebsd):
  543. proc lchmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
  544. proc fchmod*(a1: cint, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
  545. proc fstat*(a1: cint, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
  546. proc lstat*(a1: cstring, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
  547. proc mkdir*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
  548. ## Use `os.createDir() <os.html#createDir,string>`_ and similar.
  549. proc mkfifo*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>".}
  550. proc mknod*(a1: cstring, a2: Mode, a3: Dev): cint {.
  551. importc, header: "<sys/stat.h>".}
  552. proc stat*(a1: cstring, a2: var Stat): cint {.importc, header: "<sys/stat.h>".}
  553. proc umask*(a1: Mode): Mode {.importc, header: "<sys/stat.h>".}
  554. proc S_ISBLK*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  555. ## Test for a block special file.
  556. proc S_ISCHR*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  557. ## Test for a character special file.
  558. proc S_ISDIR*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  559. ## Test for a directory.
  560. proc S_ISFIFO*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  561. ## Test for a pipe or FIFO special file.
  562. proc S_ISREG*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  563. ## Test for a regular file.
  564. proc S_ISLNK*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  565. ## Test for a symbolic link.
  566. proc S_ISSOCK*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
  567. ## Test for a socket.
  568. proc S_TYPEISMQ*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
  569. ## Test for a message queue.
  570. proc S_TYPEISSEM*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
  571. ## Test for a semaphore.
  572. proc S_TYPEISSHM*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
  573. ## Test for a shared memory object.
  574. proc S_TYPEISTMO*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
  575. ## Test macro for a typed memory object.
  576. proc mlock*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".}
  577. proc mlockall*(a1: cint): cint {.importc, header: "<sys/mman.h>".}
  578. proc mmap*(a1: pointer, a2: int, a3, a4, a5: cint, a6: Off): pointer {.
  579. importc, header: "<sys/mman.h>".}
  580. proc mprotect*(a1: pointer, a2: int, a3: cint): cint {.
  581. importc, header: "<sys/mman.h>".}
  582. proc msync*(a1: pointer, a2: int, a3: cint): cint {.importc, header: "<sys/mman.h>".}
  583. proc munlock*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".}
  584. proc munlockall*(): cint {.importc, header: "<sys/mman.h>".}
  585. proc munmap*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".}
  586. proc posix_madvise*(a1: pointer, a2: int, a3: cint): cint {.
  587. importc, header: "<sys/mman.h>".}
  588. proc posix_mem_offset*(a1: pointer, a2: int, a3: var Off,
  589. a4: var int, a5: var cint): cint {.importc, header: "<sys/mman.h>".}
  590. when not (defined(linux) and defined(amd64)) and not defined(nintendoswitch) and
  591. not defined(haiku):
  592. proc posix_typed_mem_get_info*(a1: cint,
  593. a2: var Posix_typed_mem_info): cint {.importc, header: "<sys/mman.h>".}
  594. proc posix_typed_mem_open*(a1: cstring, a2, a3: cint): cint {.
  595. importc, header: "<sys/mman.h>".}
  596. proc shm_open*(a1: cstring, a2: cint, a3: Mode): cint {.
  597. importc, header: "<sys/mman.h>".}
  598. proc shm_unlink*(a1: cstring): cint {.importc, header: "<sys/mman.h>".}
  599. proc asctime*(a1: var Tm): cstring{.importc, header: "<time.h>".}
  600. proc asctime_r*(a1: var Tm, a2: cstring): cstring {.importc, header: "<time.h>".}
  601. proc clock*(): Clock {.importc, header: "<time.h>", sideEffect.}
  602. proc clock_getcpuclockid*(a1: Pid, a2: var ClockId): cint {.
  603. importc, header: "<time.h>", sideEffect.}
  604. proc clock_getres*(a1: ClockId, a2: var Timespec): cint {.
  605. importc, header: "<time.h>", sideEffect.}
  606. proc clock_gettime*(a1: ClockId, a2: var Timespec): cint {.
  607. importc, header: "<time.h>", sideEffect.}
  608. proc clock_nanosleep*(a1: ClockId, a2: cint, a3: var Timespec,
  609. a4: var Timespec): cint {.importc, header: "<time.h>", sideEffect.}
  610. proc clock_settime*(a1: ClockId, a2: var Timespec): cint {.
  611. importc, header: "<time.h>", sideEffect.}
  612. proc `==`*(a, b: Time): bool {.borrow.}
  613. proc `-`*(a, b: Time): Time {.borrow.}
  614. proc ctime*(a1: var Time): cstring {.importc, header: "<time.h>".}
  615. proc ctime_r*(a1: var Time, a2: cstring): cstring {.importc, header: "<time.h>".}
  616. proc difftime*(a1, a2: Time): cdouble {.importc, header: "<time.h>".}
  617. proc getdate*(a1: cstring): ptr Tm {.importc, header: "<time.h>".}
  618. proc gmtime*(a1: var Time): ptr Tm {.importc, header: "<time.h>".}
  619. proc gmtime_r*(a1: var Time, a2: var Tm): ptr Tm {.importc, header: "<time.h>".}
  620. proc localtime*(a1: var Time): ptr Tm {.importc, header: "<time.h>".}
  621. proc localtime_r*(a1: var Time, a2: var Tm): ptr Tm {.importc, header: "<time.h>".}
  622. proc mktime*(a1: var Tm): Time {.importc, header: "<time.h>".}
  623. proc timegm*(a1: var Tm): Time {.importc, header: "<time.h>".}
  624. proc nanosleep*(a1, a2: var Timespec): cint {.importc, header: "<time.h>", sideEffect.}
  625. proc strftime*(a1: cstring, a2: int, a3: cstring,
  626. a4: var Tm): int {.importc, header: "<time.h>".}
  627. proc strptime*(a1, a2: cstring, a3: var Tm): cstring {.importc, header: "<time.h>".}
  628. proc time*(a1: var Time): Time {.importc, header: "<time.h>", sideEffect.}
  629. proc timer_create*(a1: ClockId, a2: var SigEvent,
  630. a3: var Timer): cint {.importc, header: "<time.h>".}
  631. proc timer_delete*(a1: Timer): cint {.importc, header: "<time.h>".}
  632. proc timer_gettime*(a1: Timer, a2: var Itimerspec): cint {.
  633. importc, header: "<time.h>".}
  634. proc timer_getoverrun*(a1: Timer): cint {.importc, header: "<time.h>".}
  635. proc timer_settime*(a1: Timer, a2: cint, a3: var Itimerspec,
  636. a4: var Itimerspec): cint {.importc, header: "<time.h>".}
  637. proc tzset*() {.importc, header: "<time.h>".}
  638. proc wait*(a1: ptr cint): Pid {.importc, discardable, header: "<sys/wait.h>", sideEffect.}
  639. proc waitid*(a1: cint, a2: Id, a3: var SigInfo, a4: cint): cint {.
  640. importc, header: "<sys/wait.h>", sideEffect.}
  641. proc waitpid*(a1: Pid, a2: var cint, a3: cint): Pid {.
  642. importc, header: "<sys/wait.h>", sideEffect.}
  643. type Rusage* {.importc: "struct rusage", header: "<sys/resource.h>",
  644. bycopy.} = object
  645. ru_utime*, ru_stime*: Timeval # User and system time
  646. ru_maxrss*, ru_ixrss*, ru_idrss*, ru_isrss*, # memory sizes
  647. ru_minflt*, ru_majflt*, ru_nswap*, # paging activity
  648. ru_inblock*, ru_oublock*, ru_msgsnd*, ru_msgrcv*, # IO activity
  649. ru_nsignals*, ru_nvcsw*, ru_nivcsw*: clong # switching activity
  650. proc wait4*(pid: Pid, status: ptr cint, options: cint, rusage: ptr Rusage): Pid
  651. {.importc, header: "<sys/wait.h>", sideEffect.}
  652. const
  653. RUSAGE_SELF* = cint(0)
  654. RUSAGE_CHILDREN* = cint(-1)
  655. RUSAGE_THREAD* = cint(1) # This one is less std; Linux, BSD agree though.
  656. # This can only fail if `who` is invalid or `rusage` ptr is invalid.
  657. proc getrusage*(who: cint, rusage: ptr Rusage): cint
  658. {.importc, header: "<sys/resource.h>", discardable.}
  659. proc bsd_signal*(a1: cint, a2: proc (x: pointer) {.noconv.}) {.
  660. importc, header: "<signal.h>".}
  661. proc kill*(a1: Pid, a2: cint): cint {.importc, header: "<signal.h>", sideEffect.}
  662. proc killpg*(a1: Pid, a2: cint): cint {.importc, header: "<signal.h>", sideEffect.}
  663. proc pthread_kill*(a1: Pthread, a2: cint): cint {.importc, header: "<signal.h>".}
  664. proc pthread_sigmask*(a1: cint, a2, a3: var Sigset): cint {.
  665. importc, header: "<signal.h>".}
  666. proc `raise`*(a1: cint): cint {.importc, header: "<signal.h>".}
  667. proc sigaction*(a1: cint, a2, a3: var Sigaction): cint {.
  668. importc, header: "<signal.h>".}
  669. proc sigaction*(a1: cint, a2: var Sigaction; a3: ptr Sigaction = nil): cint {.
  670. importc, header: "<signal.h>".}
  671. proc sigaddset*(a1: var Sigset, a2: cint): cint {.importc, header: "<signal.h>".}
  672. proc sigaltstack*(a1, a2: var Stack): cint {.importc, header: "<signal.h>".}
  673. proc sigdelset*(a1: var Sigset, a2: cint): cint {.importc, header: "<signal.h>".}
  674. proc sigemptyset*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
  675. proc sigfillset*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
  676. proc sighold*(a1: cint): cint {.importc, header: "<signal.h>".}
  677. proc sigignore*(a1: cint): cint {.importc, header: "<signal.h>".}
  678. proc siginterrupt*(a1, a2: cint): cint {.importc, header: "<signal.h>".}
  679. proc sigismember*(a1: var Sigset, a2: cint): cint {.importc, header: "<signal.h>".}
  680. proc signal*(a1: cint, a2: Sighandler) {.
  681. importc, header: "<signal.h>".}
  682. proc sigpause*(a1: cint): cint {.importc, header: "<signal.h>".}
  683. proc sigpending*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
  684. proc sigprocmask*(a1: cint, a2, a3: var Sigset): cint {.
  685. importc, header: "<signal.h>".}
  686. proc sigqueue*(a1: Pid, a2: cint, a3: SigVal): cint {.
  687. importc, header: "<signal.h>".}
  688. proc sigrelse*(a1: cint): cint {.importc, header: "<signal.h>".}
  689. proc sigset*(a1: int, a2: proc (x: cint) {.noconv.}) {.
  690. importc, header: "<signal.h>".}
  691. proc sigsuspend*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
  692. when defined(android):
  693. proc syscall(arg: clong): clong {.varargs, importc: "syscall", header: "<unistd.h>".}
  694. var NR_rt_sigtimedwait {.importc: "__NR_rt_sigtimedwait", header: "<sys/syscall.h>".}: clong
  695. var NSIGMAX {.importc: "NSIG", header: "<signal.h>".}: clong
  696. proc sigtimedwait*(a1: var Sigset, a2: var SigInfo, a3: var Timespec): cint =
  697. result = cint(syscall(NR_rt_sigtimedwait, addr(a1), addr(a2), addr(a3), NSIGMAX div 8))
  698. else:
  699. proc sigtimedwait*(a1: var Sigset, a2: var SigInfo,
  700. a3: var Timespec): cint {.importc, header: "<signal.h>".}
  701. when defined(sunos) or defined(solaris):
  702. # The following compile time flag is needed on Illumos/Solaris to use the POSIX
  703. # `sigwait` implementation. See the documentation here:
  704. # https://docs.oracle.com/cd/E19455-01/806-5257/6je9h033k/index.html
  705. # https://www.illumos.org/man/2/sigwait
  706. {.passc: "-D_POSIX_PTHREAD_SEMANTICS".}
  707. proc sigwait*(a1: var Sigset, a2: var cint): cint {.
  708. importc, header: "<signal.h>".}
  709. proc sigwaitinfo*(a1: var Sigset, a2: var SigInfo): cint {.
  710. importc, header: "<signal.h>".}
  711. when not defined(nintendoswitch):
  712. proc catclose*(a1: Nl_catd): cint {.importc, header: "<nl_types.h>".}
  713. proc catgets*(a1: Nl_catd, a2, a3: cint, a4: cstring): cstring {.
  714. importc, header: "<nl_types.h>".}
  715. proc catopen*(a1: cstring, a2: cint): Nl_catd {.
  716. importc, header: "<nl_types.h>".}
  717. proc sched_get_priority_max*(a1: cint): cint {.importc, header: "<sched.h>".}
  718. proc sched_get_priority_min*(a1: cint): cint {.importc, header: "<sched.h>".}
  719. proc sched_getparam*(a1: Pid, a2: var Sched_param): cint {.
  720. importc, header: "<sched.h>".}
  721. proc sched_getscheduler*(a1: Pid): cint {.importc, header: "<sched.h>".}
  722. proc sched_rr_get_interval*(a1: Pid, a2: var Timespec): cint {.
  723. importc, header: "<sched.h>".}
  724. proc sched_setparam*(a1: Pid, a2: var Sched_param): cint {.
  725. importc, header: "<sched.h>".}
  726. proc sched_setscheduler*(a1: Pid, a2: cint, a3: var Sched_param): cint {.
  727. importc, header: "<sched.h>".}
  728. proc sched_yield*(): cint {.importc, header: "<sched.h>".}
  729. proc hstrerror*(herrnum: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>".}
  730. proc FD_CLR*(a1: cint, a2: var TFdSet) {.importc, header: "<sys/select.h>".}
  731. proc FD_ISSET*(a1: cint | SocketHandle, a2: var TFdSet): cint {.
  732. importc, header: "<sys/select.h>".}
  733. proc FD_SET*(a1: cint | SocketHandle, a2: var TFdSet) {.
  734. importc: "FD_SET", header: "<sys/select.h>".}
  735. proc FD_ZERO*(a1: var TFdSet) {.importc, header: "<sys/select.h>".}
  736. proc pselect*(a1: cint, a2, a3, a4: ptr TFdSet, a5: ptr Timespec,
  737. a6: var Sigset): cint {.importc, header: "<sys/select.h>".}
  738. proc select*(a1: cint | SocketHandle, a2, a3, a4: ptr TFdSet, a5: ptr Timeval): cint {.
  739. importc, header: "<sys/select.h>".}
  740. when hasSpawnH:
  741. proc posix_spawn*(a1: var Pid, a2: cstring,
  742. a3: var Tposix_spawn_file_actions,
  743. a4: var Tposix_spawnattr,
  744. a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
  745. proc posix_spawn_file_actions_addclose*(a1: var Tposix_spawn_file_actions,
  746. a2: cint): cint {.importc, header: "<spawn.h>".}
  747. proc posix_spawn_file_actions_adddup2*(a1: var Tposix_spawn_file_actions,
  748. a2, a3: cint): cint {.importc, header: "<spawn.h>".}
  749. proc posix_spawn_file_actions_addopen*(a1: var Tposix_spawn_file_actions,
  750. a2: cint, a3: cstring, a4: cint, a5: Mode): cint {.
  751. importc, header: "<spawn.h>".}
  752. proc posix_spawn_file_actions_destroy*(
  753. a1: var Tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
  754. proc posix_spawn_file_actions_init*(
  755. a1: var Tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
  756. proc posix_spawnattr_destroy*(a1: var Tposix_spawnattr): cint {.
  757. importc, header: "<spawn.h>".}
  758. proc posix_spawnattr_getsigdefault*(a1: var Tposix_spawnattr,
  759. a2: var Sigset): cint {.importc, header: "<spawn.h>".}
  760. proc posix_spawnattr_getflags*(a1: var Tposix_spawnattr,
  761. a2: var cshort): cint {.importc, header: "<spawn.h>".}
  762. proc posix_spawnattr_getpgroup*(a1: var Tposix_spawnattr,
  763. a2: var Pid): cint {.importc, header: "<spawn.h>".}
  764. proc posix_spawnattr_getschedparam*(a1: var Tposix_spawnattr,
  765. a2: var Sched_param): cint {.importc, header: "<spawn.h>".}
  766. proc posix_spawnattr_getschedpolicy*(a1: var Tposix_spawnattr,
  767. a2: var cint): cint {.importc, header: "<spawn.h>".}
  768. proc posix_spawnattr_getsigmask*(a1: var Tposix_spawnattr,
  769. a2: var Sigset): cint {.importc, header: "<spawn.h>".}
  770. proc posix_spawnattr_init*(a1: var Tposix_spawnattr): cint {.
  771. importc, header: "<spawn.h>".}
  772. proc posix_spawnattr_setsigdefault*(a1: var Tposix_spawnattr,
  773. a2: var Sigset): cint {.importc, header: "<spawn.h>".}
  774. proc posix_spawnattr_setflags*(a1: var Tposix_spawnattr, a2: cint): cint {.
  775. importc, header: "<spawn.h>".}
  776. proc posix_spawnattr_setpgroup*(a1: var Tposix_spawnattr, a2: Pid): cint {.
  777. importc, header: "<spawn.h>".}
  778. proc posix_spawnattr_setschedparam*(a1: var Tposix_spawnattr,
  779. a2: var Sched_param): cint {.importc, header: "<spawn.h>".}
  780. proc posix_spawnattr_setschedpolicy*(a1: var Tposix_spawnattr,
  781. a2: cint): cint {.
  782. importc, header: "<spawn.h>".}
  783. proc posix_spawnattr_setsigmask*(a1: var Tposix_spawnattr,
  784. a2: var Sigset): cint {.importc, header: "<spawn.h>".}
  785. proc posix_spawnp*(a1: var Pid, a2: cstring,
  786. a3: var Tposix_spawn_file_actions,
  787. a4: var Tposix_spawnattr,
  788. a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
  789. when not defined(nintendoswitch):
  790. proc getcontext*(a1: var Ucontext): cint {.importc, header: "<ucontext.h>".}
  791. proc makecontext*(a1: var Ucontext, a4: proc (){.noconv.}, a3: cint) {.
  792. varargs, importc, header: "<ucontext.h>".}
  793. proc setcontext*(a1: var Ucontext): cint {.importc, header: "<ucontext.h>".}
  794. proc swapcontext*(a1, a2: var Ucontext): cint {.importc, header: "<ucontext.h>".}
  795. proc readv*(a1: cint, a2: ptr IOVec, a3: cint): int {.
  796. importc, header: "<sys/uio.h>".}
  797. proc writev*(a1: cint, a2: ptr IOVec, a3: cint): int {.
  798. importc, header: "<sys/uio.h>".}
  799. proc CMSG_DATA*(cmsg: ptr Tcmsghdr): cstring {.
  800. importc, header: "<sys/socket.h>".}
  801. proc CMSG_NXTHDR*(mhdr: ptr Tmsghdr, cmsg: ptr Tcmsghdr): ptr Tcmsghdr {.
  802. importc, header: "<sys/socket.h>".}
  803. proc CMSG_FIRSTHDR*(mhdr: ptr Tmsghdr): ptr Tcmsghdr {.
  804. importc, header: "<sys/socket.h>".}
  805. proc CMSG_SPACE*(len: csize_t): csize_t {.
  806. importc, header: "<sys/socket.h>".}
  807. proc CMSG_LEN*(len: csize_t): csize_t {.
  808. importc, header: "<sys/socket.h>".}
  809. const
  810. INVALID_SOCKET* = SocketHandle(-1)
  811. proc `==`*(x, y: SocketHandle): bool {.borrow.}
  812. proc accept*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): SocketHandle {.
  813. importc, header: "<sys/socket.h>", sideEffect.}
  814. when defined(linux) or defined(bsd):
  815. proc accept4*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen,
  816. flags: cint): SocketHandle {.importc, header: "<sys/socket.h>".}
  817. proc bindSocket*(a1: SocketHandle, a2: ptr SockAddr, a3: SockLen): cint {.
  818. importc: "bind", header: "<sys/socket.h>".}
  819. ## is Posix's `bind`, because `bind` is a reserved word
  820. proc connect*(a1: SocketHandle, a2: ptr SockAddr, a3: SockLen): cint {.
  821. importc, header: "<sys/socket.h>".}
  822. proc getpeername*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): cint {.
  823. importc, header: "<sys/socket.h>".}
  824. proc getsockname*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): cint {.
  825. importc, header: "<sys/socket.h>".}
  826. proc getsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: ptr SockLen): cint {.
  827. importc, header: "<sys/socket.h>".}
  828. proc listen*(a1: SocketHandle, a2: cint): cint {.
  829. importc, header: "<sys/socket.h>", sideEffect.}
  830. proc recv*(a1: SocketHandle, a2: pointer, a3: int, a4: cint): int {.
  831. importc, header: "<sys/socket.h>", sideEffect.}
  832. proc recvfrom*(a1: SocketHandle, a2: pointer, a3: int, a4: cint,
  833. a5: ptr SockAddr, a6: ptr SockLen): int {.
  834. importc, header: "<sys/socket.h>", sideEffect.}
  835. proc recvmsg*(a1: SocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
  836. importc, header: "<sys/socket.h>", sideEffect.}
  837. proc send*(a1: SocketHandle, a2: pointer, a3: int, a4: cint): int {.
  838. importc, header: "<sys/socket.h>", sideEffect.}
  839. proc sendmsg*(a1: SocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
  840. importc, header: "<sys/socket.h>", sideEffect.}
  841. proc sendto*(a1: SocketHandle, a2: pointer, a3: int, a4: cint, a5: ptr SockAddr,
  842. a6: SockLen): int {.
  843. importc, header: "<sys/socket.h>", sideEffect.}
  844. proc setsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: SockLen): cint {.
  845. importc, header: "<sys/socket.h>".}
  846. proc shutdown*(a1: SocketHandle, a2: cint): cint {.
  847. importc, header: "<sys/socket.h>".}
  848. proc socket*(a1, a2, a3: cint): SocketHandle {.
  849. importc, header: "<sys/socket.h>".}
  850. proc sockatmark*(a1: cint): cint {.
  851. importc, header: "<sys/socket.h>".}
  852. proc socketpair*(a1, a2, a3: cint, a4: var array[0..1, cint]): cint {.
  853. importc, header: "<sys/socket.h>".}
  854. proc if_nametoindex*(a1: cstring): cint {.importc, header: "<net/if.h>".}
  855. proc if_indextoname*(a1: cint, a2: cstring): cstring {.
  856. importc, header: "<net/if.h>".}
  857. proc if_nameindex*(): ptr Tif_nameindex {.importc, header: "<net/if.h>".}
  858. proc if_freenameindex*(a1: ptr Tif_nameindex) {.importc, header: "<net/if.h>".}
  859. proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr In6Addr): cint {.
  860. importc, header: "<netinet/in.h>".}
  861. ## Unspecified address.
  862. proc IN6_IS_ADDR_LOOPBACK* (a1: ptr In6Addr): cint {.
  863. importc, header: "<netinet/in.h>".}
  864. ## Loopback address.
  865. proc IN6_IS_ADDR_MULTICAST* (a1: ptr In6Addr): cint {.
  866. importc, header: "<netinet/in.h>".}
  867. ## Multicast address.
  868. proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr In6Addr): cint {.
  869. importc, header: "<netinet/in.h>".}
  870. ## Unicast link-local address.
  871. proc IN6_IS_ADDR_SITELOCAL* (a1: ptr In6Addr): cint {.
  872. importc, header: "<netinet/in.h>".}
  873. ## Unicast site-local address.
  874. when defined(lwip):
  875. proc IN6_IS_ADDR_V4MAPPED*(ipv6_address: ptr In6Addr): cint =
  876. var bits32: ptr array[4, uint32] = cast[ptr array[4, uint32]](ipv6_address)
  877. return (bits32[1] == 0'u32 and bits32[2] == htonl(0x0000FFFF)).cint
  878. else:
  879. proc IN6_IS_ADDR_V4MAPPED* (a1: ptr In6Addr): cint {.
  880. importc, header: "<netinet/in.h>".}
  881. ## IPv4 mapped address.
  882. proc IN6_IS_ADDR_V4COMPAT* (a1: ptr In6Addr): cint {.
  883. importc, header: "<netinet/in.h>".}
  884. ## IPv4-compatible address.
  885. proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr In6Addr): cint {.
  886. importc, header: "<netinet/in.h>".}
  887. ## Multicast node-local address.
  888. proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr In6Addr): cint {.
  889. importc, header: "<netinet/in.h>".}
  890. ## Multicast link-local address.
  891. proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr In6Addr): cint {.
  892. importc, header: "<netinet/in.h>".}
  893. ## Multicast site-local address.
  894. proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr In6Addr): cint {.
  895. importc, header: "<netinet/in.h>".}
  896. ## Multicast organization-local address.
  897. proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr In6Addr): cint {.
  898. importc, header: "<netinet/in.h>".}
  899. ## Multicast global address.
  900. proc endhostent*() {.importc, header: "<netdb.h>".}
  901. proc endnetent*() {.importc, header: "<netdb.h>".}
  902. proc endprotoent*() {.importc, header: "<netdb.h>".}
  903. proc endservent*() {.importc, header: "<netdb.h>".}
  904. proc freeAddrInfo*(a1: ptr AddrInfo) {.importc: "freeaddrinfo", header: "<netdb.h>".}
  905. proc gai_strerror*(a1: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>".}
  906. proc getaddrinfo*(a1, a2: cstring, a3: ptr AddrInfo,
  907. a4: var ptr AddrInfo): cint {.importc, header: "<netdb.h>".}
  908. when not defined(android4):
  909. proc gethostbyaddr*(a1: pointer, a2: SockLen, a3: cint): ptr Hostent {.
  910. importc, header: "<netdb.h>".}
  911. else:
  912. proc gethostbyaddr*(a1: cstring, a2: cint, a3: cint): ptr Hostent {.
  913. importc, header: "<netdb.h>".}
  914. proc gethostbyname*(a1: cstring): ptr Hostent {.importc, header: "<netdb.h>".}
  915. proc gethostent*(): ptr Hostent {.importc, header: "<netdb.h>".}
  916. proc getnameinfo*(a1: ptr SockAddr, a2: SockLen,
  917. a3: cstring, a4: SockLen, a5: cstring,
  918. a6: SockLen, a7: cint): cint {.importc, header: "<netdb.h>".}
  919. proc getnetbyaddr*(a1: int32, a2: cint): ptr Tnetent {.importc, header: "<netdb.h>".}
  920. proc getnetbyname*(a1: cstring): ptr Tnetent {.importc, header: "<netdb.h>".}
  921. proc getnetent*(): ptr Tnetent {.importc, header: "<netdb.h>".}
  922. proc getprotobyname*(a1: cstring): ptr Protoent {.importc, header: "<netdb.h>".}
  923. proc getprotobynumber*(a1: cint): ptr Protoent {.importc, header: "<netdb.h>".}
  924. proc getprotoent*(): ptr Protoent {.importc, header: "<netdb.h>".}
  925. proc getservbyname*(a1, a2: cstring): ptr Servent {.importc, header: "<netdb.h>".}
  926. proc getservbyport*(a1: cint, a2: cstring): ptr Servent {.
  927. importc, header: "<netdb.h>".}
  928. proc getservent*(): ptr Servent {.importc, header: "<netdb.h>".}
  929. proc sethostent*(a1: cint) {.importc, header: "<netdb.h>".}
  930. proc setnetent*(a1: cint) {.importc, header: "<netdb.h>".}
  931. proc setprotoent*(a1: cint) {.importc, header: "<netdb.h>".}
  932. proc setservent*(a1: cint) {.importc, header: "<netdb.h>".}
  933. when not defined(lwip):
  934. proc poll*(a1: ptr TPollfd, a2: Tnfds, a3: int): cint {.
  935. importc, header: "<poll.h>", sideEffect.}
  936. proc realpath*(name, resolved: cstring): cstring {.
  937. importc: "realpath", header: "<stdlib.h>".}
  938. proc mkstemp*(tmpl: cstring): cint {.importc, header: "<stdlib.h>", sideEffect.}
  939. ## Creates a unique temporary file.
  940. ##
  941. ## .. warning:: The `tmpl` argument is written to by `mkstemp` and thus
  942. ## can't be a string literal. If in doubt make a copy of the cstring before
  943. ## passing it in.
  944. proc mkstemps*(tmpl: cstring, suffixlen: int): cint {.importc, header: "<stdlib.h>", sideEffect.}
  945. ## Creates a unique temporary file.
  946. ##
  947. ## .. warning:: The `tmpl` argument is written to by `mkstemps` and thus
  948. ## can't be a string literal. If in doubt make a copy of the cstring before
  949. ## passing it in.
  950. proc mkdtemp*(tmpl: cstring): pointer {.importc, header: "<stdlib.h>", sideEffect.}
  951. when defined(linux) or defined(bsd) or defined(osx):
  952. proc mkostemp*(tmpl: cstring, oflags: cint): cint {.importc, header: "<stdlib.h>", sideEffect.}
  953. proc mkostemps*(tmpl: cstring, suffixlen: cint, oflags: cint): cint {.importc, header: "<stdlib.h>", sideEffect.}
  954. proc posix_memalign*(memptr: pointer, alignment: csize_t, size: csize_t): cint {.importc, header: "<stdlib.h>".}
  955. proc utimes*(path: cstring, times: ptr array[2, Timeval]): int {.
  956. importc: "utimes", header: "<sys/time.h>", sideEffect.}
  957. ## Sets file access and modification times.
  958. ##
  959. ## Pass the filename and an array of times to set the access and modification
  960. ## times respectively. If you pass nil as the array both attributes will be
  961. ## set to the current time.
  962. ##
  963. ## Returns zero on success.
  964. ##
  965. ## For more information read http://www.unix.com/man-page/posix/3/utimes/.
  966. proc handle_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.importc: "signal", header: "<signal.h>".}
  967. template onSignal*(signals: varargs[cint], body: untyped) =
  968. ## Setup code to be executed when Unix signals are received. The
  969. ## currently handled signal is injected as `sig` into the calling
  970. ## scope.
  971. ##
  972. ## Example:
  973. ## ```Nim
  974. ## from std/posix import SIGINT, SIGTERM, onSignal
  975. ## onSignal(SIGINT, SIGTERM):
  976. ## echo "bye from signal ", sig
  977. ## ```
  978. for s in signals:
  979. handle_signal(s,
  980. proc (signal: cint) {.noconv.} =
  981. let sig {.inject.} = signal
  982. body
  983. )
  984. type
  985. RLimit* {.importc: "struct rlimit",
  986. header: "<sys/resource.h>", pure, final.} = object
  987. rlim_cur*: int
  988. rlim_max*: int
  989. ## The getrlimit() and setrlimit() system calls get and set resource limits respectively.
  990. ## Each resource has an associated soft and hard limit, as defined by the RLimit structure
  991. proc setrlimit*(resource: cint, rlp: var RLimit): cint
  992. {.importc: "setrlimit",header: "<sys/resource.h>".}
  993. ## The setrlimit() system calls sets resource limits.
  994. proc getrlimit*(resource: cint, rlp: var RLimit): cint
  995. {.importc: "getrlimit",header: "<sys/resource.h>".}
  996. ## The getrlimit() system call gets resource limits.
  997. when defined(nimHasStyleChecks):
  998. {.pop.} # {.push styleChecks: off.}