posix.nim 55 KB

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