posix.nim 52 KB

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