summary refs log tree commit diff stats
path: root/lib/posix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/posix')
-rw-r--r--lib/posix/epoll.nim99
-rw-r--r--lib/posix/inotify.nim111
-rw-r--r--lib/posix/kqueue.nim161
-rw-r--r--lib/posix/linux.nim39
-rw-r--r--[-rwxr-xr-x]lib/posix/posix.nim3001
-rw-r--r--lib/posix/posix_freertos_consts.nim506
-rw-r--r--lib/posix/posix_haiku.nim603
-rw-r--r--lib/posix/posix_linux_amd64.nim587
-rw-r--r--lib/posix/posix_linux_amd64_consts.nim730
-rw-r--r--lib/posix/posix_macos_amd64.nim620
-rw-r--r--lib/posix/posix_nintendoswitch.nim506
-rw-r--r--lib/posix/posix_nintendoswitch_consts.nim587
-rw-r--r--lib/posix/posix_openbsd_amd64.nim565
-rw-r--r--lib/posix/posix_other.nim706
-rw-r--r--lib/posix/posix_other_consts.nim757
-rw-r--r--lib/posix/posix_utils.nim133
-rw-r--r--lib/posix/termios.nim256
17 files changed, 7788 insertions, 2179 deletions
diff --git a/lib/posix/epoll.nim b/lib/posix/epoll.nim
new file mode 100644
index 000000000..007488354
--- /dev/null
+++ b/lib/posix/epoll.nim
@@ -0,0 +1,99 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2013 Dominik Picheta
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+from std/posix import SocketHandle
+
+const
+  EPOLLIN* = 0x00000001
+  EPOLLPRI* = 0x00000002
+  EPOLLOUT* = 0x00000004
+  EPOLLERR* = 0x00000008
+  EPOLLHUP* = 0x00000010
+  EPOLLRDNORM* = 0x00000040
+  EPOLLRDBAND* = 0x00000080
+  EPOLLWRNORM* = 0x00000100
+  EPOLLWRBAND* = 0x00000200
+  EPOLLMSG* = 0x00000400
+  EPOLLRDHUP* = 0x00002000
+  EPOLLEXCLUSIVE* = 1 shl 28
+  EPOLLWAKEUP* = 1 shl 29
+  EPOLLONESHOT* = 1 shl 30
+  EPOLLET* = 1 shl 31
+
+# Valid opcodes ( "op" parameter ) to issue to epoll_ctl().
+
+const
+  EPOLL_CTL_ADD* = 1          # Add a file descriptor to the interface.
+  EPOLL_CTL_DEL* = 2          # Remove a file descriptor from the interface.
+  EPOLL_CTL_MOD* = 3          # Change file descriptor epoll_event structure.
+
+# https://github.com/torvalds/linux/blob/ff6992735ade75aae3e35d16b17da1008d753d28/include/uapi/linux/eventpoll.h#L77
+when defined(linux) and defined(amd64):
+  {.pragma: epollPacked, packed.}
+else:
+  {.pragma: epollPacked.}
+
+type
+  EpollData* {.importc: "epoll_data_t",
+      header: "<sys/epoll.h>", pure, final, union.} = object
+    `ptr`* {.importc: "ptr".}: pointer
+    fd* {.importc: "fd".}: cint
+    u32* {.importc: "u32".}: uint32
+    u64* {.importc: "u64".}: uint64
+
+  EpollEvent* {.importc: "struct epoll_event", header: "<sys/epoll.h>", pure, final, epollPacked.} = object
+    events*: uint32 # Epoll events
+    data*: EpollData # User data variable
+
+proc epoll_create*(size: cint): cint {.importc: "epoll_create",
+    header: "<sys/epoll.h>".}
+  ## Creates an epoll instance.  Returns an fd for the new instance.
+  ##
+  ## The "size" parameter is a hint specifying the number of file
+  ## descriptors to be associated with the new instance.  The fd
+  ## returned by epoll_create() should be closed with close().
+
+proc epoll_create1*(flags: cint): cint {.importc: "epoll_create1",
+    header: "<sys/epoll.h>".}
+  ## Same as epoll_create but with an FLAGS parameter.  The unused SIZE
+  ## parameter has been dropped.
+
+proc epoll_ctl*(epfd: cint; op: cint; fd: cint | SocketHandle; event: ptr EpollEvent): cint {.
+    importc: "epoll_ctl", header: "<sys/epoll.h>".}
+  ## Manipulate an epoll instance "epfd". Returns `0` in case of success,
+  ## `-1` in case of error (the "errno" variable will contain the specific error code).
+  ##
+  ## The "op" parameter is one of the `EPOLL_CTL_*`
+  ## constants defined above. The "fd" parameter is the target of the
+  ## operation. The "event" parameter describes which events the caller
+  ## is interested in and any associated user data.
+
+proc epoll_wait*(epfd: cint; events: ptr EpollEvent; maxevents: cint;
+                 timeout: cint): cint {.importc: "epoll_wait",
+    header: "<sys/epoll.h>".}
+  ## Wait for events on an epoll instance "epfd". Returns the number of
+  ## triggered events returned in "events" buffer. Or -1 in case of
+  ## error with the "errno" variable set to the specific error code. The
+  ## "events" parameter is a buffer that will contain triggered
+  ## events. The "maxevents" is the maximum number of events to be
+  ## returned ( usually size of "events" ). The "timeout" parameter
+  ## specifies the maximum wait time in milliseconds (-1 == infinite).
+  ##
+  ## This function is a cancellation point and therefore not marked with
+  ## __THROW.
+
+
+#proc epoll_pwait*(epfd: cint; events: ptr EpollEvent; maxevents: cint;
+#                  timeout: cint; ss: ptr sigset_t): cint {.
+#    importc: "epoll_pwait", header: "<sys/epoll.h>".}
+# Same as epoll_wait, but the thread's signal mask is temporarily
+# and atomically replaced with the one provided as parameter.
+#
+# This function is a cancellation point and therefore not marked with
+# __THROW.
diff --git a/lib/posix/inotify.nim b/lib/posix/inotify.nim
new file mode 100644
index 000000000..575accc18
--- /dev/null
+++ b/lib/posix/inotify.nim
@@ -0,0 +1,111 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2012 Dominik Picheta
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+when defined(nimPreviewSlimSystem):
+  import std/syncio
+
+# Get the platform-dependent flags.
+# Structure describing an inotify event.
+type
+  InotifyEvent* {.pure, final, importc: "struct inotify_event",
+                  header: "<sys/inotify.h>",
+                  completeStruct.} = object            ## An Inotify event.
+    wd* {.importc: "wd".}: FileHandle                  ## Watch descriptor.
+    mask* {.importc: "mask".}: uint32                  ## Watch mask.
+    cookie* {.importc: "cookie".}: uint32              ## Cookie to synchronize two events.
+    len* {.importc: "len".}: uint32                    ## Length (including NULs) of name.
+    name* {.importc: "name".}: UncheckedArray[char]    ## Name.
+
+# Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH.
+const
+  IN_ACCESS* = 0x00000001                          ## File was accessed.
+  IN_MODIFY* = 0x00000002                          ## File was modified.
+  IN_ATTRIB* = 0x00000004                          ## Metadata changed.
+  IN_CLOSE_WRITE* = 0x00000008                     ## Writtable file was closed.
+  IN_CLOSE_NOWRITE* = 0x00000010                   ## Unwrittable file closed.
+  IN_CLOSE* = (IN_CLOSE_WRITE or IN_CLOSE_NOWRITE) ## Close.
+  IN_OPEN* = 0x00000020                            ## File was opened.
+  IN_MOVED_FROM* = 0x00000040                      ## File was moved from X.
+  IN_MOVED_TO* = 0x00000080                        ## File was moved to Y.
+  IN_MOVE* = (IN_MOVED_FROM or IN_MOVED_TO)        ## Moves.
+  IN_CREATE* = 0x00000100                          ## Subfile was created.
+  IN_DELETE* = 0x00000200                          ## Subfile was deleted.
+  IN_DELETE_SELF* = 0x00000400                     ## Self was deleted.
+  IN_MOVE_SELF* = 0x00000800                       ## Self was moved.
+
+# Events sent by the kernel.
+const
+  IN_UNMOUNT* = 0x00002000    ## Backing fs was unmounted.
+  IN_Q_OVERFLOW* = 0x00004000 ## Event queued overflowed.
+  IN_IGNORED* = 0x00008000    ## File was ignored.
+
+# Special flags.
+const
+  IN_ONLYDIR* = 0x01000000     ## Only watch the path if it is a directory.
+  IN_DONT_FOLLOW* = 0x02000000 ## Do not follow a sym link.
+  IN_EXCL_UNLINK* = 0x04000000 ## Exclude events on unlinked objects.
+  IN_MASK_ADD* = 0x20000000    ## Add to the mask of an already existing watch.
+  IN_ISDIR* = 0x40000000       ## Event occurred against dir.
+  IN_ONESHOT* = 0x80000000     ## Only send event once.
+
+# All events which a program can wait on.
+const
+  IN_ALL_EVENTS* = (IN_ACCESS or IN_MODIFY or IN_ATTRIB or IN_CLOSE_WRITE or
+      IN_CLOSE_NOWRITE or IN_OPEN or IN_MOVED_FROM or IN_MOVED_TO or
+      IN_CREATE or IN_DELETE or IN_DELETE_SELF or IN_MOVE_SELF)
+
+
+proc inotify_init*(): FileHandle {.cdecl, importc: "inotify_init",
+    header: "<sys/inotify.h>".}
+  ## Create and initialize inotify instance.
+
+proc inotify_init1*(flags: cint): FileHandle {.cdecl, importc: "inotify_init1",
+    header: "<sys/inotify.h>".}
+  ## Like `inotify_init<#inotify_init>`_ ,
+  ## but has a flags argument that provides access to some extra functionality.
+
+proc inotify_add_watch*(fd: cint; name: cstring; mask: uint32): cint {.cdecl,
+    importc: "inotify_add_watch", header: "<sys/inotify.h>".}
+  ## Add watch of object NAME to inotify instance FD. Notify about events specified by MASK.
+
+proc inotify_rm_watch*(fd: cint; wd: cint): cint {.cdecl,
+    importc: "inotify_rm_watch", header: "<sys/inotify.h>".}
+  ## Remove the watch specified by WD from the inotify instance FD.
+
+iterator inotify_events*(evs: pointer, n: int): ptr InotifyEvent =
+  ## Abstract the packed buffer interface to yield event object pointers.
+  runnableExamples("-r:off"):
+    when defined(linux):
+       import std/posix  # needed for FileHandle read procedure
+       const MaxWatches = 8192
+
+       let inotifyFd = inotify_init()  # create new inotify instance and get it's FileHandle
+       let wd = inotifyFd.inotify_add_watch("/tmp", IN_CREATE or IN_DELETE)  # Add new watch
+
+       var events: array[MaxWatches, byte]  # event buffer
+       while (let n = read(inotifyFd, addr events, MaxWatches); n) > 0:  # blocks until any events have been read
+         for e in inotify_events(addr events, n):
+           echo (e[].wd, e[].mask, cast[cstring](addr e[].name))    # echo watch id, mask, and name value of each event
+  var ev: ptr InotifyEvent = cast[ptr InotifyEvent](evs)
+  var n = n
+  while n > 0:
+    yield ev
+    let sz = InotifyEvent.sizeof + int(ev[].len)
+    n -= sz
+    ev = cast[ptr InotifyEvent](cast[uint](ev) + uint(sz))
+
+runnableExamples:
+  when defined(linux):
+    let inotifyFd = inotify_init()  # create and get new inotify FileHandle
+    doAssert inotifyFd >= 0         # check for errors
+
+    let wd = inotifyFd.inotify_add_watch("/tmp", IN_CREATE or IN_DELETE)  # Add new watch
+    doAssert wd >= 0                 # check for errors
+
+    discard inotifyFd.inotify_rm_watch(wd) # remove watch
diff --git a/lib/posix/kqueue.nim b/lib/posix/kqueue.nim
new file mode 100644
index 000000000..2450cdb42
--- /dev/null
+++ b/lib/posix/kqueue.nim
@@ -0,0 +1,161 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2016 Eugene Kabanov
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+from std/posix import Timespec
+
+when defined(macosx) or defined(freebsd) or defined(openbsd) or
+     defined(dragonfly):
+  const
+    EVFILT_READ*     = -1
+    EVFILT_WRITE*    = -2
+    EVFILT_AIO*      = -3 ## attached to aio requests
+    EVFILT_VNODE*    = -4 ## attached to vnodes
+    EVFILT_PROC*     = -5 ## attached to struct proc
+    EVFILT_SIGNAL*   = -6 ## attached to struct proc
+    EVFILT_TIMER*    = -7 ## timers
+elif defined(netbsd):
+  const
+    EVFILT_READ*     = 0
+    EVFILT_WRITE*    = 1
+    EVFILT_AIO*      = 2 ## attached to aio requests
+    EVFILT_VNODE*    = 3 ## attached to vnodes
+    EVFILT_PROC*     = 4 ## attached to struct proc
+    EVFILT_SIGNAL*   = 5 ## attached to struct proc
+    EVFILT_TIMER*    = 6 ## timers (in ms)
+when defined(macosx):
+  const
+    EVFILT_MACHPORT* = -8  ## Mach portsets
+    EVFILT_FS*       = -9  ## filesystem events
+    EVFILT_USER*     = -10 ## user events
+    EVFILT_VM        = -12 ## virtual memory events
+elif defined(freebsd):
+  const
+    EVFILT_FS*       = -9  ## filesystem events
+    EVFILT_LIO*      = -10 ## attached to lio requests
+    EVFILT_USER*     = -11 ## user events
+elif defined(dragonfly):
+  const
+    EVFILT_EXCEPT*   = -8  ## exceptional conditions
+    EVFILT_USER*     = -9  ## user events
+    EVFILT_FS*       = -10 ## filesystem events
+
+# Actions:
+const
+  EV_ADD*      = 0x0001 ## Add event to queue (implies enable).
+                        ## Re-adding an existing element modifies it.
+  EV_DELETE*   = 0x0002 ## Delete event from queue.
+  EV_ENABLE*   = 0x0004 ## Enable event.
+  EV_DISABLE*  = 0x0008 ## Disable event (not reported).
+
+# Flags:
+const
+  EV_ONESHOT*  = 0x0010 ## Only report one occurrence.
+  EV_CLEAR*    = 0x0020 ## Clear event state after reporting.
+  EV_RECEIPT*  = 0x0040 ## Force EV_ERROR on success, data == 0
+  EV_DISPATCH* = 0x0080 ## Disable event after reporting.
+
+  EV_SYSFLAGS* = 0xF000 ## Reserved by system
+  EV_DROP*     = 0x1000 ## Not should be dropped
+  EV_FLAG1*    = 0x2000 ## Filter-specific flag
+
+# Return values:
+const
+  EV_EOF*      = 0x8000 ## EOF detected
+  EV_ERROR*    = 0x4000 ## Error, data contains errno
+  EV_NODATA*   = 0x1000 ## EOF and no more data
+
+when defined(macosx) or defined(freebsd) or defined(dragonfly):
+  # EVFILT_USER is not supported by OpenBSD and NetBSD
+  #
+  # data/hint flags/masks for EVFILT_USER, shared with userspace
+  #
+  # On input, the top two bits of fflags specifies how the lower twenty four
+  # bits should be applied to the stored value of fflags.
+  #
+  # On output, the top two bits will always be set to NOTE_FFNOP and the
+  # remaining twenty four bits will contain the stored fflags value.
+  const
+    NOTE_FFNOP*      = 0x00000000'u32 ## ignore input fflags
+    NOTE_FFAND*      = 0x40000000'u32 ## AND fflags
+    NOTE_FFOR*       = 0x80000000'u32 ## OR fflags
+    NOTE_FFCOPY*     = 0xc0000000'u32 ## copy fflags
+    NOTE_FFCTRLMASK* = 0xc0000000'u32 ## masks for operations
+    NOTE_FFLAGSMASK* = 0x00ffffff'u32
+
+    NOTE_TRIGGER*    = 0x01000000'u32 ## Cause the event to be triggered
+                                      ## for output.
+
+# data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
+const
+  NOTE_LOWAT*      = 0x0001 ## low water mark
+
+# data/hint flags for EVFILT_VNODE, shared with userspace
+const
+  NOTE_DELETE*     = 0x0001 ## vnode was removed
+  NOTE_WRITE*      = 0x0002 ## data contents changed
+  NOTE_EXTEND*     = 0x0004 ## size increased
+  NOTE_ATTRIB*     = 0x0008 ## attributes changed
+  NOTE_LINK*       = 0x0010 ## link count changed
+  NOTE_RENAME*     = 0x0020 ## vnode was renamed
+  NOTE_REVOKE*     = 0x0040 ## vnode access was revoked
+
+# data/hint flags for EVFILT_PROC, shared with userspace
+const
+  NOTE_EXIT*       = 0x80000000'u32 ## process exited
+  NOTE_FORK*       = 0x40000000'u32 ## process forked
+  NOTE_EXEC*       = 0x20000000'u32 ## process exec'd
+  NOTE_PCTRLMASK*  = 0xf0000000'u32 ## mask for hint bits
+  NOTE_PDATAMASK*  = 0x000fffff'u32 ## mask for pid
+
+# additional flags for EVFILT_PROC
+const
+  NOTE_TRACK*      = 0x00000001'u32 ## follow across forks
+  NOTE_TRACKERR*   = 0x00000002'u32 ## could not track child
+  NOTE_CHILD*      = 0x00000004'u32 ## am a child process
+
+when defined(macosx) or defined(freebsd):
+  # additional flags for EVFILE_TIMER
+  const
+    NOTE_SECONDS*    = 0x00000001'u32 ## data is seconds
+    NOTE_MSECONDS*   = 0x00000002'u32 ## data is milliseconds
+    NOTE_USECONDS*   = 0x00000004'u32 ## data is microseconds
+    NOTE_NSECONDS*   = 0x00000008'u32 ## data is nanoseconds
+else:
+  # NetBSD and OpenBSD doesn't support NOTE_{TIME} constants, but
+  # support EVFILT_TIMER with granularity of milliseconds.
+  const
+    NOTE_MSECONDS*   = 0x00000000'u32
+
+type
+  ## This define not fully satisfy NetBSD "struct kevent"
+  ## but it works and tested.
+  KEvent* {.importc: "struct kevent",
+            header: """#include <sys/types.h>
+                       #include <sys/event.h>
+                       #include <sys/time.h>""", pure, final.} = object
+    ident*  : uint     ## identifier for this event  (uintptr_t)
+    filter* : cshort   ## filter for event
+    flags*  : cushort  ## general flags
+    fflags* : cuint    ## filter-specific flags
+    data*   : int      ## filter-specific data  (intptr_t)
+    udata*  : pointer  ## opaque user data identifier
+
+proc kqueue*(): cint {.importc: "kqueue", header: "<sys/event.h>".}
+  ## Creates new queue and returns its descriptor.
+
+proc kevent*(kqFD: cint,
+             changelist: ptr KEvent, nchanges: cint,
+             eventlist: ptr KEvent, nevents: cint, timeout: ptr Timespec): cint
+     {.importc: "kevent", header: "<sys/event.h>".}
+  ## Manipulates queue for given `kqFD` descriptor.
+
+proc EV_SET*(event: ptr KEvent, ident: uint, filter: cshort, flags: cushort,
+             fflags: cuint, data: int, udata: pointer)
+     {.importc: "EV_SET", header: "<sys/event.h>".}
+  ## Fills event with given data.
diff --git a/lib/posix/linux.nim b/lib/posix/linux.nim
new file mode 100644
index 000000000..29fd4288d
--- /dev/null
+++ b/lib/posix/linux.nim
@@ -0,0 +1,39 @@
+import std/posix
+
+## Flags of `clone` syscall.
+## See `clone syscall manual
+## <https://man7.org/linux/man-pages/man2/clone.2.html>`_ for more information.
+const
+  CSIGNAL* = 0x000000FF'i32
+  CLONE_VM* = 0x00000100'i32
+  CLONE_FS* = 0x00000200'i32
+  CLONE_FILES* = 0x00000400'i32
+  CLONE_SIGHAND* = 0x00000800'i32
+  CLONE_PIDFD* = 0x00001000'i32
+  CLONE_PTRACE* = 0x00002000'i32
+  CLONE_VFORK* = 0x00004000'i32
+  CLONE_PARENT* = 0x00008000'i32
+  CLONE_THREAD* = 0x00010000'i32
+  CLONE_NEWNS* = 0x00020000'i32
+  CLONE_SYSVSEM* = 0x00040000'i32
+  CLONE_SETTLS* = 0x00080000'i32
+  CLONE_PARENT_SETTID* = 0x00100000'i32
+  CLONE_CHILD_CLEARTID* = 0x00200000'i32
+  CLONE_DETACHED* = 0x00400000'i32
+  CLONE_UNTRACED* = 0x00800000'i32
+  CLONE_CHILD_SETTID* = 0x01000000'i32
+  CLONE_NEWCGROUP* = 0x02000000'i32
+  CLONE_NEWUTS* = 0x04000000'i32
+  CLONE_NEWIPC* = 0x08000000'i32
+  CLONE_NEWUSER* = 0x10000000'i32
+  CLONE_NEWPID* = 0x20000000'i32
+  CLONE_NEWNET* = 0x40000000'i32
+  CLONE_IO* = 0x80000000'i32
+
+
+# fn should be of type proc (a2: pointer) {.cdecl.}
+proc clone*(fn: pointer; child_stack: pointer; flags: cint;
+            arg: pointer; ptid: ptr Pid; tls: pointer;
+            ctid: ptr Pid): cint {.importc, header: "<sched.h>".}
+
+proc pipe2*(a: array[0..1, cint], flags: cint): cint {.importc, header: "<unistd.h>".}
diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim
index 6bda372bb..fbe945df3 100755..100644
--- a/lib/posix/posix.nim
+++ b/lib/posix/posix.nim
@@ -1,7 +1,7 @@
 #
 #
-#            Nimrod's Runtime Library
-#        (c) Copyright 2010 Andreas Rumpf
+#            Nim's Runtime Library
+#        (c) Copyright 2012 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -13,48 +13,57 @@
 # net/if, sys/socket, sys/uio, netinet/in, netinet/tcp, netdb
 
 ## This is a raw POSIX interface module. It does not not provide any
-## convenience: cstrings are used instead of proper Nimrod strings and
-## return codes indicate errors. If you want exceptions 
-## and a proper Nimrod-like interface, use the OS module or write a wrapper.
-
+## convenience: cstrings are used instead of proper Nim strings and
+## return codes indicate errors. If you want exceptions
+## and a proper Nim-like interface, use the OS module or write a wrapper.
+##
+## For high-level wrappers specialized for Linux and BSDs see:
+## `posix_utils <posix_utils.html>`_
+##
 ## Coding conventions:
 ## ALL types are named the same as in the POSIX standard except that they start
-## with 'T' or 'P' (if they are pointers) and without the '_t' prefix to be
-## consistent with Nimrod conventions. If an identifier is a Nimrod keyword
+## with 'T' or 'P' (if they are pointers) and without the '_t' suffix to be
+## consistent with Nim conventions. If an identifier is a Nim keyword
 ## the \`identifier\` notation is used.
 ##
-## This library relies on the header files of your C compiler. Thus the
-## resulting C code will just include <XYZ.h> and *not* define the
+## This library relies on the header files of your C compiler. The
+## resulting C code will just `#include <XYZ.h>` and *not* define the
 ## symbols declared here.
 
-from times import TTime
+# Dead code elimination ensures that we don't accidentally generate #includes
+# for files that might not exist on a specific platform! The user will get an
+# error only if they actually try to use the missing declaration
 
-const
-  hasSpawnH = defined(linux)
-  hasAioH = defined(linux)
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+when defined(nimPreviewSlimSystem):
+  import std/syncio
 
+# TODO these constants don't seem to be fetched from a header file for unknown
+#      platforms - where do they come from and why are they here?
 when false:
   const
-    C_IRUSR = 0c000400 ## Read by owner.
-    C_IWUSR = 0c000200 ## Write by owner.
-    C_IXUSR = 0c000100 ## Execute by owner.
-    C_IRGRP = 0c000040 ## Read by group.
-    C_IWGRP = 0c000020 ## Write by group.
-    C_IXGRP = 0c000010 ## Execute by group.
-    C_IROTH = 0c000004 ## Read by others.
-    C_IWOTH = 0c000002 ## Write by others.
-    C_IXOTH = 0c000001 ## Execute by others.
-    C_ISUID = 0c004000 ## Set user ID.
-    C_ISGID = 0c002000 ## Set group ID.
-    C_ISVTX = 0c001000 ## On directories, restricted deletion flag.
-    C_ISDIR = 0c040000 ## Directory.
-    C_ISFIFO = 0c010000 ##FIFO.
-    C_ISREG = 0c100000 ## Regular file.
-    C_ISBLK = 0c060000 ## Block special.
-    C_ISCHR = 0c020000 ## Character special.
-    C_ISCTG = 0c110000 ## Reserved.
-    C_ISLNK = 0c120000 ## Symbolic link.</p>
-    C_ISSOCK = 0c140000 ## Socket.
+    C_IRUSR = 0o000400 ## Read by owner.
+    C_IWUSR = 0o000200 ## Write by owner.
+    C_IXUSR = 0o000100 ## Execute by owner.
+    C_IRGRP = 0o000040 ## Read by group.
+    C_IWGRP = 0o000020 ## Write by group.
+    C_IXGRP = 0o000010 ## Execute by group.
+    C_IROTH = 0o000004 ## Read by others.
+    C_IWOTH = 0o000002 ## Write by others.
+    C_IXOTH = 0o000001 ## Execute by others.
+    C_ISUID = 0o004000 ## Set user ID.
+    C_ISGID = 0o002000 ## Set group ID.
+    C_ISVTX = 0o001000 ## On directories, restricted deletion flag.
+    C_ISDIR = 0o040000 ## Directory.
+    C_ISFIFO = 0o010000 ##FIFO.
+    C_ISREG = 0o100000 ## Regular file.
+    C_ISBLK = 0o060000 ## Block special.
+    C_ISCHR = 0o020000 ## Character special.
+    C_ISCTG = 0o110000 ## Reserved.
+    C_ISLNK = 0o120000 ## Symbolic link.</p>
+    C_ISSOCK = 0o140000 ## Socket.
 
 const
   MM_NULLLBL* = nil
@@ -63,1657 +72,69 @@ const
   MM_NULLTXT* = nil
   MM_NULLACT* = nil
   MM_NULLTAG* = nil
-  
+
   STDERR_FILENO* = 2 ## File number of stderr;
   STDIN_FILENO* = 0  ## File number of stdin;
-  STDOUT_FILENO* = 1 ## File number of stdout; 
-
-type
-  TDIR* {.importc: "DIR", header: "<dirent.h>", final, pure.} = object
-    ## A type representing a directory stream. 
-
-  Tdirent* {.importc: "struct dirent", 
-             header: "<dirent.h>", final, pure.} = object ## dirent_t struct
-    d_ino*: TIno  ## File serial number.
-    d_name*: array [0..255, char] ## Name of entry.
-
-  Tflock* {.importc: "flock", final, pure,
-            header: "<fcntl.h>".} = object ## flock type
-    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. 
-    l_whence*: cshort ## Flag for starting offset. 
-    l_start*: Toff    ## Relative offset in bytes. 
-    l_len*: Toff      ## Size; if 0 then until EOF. 
-    l_pid*: TPid      ## Process ID of the process holding the lock; 
-                      ## returned with F_GETLK. 
-  
-  Tfenv* {.importc: "fenv_t", header: "<fenv.h>", final, pure.} = 
-    object ## Represents the entire floating-point environment. The
-           ## floating-point environment refers collectively to any
-           ## floating-point status flags and control modes supported
-           ## by the implementation.
-  Tfexcept* {.importc: "fexcept_t", header: "<fenv.h>", final, pure.} = 
-    object ## Represents the floating-point status flags collectively, 
-           ## including any status the implementation associates with the 
-           ## flags. A floating-point status flag is a system variable 
-           ## whose value is set (but never cleared) when a floating-point
-           ## exception is raised, which occurs as a side effect of
-           ## exceptional floating-point arithmetic to provide auxiliary
-           ## information. A floating-point control mode is a system variable
-           ## whose value may be set by the user to affect the subsequent 
-           ## behavior of floating-point arithmetic.
-
-  TFTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
-    base*: cint
-    level*: cint
-    
-  TGlob* {.importc: "glob_t", header: "<glob.h>", 
-           final, pure.} = object ## glob_t
-    gl_pathc*: int          ## Count of paths matched by pattern. 
-    gl_pathv*: cstringArray ## Pointer to a list of matched pathnames. 
-    gl_offs*: int           ## Slots to reserve at the beginning of gl_pathv. 
-  
-  TGroup* {.importc: "struct group", header: "<grp.h>", 
-            final, pure.} = object ## struct group
-    gr_name*: cstring     ## The name of the group. 
-    gr_gid*: TGid         ## Numerical group ID. 
-    gr_mem*: cstringArray ## Pointer to a null-terminated array of character 
-                          ## pointers to member names. 
-
-  Ticonv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} = 
-    object ## Identifies the conversion from one codeset to another.
-
-  Tlconv* {.importc: "struct lconv", header: "<locale.h>", final,
-            pure.} = object
-    currency_symbol*: cstring
-    decimal_point*: cstring
-    frac_digits*: char
-    grouping*: cstring
-    int_curr_symbol*: cstring
-    int_frac_digits*: char
-    int_n_cs_precedes*: char
-    int_n_sep_by_space*: char
-    int_n_sign_posn*: char
-    int_p_cs_precedes*: char
-    int_p_sep_by_space*: char
-    int_p_sign_posn*: char
-    mon_decimal_point*: cstring
-    mon_grouping*: cstring
-    mon_thousands_sep*: cstring
-    negative_sign*: cstring
-    n_cs_precedes*: char
-    n_sep_by_space*: char
-    n_sign_posn*: char
-    positive_sign*: cstring
-    p_cs_precedes*: char
-    p_sep_by_space*: char
-    p_sign_posn*: char
-    thousands_sep*: cstring
-
-  TMqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
-  TMqAttr* {.importc: "struct mq_attr", 
-             header: "<mqueue.h>", 
-             final, pure.} = object ## message queue attribute
-    mq_flags*: int   ## Message queue flags. 
-    mq_maxmsg*: int  ## Maximum number of messages. 
-    mq_msgsize*: int ## Maximum message size. 
-    mq_curmsgs*: int ## Number of messages currently queued. 
-
-  TPasswd* {.importc: "struct passwd", header: "<pwd.h>", 
-             final, pure.} = object ## struct passwd
-    pw_name*: cstring   ## User's login name. 
-    pw_uid*: TUid       ## Numerical user ID. 
-    pw_gid*: TGid       ## Numerical group ID. 
-    pw_dir*: cstring    ## Initial working directory. 
-    pw_shell*: cstring  ## Program to use as shell. 
-
-  Tblkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int
-    ## used for file block counts
-  Tblksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int
-    ## used for block sizes
-  TClock* {.importc: "clock_t", header: "<sys/types.h>".} = int
-  TClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int
-  TDev* {.importc: "dev_t", header: "<sys/types.h>".} = int
-  Tfsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int
-  Tfsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int
-  TGid* {.importc: "gid_t", header: "<sys/types.h>".} = int
-  Tid* {.importc: "id_t", header: "<sys/types.h>".} = int
-  Tino* {.importc: "ino_t", header: "<sys/types.h>".} = int
-  TKey* {.importc: "key_t", header: "<sys/types.h>".} = int
-  TMode* {.importc: "mode_t", header: "<sys/types.h>".} = int
-  TNlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int
-  TOff* {.importc: "off_t", header: "<sys/types.h>".} = int64
-  TPid* {.importc: "pid_t", header: "<sys/types.h>".} = int
-  Tpthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = int
-  Tpthread_barrier* {.importc: "pthread_barrier_t", 
-                      header: "<sys/types.h>".} = int
-  Tpthread_barrierattr* {.importc: "pthread_barrierattr_t", 
-                          header: "<sys/types.h>".} = int
-  Tpthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = int
-  Tpthread_condattr* {.importc: "pthread_condattr_t", 
-                       header: "<sys/types.h>".} = int
-  Tpthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = int
-  Tpthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = int
-  Tpthread_mutexattr* {.importc: "pthread_mutexattr_t", 
-                        header: "<sys/types.h>".} = int
-  Tpthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = int
-  Tpthread_rwlock* {.importc: "pthread_rwlock_t", 
-                     header: "<sys/types.h>".} = int
-  Tpthread_rwlockattr* {.importc: "pthread_rwlockattr_t", 
-                         header: "<sys/types.h>".} = int
-  Tpthread_spinlock* {.importc: "pthread_spinlock_t", 
-                       header: "<sys/types.h>".} = int
-  Tpthread* {.importc: "pthread_t", header: "<sys/types.h>".} = int
-  Tsuseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int
-  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
-  Ttimer* {.importc: "timer_t", header: "<sys/types.h>".} = int
-  Ttrace_attr* {.importc: "trace_attr_t", header: "<sys/types.h>".} = int
-  Ttrace_event_id* {.importc: "trace_event_id_t", 
-                     header: "<sys/types.h>".} = int
-  Ttrace_event_set* {.importc: "trace_event_set_t", 
-                      header: "<sys/types.h>".} = int
-  Ttrace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int
-  Tuid* {.importc: "uid_t", header: "<sys/types.h>".} = int
-  Tuseconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int
-  
-  Tutsname* {.importc: "struct utsname", 
-              header: "<sys/utsname.h>", 
-              final, pure.} = object ## struct utsname
-    sysname*,      ## Name of this implementation of the operating system. 
-      nodename*,   ## Name of this node within the communications 
-                   ## network to which this node is attached, if any. 
-      release*,    ## Current release level of this implementation. 
-      version*,    ## Current version level of this release. 
-      machine*: array [0..255, char] ## Name of the hardware type on which the
-                                     ## system is running. 
-
-  TSem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
-  Tipc_perm* {.importc: "struct ipc_perm", 
-               header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
-    uid*: tuid    ## Owner's user ID. 
-    gid*: tgid    ## Owner's group ID. 
-    cuid*: Tuid   ## Creator's user ID. 
-    cgid*: Tgid   ## Creator's group ID. 
-    mode*: TMode  ## Read/write permission. 
-  
-  TStat* {.importc: "struct stat", 
-           header: "<sys/stat.h>", final, pure.} = object ## struct stat
-    st_dev*: TDev          ## Device ID of device containing file. 
-    st_ino*: TIno          ## File serial number. 
-    st_mode*: TMode        ## Mode of file (see below). 
-    st_nlink*: tnlink      ## Number of hard links to the file. 
-    st_uid*: tuid          ## User ID of file. 
-    st_gid*: Tgid          ## Group ID of file. 
-    st_rdev*: TDev         ## Device ID (if file is character or block special). 
-    st_size*: TOff         ## For regular files, the file size in bytes. 
-                           ## For symbolic links, the length in bytes of the 
-                           ## pathname contained in the symbolic link. 
-                           ## For a shared memory object, the length in bytes. 
-                           ## For a typed memory object, the length in bytes. 
-                           ## For other file types, the use of this field is 
-                           ## unspecified. 
-    st_atime*: ttime       ## Time of last access. 
-    st_mtime*: ttime       ## Time of last data modification. 
-    st_ctime*: ttime       ## Time of last status change. 
-    st_blksize*: Tblksize  ## A file system-specific preferred I/O block size  
-                           ## for this object. In some file system types, this 
-                           ## may vary from file to file. 
-    st_blocks*: Tblkcnt    ## Number of blocks allocated for this object. 
-
-  
-  TStatvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>", 
-              final, pure.} = object ## struct statvfs
-    f_bsize*: int        ## File system block size. 
-    f_frsize*: int       ## Fundamental file system block size. 
-    f_blocks*: Tfsblkcnt ## Total number of blocks on file system
-                         ## in units of f_frsize. 
-    f_bfree*: Tfsblkcnt  ## Total number of free blocks. 
-    f_bavail*: Tfsblkcnt ## Number of free blocks available to 
-                         ## non-privileged process. 
-    f_files*: Tfsfilcnt  ## Total number of file serial numbers. 
-    f_ffree*: Tfsfilcnt  ## Total number of free file serial numbers. 
-    f_favail*: Tfsfilcnt ## Number of file serial numbers available to 
-                         ## non-privileged process. 
-    f_fsid*: int         ## File system ID. 
-    f_flag*: int         ## Bit mask of f_flag values. 
-    f_namemax*: int      ## Maximum filename length. 
-
-  Tposix_typed_mem_info* {.importc: "struct posix_typed_mem_info", 
-                           header: "<sys/mman.h>", final, pure.} = object
-    posix_tmi_length*: int
-  
-  Ttm* {.importc: "struct tm", header: "<time.h>", 
-         final, pure.} = object ## struct tm
-    tm_sec*: cint   ## Seconds [0,60]. 
-    tm_min*: cint   ## Minutes [0,59]. 
-    tm_hour*: cint  ## Hour [0,23]. 
-    tm_mday*: cint  ## Day of month [1,31]. 
-    tm_mon*: cint   ## Month of year [0,11]. 
-    tm_year*: cint  ## Years since 1900. 
-    tm_wday*: cint  ## Day of week [0,6] (Sunday =0). 
-    tm_yday*: cint  ## Day of year [0,365]. 
-    tm_isdst*: cint ## Daylight Savings flag. 
-  Ttimespec* {.importc: "struct timespec", 
-               header: "<time.h>", final, pure.} = object ## struct timespec
-    tv_sec*: Ttime ## Seconds. 
-    tv_nsec*: int  ## Nanoseconds. 
-  titimerspec* {.importc: "struct itimerspec", header: "<time.h>", 
-                 final, pure.} = object ## struct itimerspec
-    it_interval*: ttimespec ## Timer period. 
-    it_value*: ttimespec    ## Timer expiration. 
-  
-  Tsig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
-    ## Possibly volatile-qualified integer type of an object that can be 
-    ## accessed as an atomic entity, even in the presence of asynchronous
-    ## interrupts.
-  Tsigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
-  
-  TsigEvent* {.importc: "struct sigevent", 
-               header: "<signal.h>", final, pure.} = object ## struct sigevent
-    sigev_notify*: cint           ## Notification type. 
-    sigev_signo*: cint            ## Signal number. 
-    sigev_value*: Tsigval         ## Signal value. 
-    sigev_notify_function*: proc (x: TSigval) {.noconv.} ## Notification func. 
-    sigev_notify_attributes*: ptr Tpthreadattr ## Notification attributes.
-
-  TsigVal* {.importc: "union sigval", 
-             header: "<signal.h>", final, pure.} = object ## struct sigval
-    sival_ptr*: pointer ## pointer signal value; 
-                        ## integer signal value not defined!
-  TSigaction* {.importc: "struct sigaction", 
-                header: "<signal.h>", final, pure.} = object ## struct sigaction
-    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
-                                            ## function or one of the macros 
-                                            ## SIG_IGN or SIG_DFL. 
-    sa_mask*: TsigSet ## Set of signals to be blocked during execution of 
-                      ## the signal handling function. 
-    sa_flags*: cint   ## Special flags. 
-    sa_sigaction*: proc (x: cint, y: var TSigInfo, z: pointer) {.noconv.}
-
-  TStack* {.importc: "stack_t",
-            header: "<signal.h>", final, pure.} = object ## stack_t
-    ss_sp*: pointer  ## Stack base or pointer. 
-    ss_size*: int    ## Stack size. 
-    ss_flags*: cint  ## Flags. 
-
-  TSigStack* {.importc: "struct sigstack", 
-               header: "<signal.h>", final, pure.} = object ## struct sigstack
-    ss_onstack*: cint ## Non-zero when signal stack is in use. 
-    ss_sp*: pointer   ## Signal stack pointer. 
-
-  TsigInfo* {.importc: "siginfo_t", 
-              header: "<signal.h>", final, pure.} = object ## siginfo_t
-    si_signo*: cint    ## Signal number. 
-    si_code*: cint     ## Signal code. 
-    si_errno*: cint    ## If non-zero, an errno value associated with 
-                       ## this signal, as defined in <errno.h>. 
-    si_pid*: tpid      ## Sending process ID. 
-    si_uid*: tuid      ## Real user ID of sending process. 
-    si_addr*: pointer  ## Address of faulting instruction. 
-    si_status*: cint   ## Exit value or signal. 
-    si_band*: int      ## Band event for SIGPOLL. 
-    si_value*: TSigval ## Signal value. 
-  
-  Tnl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
-  Tnl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
-
-  Tsched_param* {.importc: "struct sched_param", 
-                  header: "<sched.h>", 
-                  final, pure.} = object ## struct sched_param
-    sched_priority*: cint
-    sched_ss_low_priority*: cint     ## Low scheduling priority for 
-                                     ## sporadic server. 
-    sched_ss_repl_period*: ttimespec ## Replenishment period for 
-                                     ## sporadic server. 
-    sched_ss_init_budget*: ttimespec ## Initial budget for sporadic server. 
-    sched_ss_max_repl*: cint         ## Maximum pending replenishments for 
-                                     ## sporadic server. 
-
-  Ttimeval* {.importc: "struct timeval", header: "<sys/select.h>", 
-              final, pure.} = object ## struct timeval
-    tv_sec*: int       ## Seconds. 
-    tv_usec*: int ## Microseconds. 
-  Tfd_set* {.importc: "fd_set", header: "<sys/select.h>", 
-             final, pure.} = object
-  Tmcontext* {.importc: "mcontext_t", header: "<ucontext.h>", 
-               final, pure.} = object
-  Tucontext* {.importc: "ucontext_t", header: "<ucontext.h>", 
-               final, pure.} = object ## ucontext_t
-    uc_link*: ptr Tucontext ## Pointer to the context that is resumed 
-                            ## when this context returns. 
-    uc_sigmask*: Tsigset    ## The set of signals that are blocked when this 
-                            ## context is active. 
-    uc_stack*: TStack       ## The stack used by this context. 
-    uc_mcontext*: Tmcontext ## A machine-specific representation of the saved 
-                            ## context. 
-
-when hasAioH:
-  type
-    Taiocb* {.importc: "struct aiocb", header: "<aio.h>", 
-              final, pure.} = object ## struct aiocb
-      aio_fildes*: cint         ## File descriptor. 
-      aio_offset*: TOff         ## File offset. 
-      aio_buf*: pointer         ## Location of buffer. 
-      aio_nbytes*: int          ## Length of transfer. 
-      aio_reqprio*: cint        ## Request priority offset. 
-      aio_sigevent*: TSigEvent  ## Signal number and value. 
-      aio_lio_opcode: cint      ## Operation to be performed. 
- 
-when hasSpawnH:
-  type
-    Tposix_spawnattr* {.importc: "posix_spawnattr_t", 
-                        header: "<spawn.h>".} = cint
-    Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t", 
-                                 header: "<spawn.h>".} = cint 
-
-type
-  TSocklen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cint
-  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cint
-  
-  TSockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>", 
-               pure, final.} = object ## struct sockaddr
-    sa_family*: Tsa_family         ## Address family. 
-    sa_data*: array [0..255, char] ## Socket address (variable-length data). 
-  
-  Tsockaddr_storage* {.importc: "struct sockaddr_storage",
-                       header: "<sys/socket.h>", 
-                       pure, final.} = object ## struct sockaddr_storage
-    ss_family*: Tsa_family ## Address family. 
-
-  Tif_nameindex* {.importc: "struct if_nameindex", final, 
-                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
-    if_index*: cint   ## Numeric index of the interface. 
-    if_name*: cstring ## Null-terminated name of the interface. 
-
-
-  TIOVec* {.importc: "struct iovec", pure, final,
-            header: "<sys/uio.h>".} = object ## struct iovec
-    iov_base*: pointer ## Base address of a memory region for input or output. 
-    iov_len*: int    ## The size of the memory pointed to by iov_base. 
-    
-  Tmsghdr* {.importc: "struct msghdr", pure, final,
-             header: "<sys/socket.h>".} = object  ## struct msghdr
-    msg_name*: pointer  ## Optional address. 
-    msg_namelen*: TSockLen  ## Size of address. 
-    msg_iov*: ptr TIOVec    ## Scatter/gather array. 
-    msg_iovlen*: cint   ## Members in msg_iov. 
-    msg_control*: pointer  ## Ancillary data; see below. 
-    msg_controllen*: TSockLen ## Ancillary data buffer len. 
-    msg_flags*: cint ## Flags on received message. 
-
-
-  Tcmsghdr* {.importc: "struct cmsghdr", pure, final, 
-              header: "<sys/socket.h>".} = object ## struct cmsghdr
-    cmsg_len*: TSockLen ## Data byte count, including the cmsghdr. 
-    cmsg_level*: cint   ## Originating protocol. 
-    cmsg_type*: cint    ## Protocol-specific type. 
-
-  TLinger* {.importc: "struct linger", pure, final, 
-             header: "<sys/socket.h>".} = object ## struct linger
-    l_onoff*: cint  ## Indicates whether linger option is enabled. 
-    l_linger*: cint ## Linger time, in seconds. 
-  
-  TInPort* = int16 ## unsigned!
-  TInAddrScalar* = int32 ## unsigned!
-  
-  TInAddr* {.importc: "struct in_addr", pure, final, 
-             header: "<netinet/in.h>".} = object ## struct in_addr
-    s_addr*: TInAddrScalar
-
-  Tsockaddr_in* {.importc: "struct sockaddr_in", pure, final, 
-                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
-    sin_family*: TSa_family ## AF_INET. 
-    sin_port*: TInPort      ## Port number. 
-    sin_addr*: TInAddr      ## IP address. 
-
-  TIn6Addr* {.importc: "struct in6_addr", pure, final,
-              header: "<netinet/in.h>".} = object ## struct in6_addr
-    s6_addr*: array [0..15, char]
-
-  Tsockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
-                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
-    sin6_family*: TSa_family ## AF_INET6. 
-    sin6_port*: TInPort      ## Port number. 
-    sin6_flowinfo*: int32    ## IPv6 traffic class and flow information. 
-    sin6_addr*: Tin6Addr     ## IPv6 address. 
-    sin6_scope_id*: int32    ## Set of interfaces for a scope. 
-  
-  Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final, 
-                header: "<netinet/in.h>".} = object ## struct ipv6_mreq
-    ipv6mr_multiaddr*: TIn6Addr ## IPv6 multicast address. 
-    ipv6mr_interface*: cint     ## Interface index. 
-
-  Thostent* {.importc: "struct hostent", pure, final, 
-              header: "<netdb.h>".} = object ## struct hostent
-    h_name*: cstring           ## Official name of the host. 
-    h_aliases*: cstringArray   ## A pointer to an array of pointers to 
-                               ## alternative host names, terminated by a 
-                               ## null pointer. 
-    h_addrtype*: cint          ## Address type. 
-    h_length*: cint            ## The length, in bytes, of the address. 
-    h_addr_list*: cstringArray ## A pointer to an array of pointers to network 
-                               ## addresses (in network byte order) for the
-                               ## host, terminated by a null pointer. 
-
-  Tnetent* {.importc: "struct netent", pure, final, 
-              header: "<netdb.h>".} = object ## struct netent
-    n_name*: cstring         ## Official, fully-qualified (including the 
-                             ## domain) name of the host. 
-    n_aliases*: cstringArray ## A pointer to an array of pointers to 
-                             ## alternative network names, terminated by a 
-                             ## null pointer. 
-    n_addrtype*: cint        ## The address type of the network. 
-    n_net*: int32            ## The network number, in host byte order. 
-
-  TProtoent* {.importc: "struct protoent", pure, final, 
-              header: "<netdb.h>".} = object ## struct protoent
-    p_name*: cstring         ## Official name of the protocol. 
-    p_aliases*: cstringArray ## A pointer to an array of pointers to 
-                             ## alternative protocol names, terminated by 
-                             ## a null pointer. 
-    p_proto*: cint           ## The protocol number. 
-
-  TServent* {.importc: "struct servent", pure, final, 
-              header: "<netdb.h>".} = object ## struct servent
-    s_name*: cstring         ## Official name of the service. 
-    s_aliases*: cstringArray ## A pointer to an array of pointers to 
-                             ## alternative service names, terminated by 
-                             ## a null pointer. 
-    s_port*: cint            ## The port number at which the service 
-                             ## resides, in network byte order. 
-    s_proto*: cstring        ## The name of the protocol to use when 
-                             ## contacting the service. 
-
-  Taddrinfo* {.importc: "struct addrinfo", pure, final, 
-              header: "<netdb.h>".} = object ## struct addrinfo
-    ai_flags*: cint         ## Input flags. 
-    ai_family*: cint        ## Address family of socket. 
-    ai_socktype*: cint      ## Socket type. 
-    ai_protocol*: cint      ## Protocol of socket. 
-    ai_addrlen*: TSockLen   ## Length of socket address. 
-    ai_addr*: ptr TSockAddr ## Socket address of socket. 
-    ai_canonname*: cstring  ## Canonical name of service location. 
-    ai_next*: ptr TAddrInfo ## Pointer to next in list. 
-  
-  TPollfd* {.importc: "struct pollfd", pure, final, 
-             header: "<poll.h>".} = object ## struct pollfd
-    fd*: cint        ## The following descriptor being polled. 
-    events*: cshort  ## The input event flags (see below). 
-    revents*: cshort ## The output event flags (see below).  
-  
-  Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint
-
-var
-  errno* {.importc, header: "<errno.h>".}: cint ## error variable
-  daylight* {.importc, header: "<time.h>".}: cint
-  timezone* {.importc, header: "<time.h>".}: int
-  
-# Constants as variables:
-when hasAioH:
-  var
-    AIO_ALLDONE* {.importc, header: "<aio.h>".}: cint
-      ## A return value indicating that none of the requested operations 
-      ## could be canceled since they are already complete.
-    AIO_CANCELED* {.importc, header: "<aio.h>".}: cint
-      ## A return value indicating that all requested operations have
-      ## been canceled.
-    AIO_NOTCANCELED* {.importc, header: "<aio.h>".}: cint
-      ## A return value indicating that some of the requested operations could 
-      ## not be canceled since they are in progress.
-    LIO_NOP* {.importc, header: "<aio.h>".}: cint
-      ## A lio_listio() element operation option indicating that no transfer is
-      ## requested.
-    LIO_NOWAIT* {.importc, header: "<aio.h>".}: cint
-      ## A lio_listio() synchronization operation indicating that the calling 
-      ## thread is to continue execution while the lio_listio() operation is 
-      ## being performed, and no notification is given when the operation is
-      ## complete.
-    LIO_READ* {.importc, header: "<aio.h>".}: cint
-      ## A lio_listio() element operation option requesting a read.
-    LIO_WAIT* {.importc, header: "<aio.h>".}: cint
-      ## A lio_listio() synchronization operation indicating that the calling 
-      ## thread is to suspend until the lio_listio() operation is complete.
-    LIO_WRITE* {.importc, header: "<aio.h>".}: cint
-      ## A lio_listio() element operation option requesting a write.
-
-var
-  RTLD_LAZY* {.importc, header: "<dlfcn.h>".}: cint
-    ## Relocations are performed at an implementation-defined time.
-  RTLD_NOW* {.importc, header: "<dlfcn.h>".}: cint
-    ## Relocations are performed when the object is loaded.
-  RTLD_GLOBAL* {.importc, header: "<dlfcn.h>".}: cint
-    ## All symbols are available for relocation processing of other modules.
-  RTLD_LOCAL* {.importc, header: "<dlfcn.h>".}: cint
-    ## All symbols are not made available for relocation processing by 
-    ## other modules. 
-    
-  E2BIG* {.importc, header: "<errno.h>".}: cint
-      ## Argument list too long.
-  EACCES* {.importc, header: "<errno.h>".}: cint
-      ## Permission denied.
-  EADDRINUSE* {.importc, header: "<errno.h>".}: cint
-      ## Address in use.
-  EADDRNOTAVAIL* {.importc, header: "<errno.h>".}: cint
-      ## Address not available.
-  EAFNOSUPPORT* {.importc, header: "<errno.h>".}: cint
-      ## Address family not supported.
-  EAGAIN* {.importc, header: "<errno.h>".}: cint
-      ## Resource unavailable, try again (may be the same value as EWOULDBLOCK).
-  EALREADY* {.importc, header: "<errno.h>".}: cint
-      ## Connection already in progress.
-  EBADF* {.importc, header: "<errno.h>".}: cint
-      ## Bad file descriptor.
-  EBADMSG* {.importc, header: "<errno.h>".}: cint
-      ## Bad message.
-  EBUSY* {.importc, header: "<errno.h>".}: cint
-      ## Device or resource busy.
-  ECANCELED* {.importc, header: "<errno.h>".}: cint
-      ## Operation canceled.
-  ECHILD* {.importc, header: "<errno.h>".}: cint
-      ## No child processes.
-  ECONNABORTED* {.importc, header: "<errno.h>".}: cint
-      ## Connection aborted.
-  ECONNREFUSED* {.importc, header: "<errno.h>".}: cint
-      ## Connection refused.
-  ECONNRESET* {.importc, header: "<errno.h>".}: cint
-      ## Connection reset.
-  EDEADLK* {.importc, header: "<errno.h>".}: cint
-      ## Resource deadlock would occur.
-  EDESTADDRREQ* {.importc, header: "<errno.h>".}: cint
-      ## Destination address required.
-  EDOM* {.importc, header: "<errno.h>".}: cint
-      ## Mathematics argument out of domain of function.
-  EDQUOT* {.importc, header: "<errno.h>".}: cint
-      ## Reserved.
-  EEXIST* {.importc, header: "<errno.h>".}: cint
-      ## File exists.
-  EFAULT* {.importc, header: "<errno.h>".}: cint
-      ## Bad address.
-  EFBIG* {.importc, header: "<errno.h>".}: cint
-      ## File too large.
-  EHOSTUNREACH* {.importc, header: "<errno.h>".}: cint
-      ## Host is unreachable.
-  EIDRM* {.importc, header: "<errno.h>".}: cint
-      ## Identifier removed.
-  EILSEQ* {.importc, header: "<errno.h>".}: cint
-      ## Illegal byte sequence.
-  EINPROGRESS* {.importc, header: "<errno.h>".}: cint
-      ## Operation in progress.
-  EINTR* {.importc, header: "<errno.h>".}: cint
-      ## Interrupted function.
-  EINVAL* {.importc, header: "<errno.h>".}: cint
-      ## Invalid argument.
-  EIO* {.importc, header: "<errno.h>".}: cint
-      ## I/O error.
-  EISCONN* {.importc, header: "<errno.h>".}: cint
-      ## Socket is connected.
-  EISDIR* {.importc, header: "<errno.h>".}: cint
-      ## Is a directory.
-  ELOOP* {.importc, header: "<errno.h>".}: cint
-      ## Too many levels of symbolic links.
-  EMFILE* {.importc, header: "<errno.h>".}: cint
-      ## Too many open files.
-  EMLINK* {.importc, header: "<errno.h>".}: cint
-      ## Too many links.
-  EMSGSIZE* {.importc, header: "<errno.h>".}: cint
-      ## Message too large.
-  EMULTIHOP* {.importc, header: "<errno.h>".}: cint
-      ## Reserved.
-  ENAMETOOLONG* {.importc, header: "<errno.h>".}: cint
-      ## Filename too long.
-  ENETDOWN* {.importc, header: "<errno.h>".}: cint
-      ## Network is down.
-  ENETRESET* {.importc, header: "<errno.h>".}: cint
-      ## Connection aborted by network.
-  ENETUNREACH* {.importc, header: "<errno.h>".}: cint
-      ## Network unreachable.
-  ENFILE* {.importc, header: "<errno.h>".}: cint
-      ## Too many files open in system.
-  ENOBUFS* {.importc, header: "<errno.h>".}: cint
-      ## No buffer space available.
-  ENODATA* {.importc, header: "<errno.h>".}: cint
-      ## No message is available on the STREAM head read queue.
-  ENODEV* {.importc, header: "<errno.h>".}: cint
-      ## No such device.
-  ENOENT* {.importc, header: "<errno.h>".}: cint
-      ## No such file or directory.
-  ENOEXEC* {.importc, header: "<errno.h>".}: cint
-      ## Executable file format error.
-  ENOLCK* {.importc, header: "<errno.h>".}: cint
-      ## No locks available.
-  ENOLINK* {.importc, header: "<errno.h>".}: cint
-      ## Reserved.
-  ENOMEM* {.importc, header: "<errno.h>".}: cint
-      ## Not enough space.
-  ENOMSG* {.importc, header: "<errno.h>".}: cint
-      ## No message of the desired type.
-  ENOPROTOOPT* {.importc, header: "<errno.h>".}: cint
-      ## Protocol not available.
-  ENOSPC* {.importc, header: "<errno.h>".}: cint
-      ## No space left on device.
-  ENOSR* {.importc, header: "<errno.h>".}: cint
-      ## No STREAM resources.
-  ENOSTR* {.importc, header: "<errno.h>".}: cint
-      ## Not a STREAM.
-  ENOSYS* {.importc, header: "<errno.h>".}: cint
-      ## Function not supported.
-  ENOTCONN* {.importc, header: "<errno.h>".}: cint
-      ## The socket is not connected.
-  ENOTDIR* {.importc, header: "<errno.h>".}: cint
-      ## Not a directory.
-  ENOTEMPTY* {.importc, header: "<errno.h>".}: cint
-      ## Directory not empty.
-  ENOTSOCK* {.importc, header: "<errno.h>".}: cint
-      ## Not a socket.
-  ENOTSUP* {.importc, header: "<errno.h>".}: cint
-      ## Not supported.
-  ENOTTY* {.importc, header: "<errno.h>".}: cint
-      ## Inappropriate I/O control operation.
-  ENXIO* {.importc, header: "<errno.h>".}: cint
-      ## No such device or address.
-  EOPNOTSUPP* {.importc, header: "<errno.h>".}: cint
-      ## Operation not supported on socket.
-  EOVERFLOW* {.importc, header: "<errno.h>".}: cint
-      ## Value too large to be stored in data type.
-  EPERM* {.importc, header: "<errno.h>".}: cint
-      ## Operation not permitted.
-  EPIPE* {.importc, header: "<errno.h>".}: cint
-      ## Broken pipe.
-  EPROTO* {.importc, header: "<errno.h>".}: cint
-      ## Protocol error.
-  EPROTONOSUPPORT* {.importc, header: "<errno.h>".}: cint
-      ## Protocol not supported.
-  EPROTOTYPE* {.importc, header: "<errno.h>".}: cint
-      ## Protocol wrong type for socket.
-  ERANGE* {.importc, header: "<errno.h>".}: cint
-      ## Result too large.
-  EROFS* {.importc, header: "<errno.h>".}: cint
-      ## Read-only file system.
-  ESPIPE* {.importc, header: "<errno.h>".}: cint
-      ## Invalid seek.
-  ESRCH* {.importc, header: "<errno.h>".}: cint
-      ## No such process.
-  ESTALE* {.importc, header: "<errno.h>".}: cint
-      ## Reserved.
-  ETIME* {.importc, header: "<errno.h>".}: cint
-      ## Stream ioctl() timeout.
-  ETIMEDOUT* {.importc, header: "<errno.h>".}: cint
-      ## Connection timed out.
-  ETXTBSY* {.importc, header: "<errno.h>".}: cint
-      ## Text file busy.
-  EWOULDBLOCK* {.importc, header: "<errno.h>".}: cint
-      ## Operation would block (may be the same value as [EAGAIN]).
-  EXDEV* {.importc, header: "<errno.h>".}: cint
-      ## Cross-device link.   
-
-  F_DUPFD* {.importc, header: "<fcntl.h>".}: cint
-    ## Duplicate file descriptor.
-  F_GETFD* {.importc, header: "<fcntl.h>".}: cint
-    ## Get file descriptor flags.
-  F_SETFD* {.importc, header: "<fcntl.h>".}: cint
-    ## Set file descriptor flags.
-  F_GETFL* {.importc, header: "<fcntl.h>".}: cint
-    ## Get file status flags and file access modes.
-  F_SETFL* {.importc, header: "<fcntl.h>".}: cint
-    ## Set file status flags.
-  F_GETLK* {.importc, header: "<fcntl.h>".}: cint
-    ## Get record locking information.
-  F_SETLK* {.importc, header: "<fcntl.h>".}: cint
-    ## Set record locking information.
-  F_SETLKW* {.importc, header: "<fcntl.h>".}: cint
-    ## Set record locking information; wait if blocked.
-  F_GETOWN* {.importc, header: "<fcntl.h>".}: cint
-    ## Get process or process group ID to receive SIGURG signals.
-  F_SETOWN* {.importc, header: "<fcntl.h>".}: cint
-    ## Set process or process group ID to receive SIGURG signals. 
-  FD_CLOEXEC* {.importc, header: "<fcntl.h>".}: cint
-    ## Close the file descriptor upon execution of an exec family function. 
-  F_RDLCK* {.importc, header: "<fcntl.h>".}: cint
-    ## Shared or read lock.
-  F_UNLCK* {.importc, header: "<fcntl.h>".}: cint
-    ## Unlock.
-  F_WRLCK* {.importc, header: "<fcntl.h>".}: cint
-    ## Exclusive or write lock. 
-  O_CREAT* {.importc, header: "<fcntl.h>".}: cint
-    ## Create file if it does not exist.
-  O_EXCL* {.importc, header: "<fcntl.h>".}: cint
-    ## Exclusive use flag.
-  O_NOCTTY* {.importc, header: "<fcntl.h>".}: cint
-    ## Do not assign controlling terminal.
-  O_TRUNC* {.importc, header: "<fcntl.h>".}: cint
-    ## Truncate flag. 
-  O_APPEND* {.importc, header: "<fcntl.h>".}: cint
-    ## Set append mode.
-  O_DSYNC* {.importc, header: "<fcntl.h>".}: cint
-    ## Write according to synchronized I/O data integrity completion.
-  O_NONBLOCK* {.importc, header: "<fcntl.h>".}: cint
-    ## Non-blocking mode.
-  O_RSYNC* {.importc, header: "<fcntl.h>".}: cint
-    ## Synchronized read I/O operations.
-  O_SYNC* {.importc, header: "<fcntl.h>".}: cint
-    ## Write according to synchronized I/O file integrity completion. 
-  O_ACCMODE* {.importc, header: "<fcntl.h>".}: cint
-    ## Mask for file access modes.      
-  O_RDONLY* {.importc, header: "<fcntl.h>".}: cint
-    ## Open for reading only.
-  O_RDWR* {.importc, header: "<fcntl.h>".}: cint
-    ## Open for reading and writing.
-  O_WRONLY* {.importc, header: "<fcntl.h>".}: cint
-    ## Open for writing only. 
-  POSIX_FADV_NORMAL* {.importc, header: "<fcntl.h>".}: cint
-    ## The application has no advice to give on its behavior with
-    ## respect to the specified data. It is the default characteristic
-    ## if no advice is given for an open file.
-  POSIX_FADV_SEQUENTIAL* {.importc, header: "<fcntl.h>".}: cint
-    ## The application expects to access the specified data 
-    # sequentially from lower offsets to higher offsets.
-  POSIX_FADV_RANDOM* {.importc, header: "<fcntl.h>".}: cint
-    ## The application expects to access the specified data in a random order.
-  POSIX_FADV_WILLNEED* {.importc, header: "<fcntl.h>".}: cint
-    ## The application expects to access the specified data in the near future.
-  POSIX_FADV_DONTNEED* {.importc, header: "<fcntl.h>".}: cint
-    ## The application expects that it will not access the specified data
-    ## in the near future.
-  POSIX_FADV_NOREUSE* {.importc, header: "<fcntl.h>".}: cint
-    ## The application expects to access the specified data once and 
-    ## then not reuse it thereafter. 
-
-  FE_DIVBYZERO* {.importc, header: "<fenv.h>".}: cint
-  FE_INEXACT* {.importc, header: "<fenv.h>".}: cint
-  FE_INVALID* {.importc, header: "<fenv.h>".}: cint
-  FE_OVERFLOW* {.importc, header: "<fenv.h>".}: cint
-  FE_UNDERFLOW* {.importc, header: "<fenv.h>".}: cint
-  FE_ALL_EXCEPT* {.importc, header: "<fenv.h>".}: cint
-  FE_DOWNWARD* {.importc, header: "<fenv.h>".}: cint
-  FE_TONEAREST* {.importc, header: "<fenv.h>".}: cint
-  FE_TOWARDZERO* {.importc, header: "<fenv.h>".}: cint
-  FE_UPWARD* {.importc, header: "<fenv.h>".}: cint
-  FE_DFL_ENV* {.importc, header: "<fenv.h>".}: cint
-
-  MM_HARD* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Source of the condition is hardware.
-  MM_SOFT* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Source of the condition is software.
-  MM_FIRM* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Source of the condition is firmware.
-  MM_APPL* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Condition detected by application.
-  MM_UTIL* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Condition detected by utility.
-  MM_OPSYS* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Condition detected by operating system.
-  MM_RECOVER* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Recoverable error.
-  MM_NRECOV* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Non-recoverable error.
-  MM_HALT* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Error causing application to halt.
-  MM_ERROR* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Application has encountered a non-fatal fault.
-  MM_WARNING* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Application has detected unusual non-error condition.
-  MM_INFO* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Informative message.
-  MM_NOSEV* {.importc, header: "<fmtmsg.h>".}: cint
-    ## No severity level provided for the message.
-  MM_PRINT* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Display message on standard error.
-  MM_CONSOLE* {.importc, header: "<fmtmsg.h>".}: cint
-    ## Display message on system console. 
-
-  MM_OK* {.importc, header: "<fmtmsg.h>".}: cint
-    ## The function succeeded.
-  MM_NOTOK* {.importc, header: "<fmtmsg.h>".}: cint
-    ## The function failed completely.
-  MM_NOMSG* {.importc, header: "<fmtmsg.h>".}: cint
-    ## The function was unable to generate a message on standard error, 
-    ## but otherwise succeeded.
-  MM_NOCON* {.importc, header: "<fmtmsg.h>".}: cint
-    ## The function was unable to generate a console message, but 
-    ## otherwise succeeded. 
-    
-  FNM_NOMATCH* {.importc, header: "<fnmatch.h>".}: cint
-    ## The string does not match the specified pattern.
-  FNM_PATHNAME* {.importc, header: "<fnmatch.h>".}: cint
-    ## Slash in string only matches slash in pattern.
-  FNM_PERIOD* {.importc, header: "<fnmatch.h>".}: cint
-    ## Leading period in string must be exactly matched by period in pattern.
-  FNM_NOESCAPE* {.importc, header: "<fnmatch.h>".}: cint
-    ## Disable backslash escaping.
-  FNM_NOSYS* {.importc, header: "<fnmatch.h>".}: cint
-    ## Reserved.
-
-  FTW_F* {.importc, header: "<ftw.h>".}: cint
-    ## File.
-  FTW_D* {.importc, header: "<ftw.h>".}: cint
-    ## Directory.
-  FTW_DNR* {.importc, header: "<ftw.h>".}: cint
-    ## Directory without read permission.
-  FTW_DP* {.importc, header: "<ftw.h>".}: cint
-    ## Directory with subdirectories visited.
-  FTW_NS* {.importc, header: "<ftw.h>".}: cint
-    ## Unknown type; stat() failed.
-  FTW_SL* {.importc, header: "<ftw.h>".}: cint
-    ## Symbolic link.
-  FTW_SLN* {.importc, header: "<ftw.h>".}: cint
-    ## Symbolic link that names a nonexistent file.
-
-  FTW_PHYS* {.importc, header: "<ftw.h>".}: cint
-    ## Physical walk, does not follow symbolic links. Otherwise, nftw() 
-    ## follows links but does not walk down any path that crosses itself.
-  FTW_MOUNT* {.importc, header: "<ftw.h>".}: cint
-    ## The walk does not cross a mount point.
-  FTW_DEPTH* {.importc, header: "<ftw.h>".}: cint
-    ## All subdirectories are visited before the directory itself.
-  FTW_CHDIR* {.importc, header: "<ftw.h>".}: cint
-    ## The walk changes to each directory before reading it. 
-
-  GLOB_APPEND* {.importc, header: "<glob.h>".}: cint
-    ## Append generated pathnames to those previously obtained.
-  GLOB_DOOFFS* {.importc, header: "<glob.h>".}: cint
-    ## Specify how many null pointers to add to the beginning of gl_pathv.
-  GLOB_ERR* {.importc, header: "<glob.h>".}: cint
-    ## Cause glob() to return on error.
-  GLOB_MARK* {.importc, header: "<glob.h>".}: cint
-    ## Each pathname that is a directory that matches pattern has a 
-    ## slash appended.
-  GLOB_NOCHECK* {.importc, header: "<glob.h>".}: cint
-    ## If pattern does not match any pathname, then return a list
-    ## consisting of only pattern.
-  GLOB_NOESCAPE* {.importc, header: "<glob.h>".}: cint
-    ## Disable backslash escaping.
-  GLOB_NOSORT* {.importc, header: "<glob.h>".}: cint
-    ## Do not sort the pathnames returned.
-  GLOB_ABORTED* {.importc, header: "<glob.h>".}: cint
-    ## The scan was stopped because GLOB_ERR was set or errfunc() 
-    ## returned non-zero.
-  GLOB_NOMATCH* {.importc, header: "<glob.h>".}: cint
-    ## The pattern does not match any existing pathname, and GLOB_NOCHECK 
-    ## was not set in flags.
-  GLOB_NOSPACE* {.importc, header: "<glob.h>".}: cint
-    ## An attempt to allocate memory failed.
-  GLOB_NOSYS* {.importc, header: "<glob.h>".}: cint
-    ## Reserved
-
-  CODESET* {.importc, header: "<langinfo.h>".}: cint
-    ## Codeset name.
-  D_T_FMT* {.importc, header: "<langinfo.h>".}: cint
-    ## String for formatting date and time.
-  D_FMT * {.importc, header: "<langinfo.h>".}: cint
-    ## Date format string.
-  T_FMT* {.importc, header: "<langinfo.h>".}: cint
-    ## Time format string.
-  T_FMT_AMPM* {.importc, header: "<langinfo.h>".}: cint
-    ## a.m. or p.m. time format string.
-  AM_STR* {.importc, header: "<langinfo.h>".}: cint
-    ## Ante-meridiem affix.
-  PM_STR* {.importc, header: "<langinfo.h>".}: cint
-    ## Post-meridiem affix.
-  DAY_1* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the first day of the week (for example, Sunday).
-  DAY_2* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the second day of the week (for example, Monday).
-  DAY_3* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the third day of the week (for example, Tuesday).
-  DAY_4* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the fourth day of the week (for example, Wednesday).
-  DAY_5* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the fifth day of the week (for example, Thursday).
-  DAY_6* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the sixth day of the week (for example, Friday).
-  DAY_7* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the seventh day of the week (for example, Saturday).
-  ABDAY_1* {.importc, header: "<langinfo.h>".}: cint
-    ## Abbreviated name of the first day of the week.
-  ABDAY_2* {.importc, header: "<langinfo.h>".}: cint
-  ABDAY_3* {.importc, header: "<langinfo.h>".}: cint
-  ABDAY_4* {.importc, header: "<langinfo.h>".}: cint
-  ABDAY_5* {.importc, header: "<langinfo.h>".}: cint
-  ABDAY_6* {.importc, header: "<langinfo.h>".}: cint
-  ABDAY_7* {.importc, header: "<langinfo.h>".}: cint
-  MON_1* {.importc, header: "<langinfo.h>".}: cint
-    ## Name of the first month of the year.
-  MON_2* {.importc, header: "<langinfo.h>".}: cint
-  MON_3* {.importc, header: "<langinfo.h>".}: cint
-  MON_4* {.importc, header: "<langinfo.h>".}: cint
-  MON_5* {.importc, header: "<langinfo.h>".}: cint
-  MON_6* {.importc, header: "<langinfo.h>".}: cint
-  MON_7* {.importc, header: "<langinfo.h>".}: cint
-  MON_8* {.importc, header: "<langinfo.h>".}: cint
-  MON_9* {.importc, header: "<langinfo.h>".}: cint
-  MON_10* {.importc, header: "<langinfo.h>".}: cint
-  MON_11* {.importc, header: "<langinfo.h>".}: cint
-  MON_12* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_1* {.importc, header: "<langinfo.h>".}: cint
-    ## Abbreviated name of the first month.
-  ABMON_2* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_3* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_4* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_5* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_6* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_7* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_8* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_9* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_10* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_11* {.importc, header: "<langinfo.h>".}: cint
-  ABMON_12* {.importc, header: "<langinfo.h>".}: cint
-  ERA* {.importc, header: "<langinfo.h>".}: cint
-    ## Era description segments.
-  ERA_D_FMT* {.importc, header: "<langinfo.h>".}: cint
-    ## Era date format string.
-  ERA_D_T_FMT* {.importc, header: "<langinfo.h>".}: cint
-    ## Era date and time format string.
-  ERA_T_FMT* {.importc, header: "<langinfo.h>".}: cint
-    ## Era time format string.
-  ALT_DIGITS* {.importc, header: "<langinfo.h>".}: cint
-    ## Alternative symbols for digits.
-  RADIXCHAR* {.importc, header: "<langinfo.h>".}: cint
-    ## Radix character.
-  THOUSEP* {.importc, header: "<langinfo.h>".}: cint
-    ## Separator for thousands.
-  YESEXPR* {.importc, header: "<langinfo.h>".}: cint
-    ## Affirmative response expression.
-  NOEXPR* {.importc, header: "<langinfo.h>".}: cint
-    ## Negative response expression.
-  CRNCYSTR* {.importc, header: "<langinfo.h>".}: cint
-    ## Local currency symbol, preceded by '-' if the symbol 
-    ## should appear before the value, '+' if the symbol should appear 
-    ## after the value, or '.' if the symbol should replace the radix
-    ## character. If the local currency symbol is the empty string, 
-    ## implementations may return the empty string ( "" ).
-
-  LC_ALL* {.importc, header: "<locale.h>".}: cint
-  LC_COLLATE* {.importc, header: "<locale.h>".}: cint
-  LC_CTYPE* {.importc, header: "<locale.h>".}: cint
-  LC_MESSAGES* {.importc, header: "<locale.h>".}: cint
-  LC_MONETARY* {.importc, header: "<locale.h>".}: cint
-  LC_NUMERIC* {.importc, header: "<locale.h>".}: cint
-  LC_TIME* {.importc, header: "<locale.h>".}: cint
-  
-  PTHREAD_BARRIER_SERIAL_THREAD* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CANCEL_ASYNCHRONOUS* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CANCEL_ENABLE* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CANCEL_DEFERRED* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CANCEL_DISABLE* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CANCELED* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_COND_INITIALIZER* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CREATE_DETACHED* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_CREATE_JOINABLE* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_EXPLICIT_SCHED* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_INHERIT_SCHED* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_MUTEX_DEFAULT* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_MUTEX_ERRORCHECK* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_MUTEX_INITIALIZER* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_MUTEX_NORMAL* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_MUTEX_RECURSIVE* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_ONCE_INIT* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_PRIO_INHERIT* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_PRIO_NONE* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_PRIO_PROTECT* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_PROCESS_SHARED* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_PROCESS_PRIVATE* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_SCOPE_PROCESS* {.importc, header: "<pthread.h>".}: cint
-  PTHREAD_SCOPE_SYSTEM* {.importc, header: "<pthread.h>".}: cint
-
-  POSIX_ASYNC_IO* {.importc: "_POSIX_ASYNC_IO", header: "<unistd.h>".}: cint
-  POSIX_PRIO_IO* {.importc: "_POSIX_PRIO_IO", header: "<unistd.h>".}: cint
-  POSIX_SYNC_IO* {.importc: "_POSIX_SYNC_IO", header: "<unistd.h>".}: cint
-  F_OK* {.importc: "F_OK", header: "<unistd.h>".}: cint
-  R_OK* {.importc: "R_OK", header: "<unistd.h>".}: cint
-  W_OK* {.importc: "W_OK", header: "<unistd.h>".}: cint
-  X_OK* {.importc: "X_OK", header: "<unistd.h>".}: cint
-
-  CS_PATH* {.importc: "_CS_PATH", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_ILP32_OFF32_CFLAGS* {.importc: "_CS_POSIX_V6_ILP32_OFF32_CFLAGS",
-    header: "<unistd.h>".}: cint
-  CS_POSIX_V6_ILP32_OFF32_LDFLAGS* {.
-    importc: "_CS_POSIX_V6_ILP32_OFF32_LDFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_ILP32_OFF32_LIBS* {.importc: "_CS_POSIX_V6_ILP32_OFF32_LIBS",
-    header: "<unistd.h>".}: cint
-  CS_POSIX_V6_ILP32_OFFBIG_CFLAGS* {.
-    importc: "_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS* {.
-    importc: "_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_ILP32_OFFBIG_LIBS* {.
-    importc: "_CS_POSIX_V6_ILP32_OFFBIG_LIBS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_LP64_OFF64_CFLAGS* {.
-    importc: "_CS_POSIX_V6_LP64_OFF64_CFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_LP64_OFF64_LDFLAGS* {.
-    importc: "_CS_POSIX_V6_LP64_OFF64_LDFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_LP64_OFF64_LIBS* {.
-    importc: "_CS_POSIX_V6_LP64_OFF64_LIBS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS* {.
-    importc: "_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS* {.
-    importc: "_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_LPBIG_OFFBIG_LIBS* {.
-    importc: "_CS_POSIX_V6_LPBIG_OFFBIG_LIBS", header: "<unistd.h>".}: cint
-  CS_POSIX_V6_WIDTH_RESTRICTED_ENVS* {.
-    importc: "_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS", header: "<unistd.h>".}: cint
-  F_LOCK* {.importc: "F_LOCK", header: "<unistd.h>".}: cint
-  F_TEST* {.importc: "F_TEST", header: "<unistd.h>".}: cint
-  F_TLOCK* {.importc: "F_TLOCK", header: "<unistd.h>".}: cint
-  F_ULOCK* {.importc: "F_ULOCK", header: "<unistd.h>".}: cint
-  PC_2_SYMLINKS* {.importc: "_PC_2_SYMLINKS", header: "<unistd.h>".}: cint
-  PC_ALLOC_SIZE_MIN* {.importc: "_PC_ALLOC_SIZE_MIN",
-    header: "<unistd.h>".}: cint
-  PC_ASYNC_IO* {.importc: "_PC_ASYNC_IO", header: "<unistd.h>".}: cint
-  PC_CHOWN_RESTRICTED* {.importc: "_PC_CHOWN_RESTRICTED", 
-    header: "<unistd.h>".}: cint
-  PC_FILESIZEBITS* {.importc: "_PC_FILESIZEBITS", header: "<unistd.h>".}: cint
-  PC_LINK_MAX* {.importc: "_PC_LINK_MAX", header: "<unistd.h>".}: cint
-  PC_MAX_CANON* {.importc: "_PC_MAX_CANON", header: "<unistd.h>".}: cint
-
-  PC_MAX_INPUT*{.importc: "_PC_MAX_INPUT", header: "<unistd.h>".}: cint
-  PC_NAME_MAX*{.importc: "_PC_NAME_MAX", header: "<unistd.h>".}: cint
-  PC_NO_TRUNC*{.importc: "_PC_NO_TRUNC", header: "<unistd.h>".}: cint
-  PC_PATH_MAX*{.importc: "_PC_PATH_MAX", header: "<unistd.h>".}: cint
-  PC_PIPE_BUF*{.importc: "_PC_PIPE_BUF", header: "<unistd.h>".}: cint
-  PC_PRIO_IO*{.importc: "_PC_PRIO_IO", header: "<unistd.h>".}: cint
-  PC_REC_INCR_XFER_SIZE*{.importc: "_PC_REC_INCR_XFER_SIZE", 
-    header: "<unistd.h>".}: cint
-  PC_REC_MIN_XFER_SIZE*{.importc: "_PC_REC_MIN_XFER_SIZE", 
-    header: "<unistd.h>".}: cint
-  PC_REC_XFER_ALIGN*{.importc: "_PC_REC_XFER_ALIGN", header: "<unistd.h>".}: cint
-  PC_SYMLINK_MAX*{.importc: "_PC_SYMLINK_MAX", header: "<unistd.h>".}: cint
-  PC_SYNC_IO*{.importc: "_PC_SYNC_IO", header: "<unistd.h>".}: cint
-  PC_VDISABLE*{.importc: "_PC_VDISABLE", header: "<unistd.h>".}: cint
-  SC_2_C_BIND*{.importc: "_SC_2_C_BIND", header: "<unistd.h>".}: cint
-  SC_2_C_DEV*{.importc: "_SC_2_C_DEV", header: "<unistd.h>".}: cint
-  SC_2_CHAR_TERM*{.importc: "_SC_2_CHAR_TERM", header: "<unistd.h>".}: cint
-  SC_2_FORT_DEV*{.importc: "_SC_2_FORT_DEV", header: "<unistd.h>".}: cint
-  SC_2_FORT_RUN*{.importc: "_SC_2_FORT_RUN", header: "<unistd.h>".}: cint
-  SC_2_LOCALEDEF*{.importc: "_SC_2_LOCALEDEF", header: "<unistd.h>".}: cint
-  SC_2_PBS*{.importc: "_SC_2_PBS", header: "<unistd.h>".}: cint
-  SC_2_PBS_ACCOUNTING*{.importc: "_SC_2_PBS_ACCOUNTING", 
-    header: "<unistd.h>".}: cint
-  SC_2_PBS_CHECKPOINT*{.importc: "_SC_2_PBS_CHECKPOINT", 
-    header: "<unistd.h>".}: cint
-  SC_2_PBS_LOCATE*{.importc: "_SC_2_PBS_LOCATE", header: "<unistd.h>".}: cint
-  SC_2_PBS_MESSAGE*{.importc: "_SC_2_PBS_MESSAGE", header: "<unistd.h>".}: cint
-  SC_2_PBS_TRACK*{.importc: "_SC_2_PBS_TRACK", header: "<unistd.h>".}: cint
-  SC_2_SW_DEV*{.importc: "_SC_2_SW_DEV", header: "<unistd.h>".}: cint
-  SC_2_UPE*{.importc: "_SC_2_UPE", header: "<unistd.h>".}: cint
-  SC_2_VERSION*{.importc: "_SC_2_VERSION", header: "<unistd.h>".}: cint
-  SC_ADVISORY_INFO*{.importc: "_SC_ADVISORY_INFO", header: "<unistd.h>".}: cint
-  SC_AIO_LISTIO_MAX*{.importc: "_SC_AIO_LISTIO_MAX", header: "<unistd.h>".}: cint
-  SC_AIO_MAX*{.importc: "_SC_AIO_MAX", header: "<unistd.h>".}: cint
-  SC_AIO_PRIO_DELTA_MAX*{.importc: "_SC_AIO_PRIO_DELTA_MAX", 
-    header: "<unistd.h>".}: cint
-  SC_ARG_MAX*{.importc: "_SC_ARG_MAX", header: "<unistd.h>".}: cint
-  SC_ASYNCHRONOUS_IO*{.importc: "_SC_ASYNCHRONOUS_IO", 
-    header: "<unistd.h>".}: cint
-  SC_ATEXIT_MAX*{.importc: "_SC_ATEXIT_MAX", header: "<unistd.h>".}: cint
-  SC_BARRIERS*{.importc: "_SC_BARRIERS", header: "<unistd.h>".}: cint
-  SC_BC_BASE_MAX*{.importc: "_SC_BC_BASE_MAX", header: "<unistd.h>".}: cint
-  SC_BC_DIM_MAX*{.importc: "_SC_BC_DIM_MAX", header: "<unistd.h>".}: cint
-  SC_BC_SCALE_MAX*{.importc: "_SC_BC_SCALE_MAX", header: "<unistd.h>".}: cint
-  SC_BC_STRING_MAX*{.importc: "_SC_BC_STRING_MAX", header: "<unistd.h>".}: cint
-  SC_CHILD_MAX*{.importc: "_SC_CHILD_MAX", header: "<unistd.h>".}: cint
-  SC_CLK_TCK*{.importc: "_SC_CLK_TCK", header: "<unistd.h>".}: cint
-  SC_CLOCK_SELECTION*{.importc: "_SC_CLOCK_SELECTION", 
-    header: "<unistd.h>".}: cint
-  SC_COLL_WEIGHTS_MAX*{.importc: "_SC_COLL_WEIGHTS_MAX", 
-    header: "<unistd.h>".}: cint
-  SC_CPUTIME*{.importc: "_SC_CPUTIME", header: "<unistd.h>".}: cint
-  SC_DELAYTIMER_MAX*{.importc: "_SC_DELAYTIMER_MAX", header: "<unistd.h>".}: cint
-  SC_EXPR_NEST_MAX*{.importc: "_SC_EXPR_NEST_MAX", header: "<unistd.h>".}: cint
-  SC_FSYNC*{.importc: "_SC_FSYNC", header: "<unistd.h>".}: cint
-  SC_GETGR_R_SIZE_MAX*{.importc: "_SC_GETGR_R_SIZE_MAX", 
-    header: "<unistd.h>".}: cint
-  SC_GETPW_R_SIZE_MAX*{.importc: "_SC_GETPW_R_SIZE_MAX", 
-    header: "<unistd.h>".}: cint
-  SC_HOST_NAME_MAX*{.importc: "_SC_HOST_NAME_MAX", header: "<unistd.h>".}: cint
-  SC_IOV_MAX*{.importc: "_SC_IOV_MAX", header: "<unistd.h>".}: cint
-  SC_IPV6*{.importc: "_SC_IPV6", header: "<unistd.h>".}: cint
-  SC_JOB_CONTROL*{.importc: "_SC_JOB_CONTROL", header: "<unistd.h>".}: cint
-  SC_LINE_MAX*{.importc: "_SC_LINE_MAX", header: "<unistd.h>".}: cint
-  SC_LOGIN_NAME_MAX*{.importc: "_SC_LOGIN_NAME_MAX", header: "<unistd.h>".}: cint
-  SC_MAPPED_FILES*{.importc: "_SC_MAPPED_FILES", header: "<unistd.h>".}: cint
-  SC_MEMLOCK*{.importc: "_SC_MEMLOCK", header: "<unistd.h>".}: cint
-  SC_MEMLOCK_RANGE*{.importc: "_SC_MEMLOCK_RANGE", header: "<unistd.h>".}: cint
-  SC_MEMORY_PROTECTION*{.importc: "_SC_MEMORY_PROTECTION", 
-    header: "<unistd.h>".}: cint
-  SC_MESSAGE_PASSING*{.importc: "_SC_MESSAGE_PASSING", 
-    header: "<unistd.h>".}: cint
-  SC_MONOTONIC_CLOCK*{.importc: "_SC_MONOTONIC_CLOCK", 
-    header: "<unistd.h>".}: cint
-  SC_MQ_OPEN_MAX*{.importc: "_SC_MQ_OPEN_MAX", header: "<unistd.h>".}: cint
-  SC_MQ_PRIO_MAX*{.importc: "_SC_MQ_PRIO_MAX", header: "<unistd.h>".}: cint
-  SC_NGROUPS_MAX*{.importc: "_SC_NGROUPS_MAX", header: "<unistd.h>".}: cint
-  SC_OPEN_MAX*{.importc: "_SC_OPEN_MAX", header: "<unistd.h>".}: cint
-  SC_PAGE_SIZE*{.importc: "_SC_PAGE_SIZE", header: "<unistd.h>".}: cint
-  SC_PRIORITIZED_IO*{.importc: "_SC_PRIORITIZED_IO", header: "<unistd.h>".}: cint
-  SC_PRIORITY_SCHEDULING*{.importc: "_SC_PRIORITY_SCHEDULING", 
-    header: "<unistd.h>".}: cint
-  SC_RAW_SOCKETS*{.importc: "_SC_RAW_SOCKETS", header: "<unistd.h>".}: cint
-  SC_RE_DUP_MAX*{.importc: "_SC_RE_DUP_MAX", header: "<unistd.h>".}: cint
-  SC_READER_WRITER_LOCKS*{.importc: "_SC_READER_WRITER_LOCKS", 
-    header: "<unistd.h>".}: cint
-  SC_REALTIME_SIGNALS*{.importc: "_SC_REALTIME_SIGNALS", 
-    header: "<unistd.h>".}: cint
-  SC_REGEXP*{.importc: "_SC_REGEXP", header: "<unistd.h>".}: cint
-  SC_RTSIG_MAX*{.importc: "_SC_RTSIG_MAX", header: "<unistd.h>".}: cint
-  SC_SAVED_IDS*{.importc: "_SC_SAVED_IDS", header: "<unistd.h>".}: cint
-  SC_SEM_NSEMS_MAX*{.importc: "_SC_SEM_NSEMS_MAX", header: "<unistd.h>".}: cint
-  SC_SEM_VALUE_MAX*{.importc: "_SC_SEM_VALUE_MAX", header: "<unistd.h>".}: cint
-  SC_SEMAPHORES*{.importc: "_SC_SEMAPHORES", header: "<unistd.h>".}: cint
-  SC_SHARED_MEMORY_OBJECTS*{.importc: "_SC_SHARED_MEMORY_OBJECTS", 
-    header: "<unistd.h>".}: cint
-  SC_SHELL*{.importc: "_SC_SHELL", header: "<unistd.h>".}: cint
-  SC_SIGQUEUE_MAX*{.importc: "_SC_SIGQUEUE_MAX", header: "<unistd.h>".}: cint
-  SC_SPAWN*{.importc: "_SC_SPAWN", header: "<unistd.h>".}: cint
-  SC_SPIN_LOCKS*{.importc: "_SC_SPIN_LOCKS", header: "<unistd.h>".}: cint
-  SC_SPORADIC_SERVER*{.importc: "_SC_SPORADIC_SERVER", 
-    header: "<unistd.h>".}: cint
-  SC_SS_REPL_MAX*{.importc: "_SC_SS_REPL_MAX", header: "<unistd.h>".}: cint
-  SC_STREAM_MAX*{.importc: "_SC_STREAM_MAX", header: "<unistd.h>".}: cint
-  SC_SYMLOOP_MAX*{.importc: "_SC_SYMLOOP_MAX", header: "<unistd.h>".}: cint
-  SC_SYNCHRONIZED_IO*{.importc: "_SC_SYNCHRONIZED_IO", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_ATTR_STACKADDR*{.importc: "_SC_THREAD_ATTR_STACKADDR", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_ATTR_STACKSIZE*{.importc: "_SC_THREAD_ATTR_STACKSIZE", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_CPUTIME*{.importc: "_SC_THREAD_CPUTIME", header: "<unistd.h>".}: cint
-  SC_THREAD_DESTRUCTOR_ITERATIONS*{.importc: "_SC_THREAD_DESTRUCTOR_ITERATIONS",
-    header: "<unistd.h>".}: cint
-  SC_THREAD_KEYS_MAX*{.importc: "_SC_THREAD_KEYS_MAX", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_PRIO_INHERIT*{.importc: "_SC_THREAD_PRIO_INHERIT", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_PRIO_PROTECT*{.importc: "_SC_THREAD_PRIO_PROTECT", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_PRIORITY_SCHEDULING*{.importc: "_SC_THREAD_PRIORITY_SCHEDULING",
-    header: "<unistd.h>".}: cint
-  SC_THREAD_PROCESS_SHARED*{.importc: "_SC_THREAD_PROCESS_SHARED", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_SAFE_FUNCTIONS*{.importc: "_SC_THREAD_SAFE_FUNCTIONS", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_SPORADIC_SERVER*{.importc: "_SC_THREAD_SPORADIC_SERVER", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_STACK_MIN*{.importc: "_SC_THREAD_STACK_MIN", 
-    header: "<unistd.h>".}: cint
-  SC_THREAD_THREADS_MAX*{.importc: "_SC_THREAD_THREADS_MAX", 
-    header: "<unistd.h>".}: cint
-  SC_THREADS*{.importc: "_SC_THREADS", header: "<unistd.h>".}: cint
-  SC_TIMEOUTS*{.importc: "_SC_TIMEOUTS", header: "<unistd.h>".}: cint
-  SC_TIMER_MAX*{.importc: "_SC_TIMER_MAX", header: "<unistd.h>".}: cint
-  SC_TIMERS*{.importc: "_SC_TIMERS", header: "<unistd.h>".}: cint
-  SC_TRACE*{.importc: "_SC_TRACE", header: "<unistd.h>".}: cint
-  SC_TRACE_EVENT_FILTER*{.importc: "_SC_TRACE_EVENT_FILTER", header: "<unistd.h>".}: cint
-  SC_TRACE_EVENT_NAME_MAX*{.importc: "_SC_TRACE_EVENT_NAME_MAX", header: "<unistd.h>".}: cint
-  SC_TRACE_INHERIT*{.importc: "_SC_TRACE_INHERIT", header: "<unistd.h>".}: cint
-  SC_TRACE_LOG*{.importc: "_SC_TRACE_LOG", header: "<unistd.h>".}: cint
-  SC_TRACE_NAME_MAX*{.importc: "_SC_TRACE_NAME_MAX", header: "<unistd.h>".}: cint
-  SC_TRACE_SYS_MAX*{.importc: "_SC_TRACE_SYS_MAX", header: "<unistd.h>".}: cint
-  SC_TRACE_USER_EVENT_MAX*{.importc: "_SC_TRACE_USER_EVENT_MAX", header: "<unistd.h>".}: cint
-  SC_TTY_NAME_MAX*{.importc: "_SC_TTY_NAME_MAX", header: "<unistd.h>".}: cint
-  SC_TYPED_MEMORY_OBJECTS*{.importc: "_SC_TYPED_MEMORY_OBJECTS", header: "<unistd.h>".}: cint
-  SC_TZNAME_MAX*{.importc: "_SC_TZNAME_MAX", header: "<unistd.h>".}: cint
-  SC_V6_ILP32_OFF32*{.importc: "_SC_V6_ILP32_OFF32", header: "<unistd.h>".}: cint
-  SC_V6_ILP32_OFFBIG*{.importc: "_SC_V6_ILP32_OFFBIG", header: "<unistd.h>".}: cint
-  SC_V6_LP64_OFF64*{.importc: "_SC_V6_LP64_OFF64", header: "<unistd.h>".}: cint
-  SC_V6_LPBIG_OFFBIG*{.importc: "_SC_V6_LPBIG_OFFBIG", header: "<unistd.h>".}: cint
-  SC_VERSION*{.importc: "_SC_VERSION", header: "<unistd.h>".}: cint
-  SC_XBS5_ILP32_OFF32*{.importc: "_SC_XBS5_ILP32_OFF32", header: "<unistd.h>".}: cint
-  SC_XBS5_ILP32_OFFBIG*{.importc: "_SC_XBS5_ILP32_OFFBIG", header: "<unistd.h>".}: cint
-  SC_XBS5_LP64_OFF64*{.importc: "_SC_XBS5_LP64_OFF64", header: "<unistd.h>".}: cint
-  SC_XBS5_LPBIG_OFFBIG*{.importc: "_SC_XBS5_LPBIG_OFFBIG", 
-                         header: "<unistd.h>".}: cint
-  SC_XOPEN_CRYPT*{.importc: "_SC_XOPEN_CRYPT", header: "<unistd.h>".}: cint
-  SC_XOPEN_ENH_I18N*{.importc: "_SC_XOPEN_ENH_I18N", header: "<unistd.h>".}: cint
-  SC_XOPEN_LEGACY*{.importc: "_SC_XOPEN_LEGACY", header: "<unistd.h>".}: cint
-  SC_XOPEN_REALTIME*{.importc: "_SC_XOPEN_REALTIME", header: "<unistd.h>".}: cint
-  SC_XOPEN_REALTIME_THREADS*{.importc: "_SC_XOPEN_REALTIME_THREADS", 
-                              header: "<unistd.h>".}: cint
-  SC_XOPEN_SHM*{.importc: "_SC_XOPEN_SHM", header: "<unistd.h>".}: cint
-  SC_XOPEN_STREAMS*{.importc: "_SC_XOPEN_STREAMS", header: "<unistd.h>".}: cint
-  SC_XOPEN_UNIX*{.importc: "_SC_XOPEN_UNIX", header: "<unistd.h>".}: cint
-  SC_XOPEN_VERSION*{.importc: "_SC_XOPEN_VERSION", header: "<unistd.h>".}: cint
-  SC_NPROCESSORS_ONLN*{.importc: "_SC_NPROCESSORS_ONLN", 
-                        header: "<unistd.h>".}: cint
-  
-  SEM_FAILED* {.importc, header: "<semaphore.h>".}: pointer
-  IPC_CREAT* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Create entry if key does not exist.
-  IPC_EXCL* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Fail if key exists.
-  IPC_NOWAIT* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Error if request must wait.
-
-  IPC_PRIVATE* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Private key.
-
-  IPC_RMID* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Remove identifier.
-  IPC_SET* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Set options.
-  IPC_STAT* {.importc, header: "<sys/ipc.h>".}: cint
-    ## Get options. 
-
-  S_IFMT* {.importc, header: "<sys/stat.h>".}: cint
-    ## Type of file.
-  S_IFBLK* {.importc, header: "<sys/stat.h>".}: cint
-    ## Block special.
-  S_IFCHR* {.importc, header: "<sys/stat.h>".}: cint
-    ## Character special.
-  S_IFIFO* {.importc, header: "<sys/stat.h>".}: cint
-    ## FIFO special.
-  S_IFREG* {.importc, header: "<sys/stat.h>".}: cint
-    ## Regular.
-  S_IFDIR* {.importc, header: "<sys/stat.h>".}: cint
-    ## Directory.
-  S_IFLNK* {.importc, header: "<sys/stat.h>".}: cint
-    ## Symbolic link.
-  S_IFSOCK* {.importc, header: "<sys/stat.h>".}: cint
-    ## Socket.
-  S_IRWXU* {.importc, header: "<sys/stat.h>".}: cint
-    ## Read, write, execute/search by owner.
-  S_IRUSR* {.importc, header: "<sys/stat.h>".}: cint
-    ## Read permission, owner.
-  S_IWUSR* {.importc, header: "<sys/stat.h>".}: cint
-    ## Write permission, owner.
-  S_IXUSR* {.importc, header: "<sys/stat.h>".}: cint
-    ## Execute/search permission, owner.
-  S_IRWXG* {.importc, header: "<sys/stat.h>".}: cint
-    ## Read, write, execute/search by group.
-  S_IRGRP* {.importc, header: "<sys/stat.h>".}: cint
-    ## Read permission, group.
-  S_IWGRP* {.importc, header: "<sys/stat.h>".}: cint
-    ## Write permission, group.
-  S_IXGRP* {.importc, header: "<sys/stat.h>".}: cint
-    ## Execute/search permission, group.
-  S_IRWXO* {.importc, header: "<sys/stat.h>".}: cint
-    ## Read, write, execute/search by others.
-  S_IROTH* {.importc, header: "<sys/stat.h>".}: cint
-    ## Read permission, others.
-  S_IWOTH* {.importc, header: "<sys/stat.h>".}: cint
-    ## Write permission, others.
-  S_IXOTH* {.importc, header: "<sys/stat.h>".}: cint
-    ## Execute/search permission, others.
-  S_ISUID* {.importc, header: "<sys/stat.h>".}: cint
-    ## Set-user-ID on execution.
-  S_ISGID* {.importc, header: "<sys/stat.h>".}: cint
-    ## Set-group-ID on execution.
-  S_ISVTX* {.importc, header: "<sys/stat.h>".}: cint
-    ## On directories, restricted deletion flag.
-  
-  ST_RDONLY* {.importc, header: "<sys/statvfs.h>".}: cint
-    ## Read-only file system.
-  ST_NOSUID* {.importc, header: "<sys/statvfs.h>".}: cint
-    ## Does not support the semantics of the ST_ISUID and ST_ISGID file mode bits.
-       
-  PROT_READ* {.importc, header: "<sys/mman.h>".}: cint
-    ## Page can be read.
-  PROT_WRITE* {.importc, header: "<sys/mman.h>".}: cint
-    ## Page can be written.
-  PROT_EXEC* {.importc, header: "<sys/mman.h>".}: cint
-    ## Page can be executed.
-  PROT_NONE* {.importc, header: "<sys/mman.h>".}: cint
-    ## Page cannot be accessed.
-  MAP_SHARED* {.importc, header: "<sys/mman.h>".}: cint
-    ## Share changes.
-  MAP_PRIVATE* {.importc, header: "<sys/mman.h>".}: cint
-    ## Changes are private.
-  MAP_FIXED* {.importc, header: "<sys/mman.h>".}: cint
-    ## Interpret addr exactly.
-  MS_ASYNC* {.importc, header: "<sys/mman.h>".}: cint
-    ## Perform asynchronous writes.
-  MS_SYNC* {.importc, header: "<sys/mman.h>".}: cint
-    ## Perform synchronous writes.
-  MS_INVALIDATE* {.importc, header: "<sys/mman.h>".}: cint
-    ## Invalidate mappings.
-  MCL_CURRENT* {.importc, header: "<sys/mman.h>".}: cint
-    ## Lock currently mapped pages.
-  MCL_FUTURE* {.importc, header: "<sys/mman.h>".}: cint
-    ## Lock pages that become mapped.
-  MAP_FAILED* {.importc, header: "<sys/mman.h>".}: cint
-  POSIX_MADV_NORMAL* {.importc, header: "<sys/mman.h>".}: cint
-    ## The application has no advice to give on its behavior with 
-    ## respect to the specified range. It is the default characteristic 
-    ## if no advice is given for a range of memory.
-  POSIX_MADV_SEQUENTIAL* {.importc, header: "<sys/mman.h>".}: cint
-    ## The application expects to access the specified range sequentially
-    ## from lower addresses to higher addresses.
-  POSIX_MADV_RANDOM* {.importc, header: "<sys/mman.h>".}: cint
-    ## The application expects to access the specified range in a random order.
-  POSIX_MADV_WILLNEED* {.importc, header: "<sys/mman.h>".}: cint
-    ## The application expects to access the specified range in the near future.
-  POSIX_MADV_DONTNEED* {.importc, header: "<sys/mman.h>".}: cint
-  POSIX_TYPED_MEM_ALLOCATE* {.importc, header: "<sys/mman.h>".}: cint
-  POSIX_TYPED_MEM_ALLOCATE_CONTIG* {.importc, header: "<sys/mman.h>".}: cint
-  POSIX_TYPED_MEM_MAP_ALLOCATABLE* {.importc, header: "<sys/mman.h>".}: cint
-
-
-  CLOCKS_PER_SEC* {.importc, header: "<time.h>".}: int
-    ## A number used to convert the value returned by the clock() function
-    ## into seconds.
-  CLOCK_PROCESS_CPUTIME_ID* {.importc, header: "<time.h>".}: cint
-    ## The identifier of the CPU-time clock associated with the process 
-    ## making a clock() or timer*() function call.
-  CLOCK_THREAD_CPUTIME_ID* {.importc, header: "<time.h>".}: cint
-  CLOCK_REALTIME* {.importc, header: "<time.h>".}: cint
-    ## The identifier of the system-wide realtime clock.
-  TIMER_ABSTIME* {.importc, header: "<time.h>".}: cint
-    ## Flag indicating time is absolute. For functions taking timer 
-    ## objects, this refers to the clock associated with the timer.
-  CLOCK_MONOTONIC* {.importc, header: "<time.h>".}: cint
-
-  WNOHANG* {.importc, header: "<sys/wait.h>".}: cint
-    ## Do not hang if no status is available; return immediately.
-  WUNTRACED* {.importc, header: "<sys/wait.h>".}: cint
-    ## Report status of stopped child process.
-  WEXITSTATUS* {.importc, header: "<sys/wait.h>".}: cint
-    ## Return exit status.
-  WIFCONTINUED* {.importc, header: "<sys/wait.h>".}: cint
-    ## True if child has been continued.
-  WIFEXITED* {.importc, header: "<sys/wait.h>".}: cint
-    ## True if child exited normally.
-  WIFSIGNALED* {.importc, header: "<sys/wait.h>".}: cint
-    ## True if child exited due to uncaught signal.
-  WIFSTOPPED* {.importc, header: "<sys/wait.h>".}: cint
-    ## True if child is currently stopped.
-  WSTOPSIG* {.importc, header: "<sys/wait.h>".}: cint
-    ## Return signal number that caused process to stop.
-  WTERMSIG* {.importc, header: "<sys/wait.h>".}: cint
-    ## Return signal number that caused process to terminate.
-  WEXITED* {.importc, header: "<sys/wait.h>".}: cint
-    ## Wait for processes that have exited.
-  WSTOPPED* {.importc, header: "<sys/wait.h>".}: cint
-    ## Status is returned for any child that has stopped upon receipt 
-    ## of a signal.
-  WCONTINUED* {.importc, header: "<sys/wait.h>".}: cint
-    ## Status is returned for any child that was stopped and has been continued.
-  WNOWAIT* {.importc, header: "<sys/wait.h>".}: cint
-    ## Keep the process whose status is returned in infop in a waitable state. 
-  P_ALL* {.importc, header: "<sys/wait.h>".}: cint 
-  P_PID* {.importc, header: "<sys/wait.h>".}: cint 
-  P_PGID* {.importc, header: "<sys/wait.h>".}: cint
-       
-  SIG_DFL* {.importc, header: "<signal.h>".}: proc (x: cint) {.noconv.}
-    ## Request for default signal handling.
-  SIG_ERR* {.importc, header: "<signal.h>".}: proc (x: cint) {.noconv.}
-    ## Return value from signal() in case of error.
-  cSIG_HOLD* {.importc: "SIG_HOLD", 
-    header: "<signal.h>".}: proc (x: cint) {.noconv.}
-    ## Request that signal be held.
-  SIG_IGN* {.importc, header: "<signal.h>".}: proc (x: cint) {.noconv.}
-    ## Request that signal be ignored. 
-
-  SIGEV_NONE* {.importc, header: "<signal.h>".}: cint
-  SIGEV_SIGNAL* {.importc, header: "<signal.h>".}: cint
-  SIGEV_THREAD* {.importc, header: "<signal.h>".}: cint
-  SIGABRT* {.importc, header: "<signal.h>".}: cint
-  SIGALRM* {.importc, header: "<signal.h>".}: cint
-  SIGBUS* {.importc, header: "<signal.h>".}: cint
-  SIGCHLD* {.importc, header: "<signal.h>".}: cint
-  SIGCONT* {.importc, header: "<signal.h>".}: cint
-  SIGFPE* {.importc, header: "<signal.h>".}: cint
-  SIGHUP* {.importc, header: "<signal.h>".}: cint
-  SIGILL* {.importc, header: "<signal.h>".}: cint
-  SIGINT* {.importc, header: "<signal.h>".}: cint
-  SIGKILL* {.importc, header: "<signal.h>".}: cint
-  SIGPIPE* {.importc, header: "<signal.h>".}: cint
-  SIGQUIT* {.importc, header: "<signal.h>".}: cint
-  SIGSEGV* {.importc, header: "<signal.h>".}: cint
-  SIGSTOP* {.importc, header: "<signal.h>".}: cint
-  SIGTERM* {.importc, header: "<signal.h>".}: cint
-  SIGTSTP* {.importc, header: "<signal.h>".}: cint
-  SIGTTIN* {.importc, header: "<signal.h>".}: cint
-  SIGTTOU* {.importc, header: "<signal.h>".}: cint
-  SIGUSR1* {.importc, header: "<signal.h>".}: cint
-  SIGUSR2* {.importc, header: "<signal.h>".}: cint
-  SIGPOLL* {.importc, header: "<signal.h>".}: cint
-  SIGPROF* {.importc, header: "<signal.h>".}: cint
-  SIGSYS* {.importc, header: "<signal.h>".}: cint
-  SIGTRAP* {.importc, header: "<signal.h>".}: cint
-  SIGURG* {.importc, header: "<signal.h>".}: cint
-  SIGVTALRM* {.importc, header: "<signal.h>".}: cint
-  SIGXCPU* {.importc, header: "<signal.h>".}: cint
-  SIGXFSZ* {.importc, header: "<signal.h>".}: cint
-  SA_NOCLDSTOP* {.importc, header: "<signal.h>".}: cint
-  SIG_BLOCK* {.importc, header: "<signal.h>".}: cint
-  SIG_UNBLOCK* {.importc, header: "<signal.h>".}: cint
-  SIG_SETMASK* {.importc, header: "<signal.h>".}: cint
-  SA_ONSTACK* {.importc, header: "<signal.h>".}: cint
-  SA_RESETHAND* {.importc, header: "<signal.h>".}: cint
-  SA_RESTART* {.importc, header: "<signal.h>".}: cint
-  SA_SIGINFO* {.importc, header: "<signal.h>".}: cint
-  SA_NOCLDWAIT* {.importc, header: "<signal.h>".}: cint
-  SA_NODEFER* {.importc, header: "<signal.h>".}: cint
-  SS_ONSTACK* {.importc, header: "<signal.h>".}: cint
-  SS_DISABLE* {.importc, header: "<signal.h>".}: cint
-  MINSIGSTKSZ* {.importc, header: "<signal.h>".}: cint
-  SIGSTKSZ* {.importc, header: "<signal.h>".}: cint
-
-  NL_SETD* {.importc, header: "<nl_types.h>".}: cint
-  NL_CAT_LOCALE* {.importc, header: "<nl_types.h>".}: cint
-
-  SCHED_FIFO* {.importc, header: "<sched.h>".}: cint
-  SCHED_RR* {.importc, header: "<sched.h>".}: cint
-  SCHED_SPORADIC* {.importc, header: "<sched.h>".}: cint
-  SCHED_OTHER* {.importc, header: "<sched.h>".}: cint
-  FD_SETSIZE* {.importc, header: "<sys/select.h>".}: cint
-
-  SEEK_SET* {.importc, header: "<unistd.h>".}: cint
-  SEEK_CUR* {.importc, header: "<unistd.h>".}: cint
-  SEEK_END* {.importc, header: "<unistd.h>".}: cint
-
-  SCM_RIGHTS* {.importc, header: "<sys/socket.h>".}: cint
-    ## Indicates that the data array contains the access rights 
-    ## to be sent or received. 
-
-  SOCK_DGRAM* {.importc, header: "<sys/socket.h>".}: cint ## Datagram socket.
-  SOCK_RAW* {.importc, header: "<sys/socket.h>".}: cint
-    ## Raw Protocol Interface.
-  SOCK_SEQPACKET* {.importc, header: "<sys/socket.h>".}: cint
-    ## Sequenced-packet socket.
-  SOCK_STREAM* {.importc, header: "<sys/socket.h>".}: cint
-    ## Byte-stream socket. 
-    
-  SOL_SOCKET* {.importc, header: "<sys/socket.h>".}: cint
-    ## Options to be accessed at socket level, not protocol level. 
-    
-  SO_ACCEPTCONN* {.importc, header: "<sys/socket.h>".}: cint
-    ## Socket is accepting connections.
-  SO_BROADCAST* {.importc, header: "<sys/socket.h>".}: cint
-    ## Transmission of broadcast messages is supported.
-  SO_DEBUG* {.importc, header: "<sys/socket.h>".}: cint
-    ## Debugging information is being recorded.
-  SO_DONTROUTE* {.importc, header: "<sys/socket.h>".}: cint
-    ## Bypass normal routing.
-  SO_ERROR* {.importc, header: "<sys/socket.h>".}: cint
-    ## Socket error status.
-  SO_KEEPALIVE* {.importc, header: "<sys/socket.h>".}: cint
-    ## Connections are kept alive with periodic messages.
-  SO_LINGER* {.importc, header: "<sys/socket.h>".}: cint
-    ## Socket lingers on close.
-  SO_OOBINLINE* {.importc, header: "<sys/socket.h>".}: cint
-    ## Out-of-band data is transmitted in line.
-  SO_RCVBUF* {.importc, header: "<sys/socket.h>".}: cint
-    ## Receive buffer size.
-  SO_RCVLOWAT* {.importc, header: "<sys/socket.h>".}: cint
-    ## Receive *low water mark*.
-  SO_RCVTIMEO* {.importc, header: "<sys/socket.h>".}: cint
-    ## Receive timeout.
-  SO_REUSEADDR* {.importc, header: "<sys/socket.h>".}: cint
-    ## Reuse of local addresses is supported.
-  SO_SNDBUF* {.importc, header: "<sys/socket.h>".}: cint
-    ## Send buffer size.
-  SO_SNDLOWAT* {.importc, header: "<sys/socket.h>".}: cint
-    ## Send *low water mark*.
-  SO_SNDTIMEO* {.importc, header: "<sys/socket.h>".}: cint
-    ## Send timeout.
-  SO_TYPE* {.importc, header: "<sys/socket.h>".}: cint
-    ## Socket type. 
-      
-  SOMAXCONN* {.importc, header: "<sys/socket.h>".}: cint
-    ## The maximum backlog queue length. 
-    
-  MSG_CTRUNC* {.importc, header: "<sys/socket.h>".}: cint
-    ## Control data truncated.
-  MSG_DONTROUTE* {.importc, header: "<sys/socket.h>".}: cint
-    ## Send without using routing tables.
-  MSG_EOR* {.importc, header: "<sys/socket.h>".}: cint
-    ## Terminates a record (if supported by the protocol).
-  MSG_OOB* {.importc, header: "<sys/socket.h>".}: cint
-    ## Out-of-band data.
-  MSG_PEEK* {.importc, header: "<sys/socket.h>".}: cint
-    ## Leave received data in queue.
-  MSG_TRUNC* {.importc, header: "<sys/socket.h>".}: cint
-    ## Normal data truncated.
-  MSG_WAITALL* {.importc, header: "<sys/socket.h>".}: cint
-    ## Attempt to fill the read buffer. 
-
-  AF_INET* {.importc, header: "<sys/socket.h>".}: cint
-    ## Internet domain sockets for use with IPv4 addresses.
-  AF_INET6* {.importc, header: "<sys/socket.h>".}: cint
-    ## Internet domain sockets for use with IPv6 addresses.
-  AF_UNIX* {.importc, header: "<sys/socket.h>".}: cint
-    ## UNIX domain sockets.
-  AF_UNSPEC* {.importc, header: "<sys/socket.h>".}: cint
-    ## Unspecified. 
-
-  SHUT_RD* {.importc, header: "<sys/socket.h>".}: cint
-    ## Disables further receive operations.
-  SHUT_RDWR* {.importc, header: "<sys/socket.h>".}: cint
-    ## Disables further send and receive operations.
-  SHUT_WR* {.importc, header: "<sys/socket.h>".}: cint
-    ## Disables further send operations. 
-
-  IF_NAMESIZE* {.importc, header: "<net/if.h>".}: cint
-    
-  IPPROTO_IP* {.importc, header: "<netinet/in.h>".}: cint
-    ## Internet protocol.
-  IPPROTO_IPV6* {.importc, header: "<netinet/in.h>".}: cint
-    ## Internet Protocol Version 6.
-  IPPROTO_ICMP* {.importc, header: "<netinet/in.h>".}: cint
-    ## Control message protocol.
-  IPPROTO_RAW* {.importc, header: "<netinet/in.h>".}: cint
-    ## Raw IP Packets Protocol. 
-  IPPROTO_TCP* {.importc, header: "<netinet/in.h>".}: cint
-    ## Transmission control protocol.
-  IPPROTO_UDP* {.importc, header: "<netinet/in.h>".}: cint
-    ## User datagram protocol.
-
-  INADDR_ANY* {.importc, header: "<netinet/in.h>".}: TinAddrScalar
-    ## IPv4 local host address.
-  INADDR_BROADCAST* {.importc, header: "<netinet/in.h>".}: TinAddrScalar
-    ## IPv4 broadcast address.
-
-  INET_ADDRSTRLEN* {.importc, header: "<netinet/in.h>".}: cint
-    ## 16. Length of the string form for IP. 
-
-  IPV6_JOIN_GROUP* {.importc, header: "<netinet/in.h>".}: cint
-    ## Join a multicast group.
-  IPV6_LEAVE_GROUP* {.importc, header: "<netinet/in.h>".}: cint
-    ## Quit a multicast group.
-  IPV6_MULTICAST_HOPS* {.importc, header: "<netinet/in.h>".}: cint
-    ## Multicast hop limit.
-  IPV6_MULTICAST_IF* {.importc, header: "<netinet/in.h>".}: cint
-    ## Interface to use for outgoing multicast packets.
-  IPV6_MULTICAST_LOOP* {.importc, header: "<netinet/in.h>".}: cint
-    ## Multicast packets are delivered back to the local application.
-  IPV6_UNICAST_HOPS* {.importc, header: "<netinet/in.h>".}: cint
-    ## Unicast hop limit.
-  IPV6_V6ONLY* {.importc, header: "<netinet/in.h>".}: cint
-    ## Restrict AF_INET6 socket to IPv6 communications only.
-
-  TCP_NODELAY* {.importc, header: "<netinet/tcp.h>".}: cint
-    ## Avoid coalescing of small segments. 
-
-  IPPORT_RESERVED* {.importc, header: "<netdb.h>".}: cint 
-
-  HOST_NOT_FOUND* {.importc, header: "<netdb.h>".}: cint 
-  NO_DATA* {.importc, header: "<netdb.h>".}: cint 
-  NO_RECOVERY* {.importc, header: "<netdb.h>".}: cint 
-  TRY_AGAIN* {.importc, header: "<netdb.h>".}: cint 
-
-  AI_PASSIVE* {.importc, header: "<netdb.h>".}: cint 
-    ## Socket address is intended for bind().
-  AI_CANONNAME* {.importc, header: "<netdb.h>".}: cint 
-    ## Request for canonical name.
-  AI_NUMERICHOST* {.importc, header: "<netdb.h>".}: cint 
-    ## Return numeric host address as name.
-  AI_NUMERICSERV* {.importc, header: "<netdb.h>".}: cint 
-    ## Inhibit service name resolution.
-  AI_V4MAPPED* {.importc, header: "<netdb.h>".}: cint 
-     ## If no IPv6 addresses are found, query for IPv4 addresses and
-     ## return them to the caller as IPv4-mapped IPv6 addresses.
-  AI_ALL* {.importc, header: "<netdb.h>".}: cint 
-    ## Query for both IPv4 and IPv6 addresses.
-  AI_ADDRCONFIG* {.importc, header: "<netdb.h>".}: cint 
-    ## Query for IPv4 addresses only when an IPv4 address is configured; 
-    ## query for IPv6 addresses only when an IPv6 address is configured.
-
-  NI_NOFQDN* {.importc, header: "<netdb.h>".}: cint 
-    ## Only the nodename portion of the FQDN is returned for local hosts.
-  NI_NUMERICHOST* {.importc, header: "<netdb.h>".}: cint 
-    ## The numeric form of the node's address is returned instead of its name.
-  NI_NAMEREQD* {.importc, header: "<netdb.h>".}: cint 
-    ## Return an error if the node's name cannot be located in the database.
-  NI_NUMERICSERV* {.importc, header: "<netdb.h>".}: cint 
-    ## The numeric form of the service address is returned instead of its name.
-  NI_NUMERICSCOPE* {.importc, header: "<netdb.h>".}: cint 
-    ## For IPv6 addresses, the numeric form of the scope identifier is
-    ## returned instead of its name.
-  NI_DGRAM* {.importc, header: "<netdb.h>".}: cint 
-    ## Indicates that the service is a datagram service (SOCK_DGRAM). 
-
-  EAI_AGAIN* {.importc, header: "<netdb.h>".}: cint 
-    ## The name could not be resolved at this time. Future attempts may succeed.
-  EAI_BADFLAGS* {.importc, header: "<netdb.h>".}: cint 
-    ## The flags had an invalid value.
-  EAI_FAIL* {.importc, header: "<netdb.h>".}: cint 
-    ## A non-recoverable error occurred.
-  EAI_FAMILY* {.importc, header: "<netdb.h>".}: cint 
-    ## The address family was not recognized or the address length 
-    ## was invalid for the specified family.
-  EAI_MEMORY* {.importc, header: "<netdb.h>".}: cint 
-    ## There was a memory allocation failure.
-  EAI_NONAME* {.importc, header: "<netdb.h>".}: cint 
-    ## The name does not resolve for the supplied parameters.
-    ## NI_NAMEREQD is set and the host's name cannot be located, 
-    ## or both nodename and servname were null.
-  EAI_SERVICE* {.importc, header: "<netdb.h>".}: cint 
-    ## The service passed was not recognized for the specified socket type.
-  EAI_SOCKTYPE* {.importc, header: "<netdb.h>".}: cint 
-    ## The intended socket type was not recognized.
-  EAI_SYSTEM* {.importc, header: "<netdb.h>".}: cint 
-    ## A system error occurred. The error code can be found in errno.
-  EAI_OVERFLOW* {.importc, header: "<netdb.h>".}: cint 
-    ## An argument buffer overflowed.
-
-  POLLIN* {.importc, header: "<poll.h>".}: cshort
-    ## Data other than high-priority data may be read without blocking.
-  POLLRDNORM* {.importc, header: "<poll.h>".}: cshort
-    ## Normal data may be read without blocking.
-  POLLRDBAND* {.importc, header: "<poll.h>".}: cshort
-    ## Priority data may be read without blocking.
-  POLLPRI* {.importc, header: "<poll.h>".}: cshort
-    ## High priority data may be read without blocking.
-  POLLOUT* {.importc, header: "<poll.h>".}: cshort
-    ## Normal data may be written without blocking.
-  POLLWRNORM* {.importc, header: "<poll.h>".}: cshort
-    ## Equivalent to POLLOUT.
-  POLLWRBAND* {.importc, header: "<poll.h>".}: cshort
-    ## Priority data may be written.
-  POLLERR* {.importc, header: "<poll.h>".}: cshort
-    ## An error has occurred (revents only).
-  POLLHUP* {.importc, header: "<poll.h>".}: cshort
-    ## Device has been disconnected (revents only).
-  POLLNVAL* {.importc, header: "<poll.h>".}: cshort
-    ## Invalid fd member (revents only). 
-
-
-when hasSpawnh:
-  var
-    POSIX_SPAWN_RESETIDS* {.importc, header: "<spawn.h>".}: cint
-    POSIX_SPAWN_SETPGROUP* {.importc, header: "<spawn.h>".}: cint
-    POSIX_SPAWN_SETSCHEDPARAM* {.importc, header: "<spawn.h>".}: cint
-    POSIX_SPAWN_SETSCHEDULER* {.importc, header: "<spawn.h>".}: cint
-    POSIX_SPAWN_SETSIGDEF* {.importc, header: "<spawn.h>".}: cint
-    POSIX_SPAWN_SETSIGMASK* {.importc, header: "<spawn.h>".}: cint
+  STDOUT_FILENO* = 1 ## File number of stdout;
+
+  DT_UNKNOWN* = 0 ## Unknown file type.
+  DT_FIFO* = 1    ## Named pipe, or FIFO.
+  DT_CHR* = 2     ## Character device.
+  DT_DIR* = 4     ## Directory.
+  DT_BLK* = 6     ## Block device.
+  DT_REG* = 8     ## Regular file.
+  DT_LNK* = 10    ## Symbolic link.
+  DT_SOCK* = 12   ## UNIX domain socket.
+  DT_WHT* = 14
+
+# Special types
+type Sighandler = proc (a: cint) {.noconv.}
+
+const StatHasNanoseconds* = defined(linux) or defined(freebsd) or
+    defined(osx) or defined(openbsd) or defined(dragonfly) or defined(haiku) ## \
+  ## Boolean flag that indicates if the system supports nanosecond time
+  ## resolution in the fields of `Stat`. Note that the nanosecond based fields
+  ## (`Stat.st_atim`, `Stat.st_mtim` and `Stat.st_ctim`) can be accessed
+  ## without checking this flag, because this module defines fallback procs
+  ## when they are not available.
+
+# Platform specific stuff
+
+when (defined(linux) and not defined(android)) and defined(amd64):
+  include posix_linux_amd64
+elif defined(openbsd) and defined(amd64):
+  include posix_openbsd_amd64
+elif (defined(macos) or defined(macosx) or defined(bsd)) and defined(cpu64):
+  include posix_macos_amd64
+elif defined(nintendoswitch):
+  include posix_nintendoswitch
+elif defined(haiku):
+  include posix_haiku
+else:
+  include posix_other
+
+# There used to be this name in posix.nim a long time ago, not sure why!
+
+when StatHasNanoseconds:
+  proc st_atime*(s: Stat): Time {.inline.} =
+    ## Second-granularity time of last access.
+    result = s.st_atim.tv_sec
+  proc st_mtime*(s: Stat): Time {.inline.} =
+    ## Second-granularity time of last data modification.
+    result = s.st_mtim.tv_sec
+  proc st_ctime*(s: Stat): Time {.inline.} =
+    ## Second-granularity time of last status change.
+    result = s.st_ctim.tv_sec
+else:
+  proc st_atim*(s: Stat): Timespec {.inline.} =
+    ## Nanosecond-granularity time of last access.
+    result.tv_sec = s.st_atime
+  proc st_mtim*(s: Stat): Timespec {.inline.} =
+    ## Nanosecond-granularity time of last data modification.
+    result.tv_sec = s.st_mtime
+  proc st_ctim*(s: Stat): Timespec {.inline.} =
+    ## Nanosecond-granularity time of last data modification.
+    result.tv_sec = s.st_ctime
 
 when hasAioH:
   proc aio_cancel*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
@@ -1721,326 +142,373 @@ when hasAioH:
   proc aio_fsync*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".}
   proc aio_read*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
   proc aio_return*(a1: ptr Taiocb): int {.importc, header: "<aio.h>".}
-  proc aio_suspend*(a1: ptr ptr Taiocb, a2: cint, a3: ptr ttimespec): cint {.
+  proc aio_suspend*(a1: ptr ptr Taiocb, a2: cint, a3: ptr Timespec): cint {.
                    importc, header: "<aio.h>".}
   proc aio_write*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".}
   proc lio_listio*(a1: cint, a2: ptr ptr Taiocb, a3: cint,
-               a4: ptr Tsigevent): cint {.importc, header: "<aio.h>".}
+               a4: ptr SigEvent): cint {.importc, header: "<aio.h>".}
 
 # arpa/inet.h
-proc htonl*(a1: int32): int32 {.importc, header: "<arpa/inet.h>".}
-proc htons*(a1: int16): int16 {.importc, header: "<arpa/inet.h>".}
-proc ntohl*(a1: int32): int32 {.importc, header: "<arpa/inet.h>".}
-proc ntohs*(a1: int16): int16 {.importc, header: "<arpa/inet.h>".}
-
-proc inet_addr*(a1: cstring): int32 {.importc, header: "<arpa/inet.h>".}
-proc inet_ntoa*(a1: int32): cstring {.importc, header: "<arpa/inet.h>".}
-proc inet_ntop*(a1: cint, a2: pointer, a3: cstring, a4: int32): cstring {.
-  importc, header: "<arpa/inet.h>".}
-proc inet_pton*(a1: cint, a2: cstring, a3: pointer): cint {.
+proc htonl*(a1: uint32): uint32 {.importc, header: "<arpa/inet.h>".}
+proc htons*(a1: uint16): uint16 {.importc, header: "<arpa/inet.h>".}
+proc ntohl*(a1: uint32): uint32 {.importc, header: "<arpa/inet.h>".}
+proc ntohs*(a1: uint16): uint16 {.importc, header: "<arpa/inet.h>".}
+
+when not defined(zephyr):
+  proc inet_addr*(a1: cstring): InAddrT {.importc, header: "<arpa/inet.h>".}
+  proc inet_ntoa*(a1: InAddr): cstring {.importc, header: "<arpa/inet.h>".}
+
+proc inet_ntop*(a1: cint, a2: pointer | ptr InAddr | ptr In6Addr, a3: cstring, a4: int32): cstring {.
+  importc:"(char *)$1", header: "<arpa/inet.h>".}
+proc inet_pton*(a1: cint, a2: cstring, a3: pointer | ptr InAddr | ptr In6Addr): cint {.
   importc, header: "<arpa/inet.h>".}
 
 var
-  in6addr_any* {.importc, header: "<netinet/in.h>".}: TIn6Addr
-  in6addr_loopback* {.importc, header: "<netinet/in.h>".}: TIn6Addr
+  in6addr_any* {.importc, header: "<netinet/in.h>".}: In6Addr
+  in6addr_loopback* {.importc, header: "<netinet/in.h>".}: In6Addr
 
-proc IN6ADDR_ANY_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
-proc IN6ADDR_LOOPBACK_INIT* (): TIn6Addr {.importc, header: "<netinet/in.h>".}
+proc IN6ADDR_ANY_INIT* (): In6Addr {.importc, header: "<netinet/in.h>".}
+proc IN6ADDR_LOOPBACK_INIT* (): In6Addr {.importc, header: "<netinet/in.h>".}
 
 # dirent.h
-proc closedir*(a1: ptr TDIR): cint  {.importc, header: "<dirent.h>".}
-proc opendir*(a1: cstring): ptr TDir {.importc, header: "<dirent.h>".}
-proc readdir*(a1: ptr TDIR): ptr TDirent  {.importc, header: "<dirent.h>".}
-proc readdir_r*(a1: ptr TDIR, a2: ptr Tdirent, a3: ptr ptr TDirent): cint  {.
-                importc, header: "<dirent.h>".}
-proc rewinddir*(a1: ptr TDIR)  {.importc, header: "<dirent.h>".}
-proc seekdir*(a1: ptr TDIR, a2: int)  {.importc, header: "<dirent.h>".}
-proc telldir*(a1: ptr TDIR): int {.importc, header: "<dirent.h>".}
+proc closedir*(a1: ptr DIR): cint  {.importc, header: "<dirent.h>".}
+proc opendir*(a1: cstring): ptr DIR {.importc, header: "<dirent.h>", sideEffect.}
+proc readdir*(a1: ptr DIR): ptr Dirent  {.importc, header: "<dirent.h>", sideEffect.}
+proc readdir_r*(a1: ptr DIR, a2: ptr Dirent, a3: ptr ptr Dirent): cint  {.
+                importc, header: "<dirent.h>", sideEffect.}
+proc rewinddir*(a1: ptr DIR)  {.importc, header: "<dirent.h>".}
+proc seekdir*(a1: ptr DIR, a2: int)  {.importc, header: "<dirent.h>".}
+proc telldir*(a1: ptr DIR): int {.importc, header: "<dirent.h>".}
 
 # dlfcn.h
-proc dlclose*(a1: pointer): cint {.importc, header: "<dlfcn.h>".}
-proc dlerror*(): cstring {.importc, header: "<dlfcn.h>".}
-proc dlopen*(a1: cstring, a2: cint): pointer {.importc, header: "<dlfcn.h>".}
-proc dlsym*(a1: pointer, a2: cstring): pointer {.importc, header: "<dlfcn.h>".}
-
-proc creat*(a1: cstring, a2: Tmode): cint {.importc, header: "<fcntl.h>".}
-proc fcntl*(a1: cint, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
-proc open*(a1: cstring, a2: cint): cint {.varargs, importc, header: "<fcntl.h>".}
-proc posix_fadvise*(a1: cint, a2, a3: Toff, a4: cint): cint {.
-  importc, header: "<fcntl.h>".}
-proc posix_fallocate*(a1: cint, a2, a3: Toff): cint {.
+proc dlclose*(a1: pointer): cint {.importc, header: "<dlfcn.h>", sideEffect.}
+proc dlerror*(): cstring {.importc, header: "<dlfcn.h>", sideEffect.}
+proc dlopen*(a1: cstring, a2: cint): pointer {.importc, header: "<dlfcn.h>", sideEffect.}
+proc dlsym*(a1: pointer, a2: cstring): pointer {.importc, header: "<dlfcn.h>", sideEffect.}
+
+proc creat*(a1: cstring, a2: Mode): cint {.importc, header: "<fcntl.h>", sideEffect.}
+proc fcntl*(a1: cint | SocketHandle, a2: cint): cint {.varargs, importc, header: "<fcntl.h>", sideEffect.}
+proc openImpl(a1: cstring, a2: cint): cint {.varargs, importc: "open", header: "<fcntl.h>", sideEffect.}
+proc open*(a1: cstring, a2: cint, mode: Mode | cint = 0.Mode): cint {.inline.} =
+  # prevents bug #17888
+  openImpl(a1, a2, mode)
+
+proc posix_fadvise*(a1: cint, a2, a3: Off, a4: cint): cint {.
   importc, header: "<fcntl.h>".}
 
-proc feclearexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
-proc fegetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {.
-  importc, header: "<fenv.h>".}
-proc feraiseexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
-proc fesetexceptflag*(a1: ptr Tfexcept, a2: cint): cint {.
-  importc, header: "<fenv.h>".}
-proc fetestexcept*(a1: cint): cint {.importc, header: "<fenv.h>".}
-proc fegetround*(): cint {.importc, header: "<fenv.h>".}
-proc fesetround*(a1: cint): cint {.importc, header: "<fenv.h>".}
-proc fegetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
-proc feholdexcept*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
-proc fesetenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
-proc feupdateenv*(a1: ptr TFenv): cint {.importc, header: "<fenv.h>".}
-
-proc fmtmsg*(a1: int, a2: cstring, a3: cint,
-            a4, a5, a6: cstring): cint {.importc, header: "<fmtmsg.h>".}
-            
+proc ftruncate*(a1: cint, a2: Off): cint {.importc, header: "<unistd.h>".}
+when defined(osx):              # 2001 POSIX evidently does not concern Apple
+  type FStore {.importc: "fstore_t", header: "<fcntl.h>", bycopy.} = object
+    fst_flags: uint32           ## IN: flags word
+    fst_posmode: cint           ## IN: indicates offset field
+    fst_offset,                 ## IN: start of the region
+      fst_length,               ## IN: size of the region
+      fst_bytesalloc: Off       ## OUT: number of bytes allocated
+  var F_PEOFPOSMODE {.importc, header: "<fcntl.h>".}: cint
+  var F_ALLOCATEALL {.importc, header: "<fcntl.h>".}: uint32
+  var F_PREALLOCATE {.importc, header: "<fcntl.h>".}: cint
+  proc posix_fallocate*(a1: cint, a2, a3: Off): cint =
+    var fst = FStore(fst_flags: F_ALLOCATEALL, fst_posmode: F_PEOFPOSMODE,
+                     fst_offset: a2, fst_length: a3)
+    # Must also call ftruncate to match what POSIX does. Unlike posix_fallocate,
+    # this can shrink files.  Could guard w/getFileSize, but caller likely knows
+    # present size & has no good reason to call this unless it is growing.
+    if fcntl(a1, F_PREALLOCATE, fst.addr) != cint(-1): ftruncate(a1, a2 + a3)
+    else: cint(-1)
+else:
+  proc posix_fallocate*(a1: cint, a2, a3: Off): cint {.
+    importc, header: "<fcntl.h>".}
+
+when not defined(haiku) and not defined(openbsd):
+  proc fmtmsg*(a1: int, a2: cstring, a3: cint,
+              a4, a5, a6: cstring): cint {.importc, header: "<fmtmsg.h>".}
+
 proc fnmatch*(a1, a2: cstring, a3: cint): cint {.importc, header: "<fnmatch.h>".}
-proc ftw*(a1: cstring, 
-         a2: proc (x1: cstring, x2: ptr TStat, x3: cint): cint {.noconv.},
+proc ftw*(a1: cstring,
+         a2: proc (x1: cstring, x2: ptr Stat, x3: cint): cint {.noconv.},
          a3: cint): cint {.importc, header: "<ftw.h>".}
-proc nftw*(a1: cstring, 
-          a2: proc (x1: cstring, x2: ptr TStat, 
-                    x3: cint, x4: ptr TFTW): cint {.noconv.},
-          a3: cint,
-          a4: cint): cint {.importc, header: "<ftw.h>".}
+when not (defined(linux) and defined(amd64)) and not defined(nintendoswitch):
+  proc nftw*(a1: cstring,
+            a2: proc (x1: cstring, x2: ptr Stat,
+                      x3: cint, x4: ptr FTW): cint {.noconv.},
+            a3: cint,
+            a4: cint): cint {.importc, header: "<ftw.h>".}
 
 proc glob*(a1: cstring, a2: cint,
           a3: proc (x1: cstring, x2: cint): cint {.noconv.},
-          a4: ptr Tglob): cint {.importc, header: "<glob.h>".}
-proc globfree*(a1: ptr TGlob) {.importc, header: "<glob.h>".}
-
-proc getgrgid*(a1: TGid): ptr TGroup {.importc, header: "<grp.h>".}
-proc getgrnam*(a1: cstring): ptr TGroup {.importc, header: "<grp.h>".}
-proc getgrgid_r*(a1: Tgid, a2: ptr TGroup, a3: cstring, a4: int,
-                 a5: ptr ptr TGroup): cint {.importc, header: "<grp.h>".}
-proc getgrnam_r*(a1: cstring, a2: ptr TGroup, a3: cstring, 
-                  a4: int, a5: ptr ptr TGroup): cint {.
+          a4: ptr Glob): cint {.importc, header: "<glob.h>", sideEffect.}
+  ## Filename globbing. Use `os.walkPattern() <os.html#glob_1>`_ and similar.
+
+proc globfree*(a1: ptr Glob) {.importc, header: "<glob.h>".}
+
+proc getgrgid*(a1: Gid): ptr Group {.importc, header: "<grp.h>".}
+proc getgrnam*(a1: cstring): ptr Group {.importc, header: "<grp.h>".}
+proc getgrgid_r*(a1: Gid, a2: ptr Group, a3: cstring, a4: int,
+                 a5: ptr ptr Group): cint {.importc, header: "<grp.h>".}
+proc getgrnam_r*(a1: cstring, a2: ptr Group, a3: cstring,
+                  a4: int, a5: ptr ptr Group): cint {.
                  importc, header: "<grp.h>".}
-proc getgrent*(): ptr TGroup {.importc, header: "<grp.h>".}
+proc getgrent*(): ptr Group {.importc, header: "<grp.h>".}
 proc endgrent*() {.importc, header: "<grp.h>".}
 proc setgrent*() {.importc, header: "<grp.h>".}
 
 
-proc iconv_open*(a1, a2: cstring): TIconv {.importc, header: "<iconv.h>".}
-proc iconv*(a1: Ticonv, a2: var cstring, a3: var int, a4: var cstring,
+proc iconv_open*(a1, a2: cstring): Iconv {.importc, header: "<iconv.h>".}
+proc iconv*(a1: Iconv, a2: var cstring, a3: var int, a4: var cstring,
             a5: var int): int {.importc, header: "<iconv.h>".}
-proc iconv_close*(a1: Ticonv): cint {.importc, header: "<iconv.h>".}
+proc iconv_close*(a1: Iconv): cint {.importc, header: "<iconv.h>".}
 
-proc nl_langinfo*(a1: Tnl_item): cstring {.importc, header: "<langinfo.h>".}
+proc nl_langinfo*(a1: Nl_item): cstring {.importc, header: "<langinfo.h>".}
 
 proc basename*(a1: cstring): cstring {.importc, header: "<libgen.h>".}
 proc dirname*(a1: cstring): cstring {.importc, header: "<libgen.h>".}
 
-proc localeconv*(): ptr Tlconv {.importc, header: "<locale.h>".}
+proc localeconv*(): ptr Lconv {.importc, header: "<locale.h>".}
 proc setlocale*(a1: cint, a2: cstring): cstring {.
-                importc, header: "<locale.h>".}
+                importc, header: "<locale.h>", sideEffect.}
 
 proc strfmon*(a1: cstring, a2: int, a3: cstring): int {.varargs,
    importc, header: "<monetary.h>".}
 
-proc mq_close*(a1: Tmqd): cint {.importc, header: "<mqueue.h>".}
-proc mq_getattr*(a1: Tmqd, a2: ptr Tmq_attr): cint {.
-  importc, header: "<mqueue.h>".}
-proc mq_notify*(a1: Tmqd, a2: ptr Tsigevent): cint {.
-  importc, header: "<mqueue.h>".}
-proc mq_open*(a1: cstring, a2: cint): TMqd {.
-  varargs, importc, header: "<mqueue.h>".}
-proc mq_receive*(a1: Tmqd, a2: cstring, a3: int, a4: var int): int {.
-  importc, header: "<mqueue.h>".}
-proc mq_send*(a1: Tmqd, a2: cstring, a3: int, a4: int): cint {.
-  importc, header: "<mqueue.h>".}
-proc mq_setattr*(a1: Tmqd, a2, a3: ptr Tmq_attr): cint {.
-  importc, header: "<mqueue.h>".}
-
-proc mq_timedreceive*(a1: Tmqd, a2: cstring, a3: int, a4: int, 
-                      a5: ptr TTimespec): int {.importc, header: "<mqueue.h>".}
-proc mq_timedsend*(a1: Tmqd, a2: cstring, a3: int, a4: int, 
-                   a5: ptr TTimeSpec): cint {.importc, header: "<mqueue.h>".}
-proc mq_unlink*(a1: cstring): cint {.importc, header: "<mqueue.h>".}
-
-
-proc getpwnam*(a1: cstring): ptr TPasswd {.importc, header: "<pwd.h>".}
-proc getpwuid*(a1: Tuid): ptr TPasswd {.importc, header: "<pwd.h>".}
-proc getpwnam_r*(a1: cstring, a2: ptr Tpasswd, a3: cstring, a4: int,
-                 a5: ptr ptr Tpasswd): cint {.importc, header: "<pwd.h>".}
-proc getpwuid_r*(a1: Tuid, a2: ptr Tpasswd, a3: cstring,
-      a4: int, a5: ptr ptr Tpasswd): cint {.importc, header: "<pwd.h>".}
+when not (defined(nintendoswitch) or defined(macos) or defined(macosx)):
+  proc mq_notify*(mqdes: Mqd, event: ptr SigEvent): cint {.
+    importc, header: "<mqueue.h>".}
+
+  proc mq_open*(name: cstring, flags: cint): Mqd {.
+    varargs, importc, header: "<mqueue.h>".}
+
+  proc mq_close*(mqdes: Mqd): cint {.importc, header: "<mqueue.h>".}
+
+  proc mq_receive*(
+    mqdes: Mqd,
+    buffer: cstring,
+    length: csize_t,
+    priority: var cuint
+  ): int {.importc, header: "<mqueue.h>".}
+
+  proc mq_timedreceive*(
+    mqdes: Mqd,
+    buffer: cstring,
+    length: csize_t,
+    priority: cuint,
+    timeout: ptr Timespec
+  ): int {.importc, header: "<mqueue.h>".}
+
+  proc mq_send*(
+    mqdes: Mqd,
+    buffer: cstring,
+    length: csize_t,
+    priority: cuint
+  ): cint {.importc, header: "<mqueue.h>".}
+
+  proc mq_timedsend*(
+    mqdes: Mqd,
+    buffer: cstring,
+    length: csize_t,
+    priority: cuint,
+    timeout: ptr Timespec
+  ): cint {.importc, header: "<mqueue.h>".}
+
+  proc mq_getattr*(mqdes: Mqd, attribute: ptr MqAttr): cint {.
+    importc, header: "<mqueue.h>".}
+
+  proc mq_setattr*(mqdes: Mqd, newAttribute, oldAttribute: ptr MqAttr): cint {.
+    importc, header: "<mqueue.h>".}
+
+  proc mq_unlink*(mqdes: cstring): cint {.importc, header: "<mqueue.h>".}
+
+
+proc getpwnam*(a1: cstring): ptr Passwd {.importc, header: "<pwd.h>".}
+proc getpwuid*(a1: Uid): ptr Passwd {.importc, header: "<pwd.h>".}
+proc getpwnam_r*(a1: cstring, a2: ptr Passwd, a3: cstring, a4: int,
+                 a5: ptr ptr Passwd): cint {.importc, header: "<pwd.h>".}
+proc getpwuid_r*(a1: Uid, a2: ptr Passwd, a3: cstring,
+      a4: int, a5: ptr ptr Passwd): cint {.importc, header: "<pwd.h>".}
 proc endpwent*() {.importc, header: "<pwd.h>".}
-proc getpwent*(): ptr TPasswd {.importc, header: "<pwd.h>".}
+proc getpwent*(): ptr Passwd {.importc, header: "<pwd.h>".}
 proc setpwent*() {.importc, header: "<pwd.h>".}
 
-proc uname*(a1: var Tutsname): cint {.importc, header: "<sys/utsname.h>".}
+proc uname*(a1: var Utsname): cint {.importc, header: "<sys/utsname.h>".}
+
+proc strerror*(errnum: cint): cstring {.importc, header: "<string.h>".}
 
-proc pthread_atfork*(a1, a2, a3: proc {.noconv.}): cint {.
+proc pthread_atfork*(a1, a2, a3: proc () {.noconv.}): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_destroy*(a1: ptr Tpthread_attr): cint {.
+proc pthread_attr_destroy*(a1: ptr Pthread_attr): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_getdetachstate*(a1: ptr Tpthread_attr, a2: cint): cint {.
+proc pthread_attr_getdetachstate*(a1: ptr Pthread_attr, a2: cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_getguardsize*(a1: ptr Tpthread_attr, a2: var cint): cint {.
+proc pthread_attr_getguardsize*(a1: ptr Pthread_attr, a2: var cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_getinheritsched*(a1: ptr Tpthread_attr,
+proc pthread_attr_getinheritsched*(a1: ptr Pthread_attr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_getschedparam*(a1: ptr Tpthread_attr,
-          a2: ptr Tsched_param): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_getschedpolicy*(a1: ptr Tpthread_attr,
+proc pthread_attr_getschedparam*(a1: ptr Pthread_attr,
+          a2: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
+proc pthread_attr_getschedpolicy*(a1: ptr Pthread_attr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_getscope*(a1: ptr Tpthread_attr,
+proc pthread_attr_getscope*(a1: ptr Pthread_attr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_getstack*(a1: ptr Tpthread_attr,
+proc pthread_attr_getstack*(a1: ptr Pthread_attr,
          a2: var pointer, a3: var int): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_getstackaddr*(a1: ptr Tpthread_attr,
+proc pthread_attr_getstackaddr*(a1: ptr Pthread_attr,
           a2: var pointer): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_getstacksize*(a1: ptr Tpthread_attr,
+proc pthread_attr_getstacksize*(a1: ptr Pthread_attr,
           a2: var int): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_init*(a1: ptr Tpthread_attr): cint {.
+proc pthread_attr_init*(a1: ptr Pthread_attr): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setdetachstate*(a1: ptr Tpthread_attr, a2: cint): cint {.
+proc pthread_attr_setdetachstate*(a1: ptr Pthread_attr, a2: cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setguardsize*(a1: ptr Tpthread_attr, a2: int): cint {.
+proc pthread_attr_setguardsize*(a1: ptr Pthread_attr, a2: int): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setinheritsched*(a1: ptr Tpthread_attr, a2: cint): cint {.
+proc pthread_attr_setinheritsched*(a1: ptr Pthread_attr, a2: cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setschedparam*(a1: ptr Tpthread_attr,
-          a2: ptr Tsched_param): cint {.importc, header: "<pthread.h>".}
-proc pthread_attr_setschedpolicy*(a1: ptr Tpthread_attr, a2: cint): cint {.
+proc pthread_attr_setschedparam*(a1: ptr Pthread_attr,
+          a2: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
+proc pthread_attr_setschedpolicy*(a1: ptr Pthread_attr, a2: cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setscope*(a1: ptr Tpthread_attr, a2: cint): cint {.importc,
+proc pthread_attr_setscope*(a1: ptr Pthread_attr, a2: cint): cint {.importc,
   header: "<pthread.h>".}
-proc pthread_attr_setstack*(a1: ptr Tpthread_attr, a2: pointer, a3: int): cint {.
+proc pthread_attr_setstack*(a1: ptr Pthread_attr, a2: pointer, a3: int): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setstackaddr*(a1: ptr TPthread_attr, a2: pointer): cint {.
+proc pthread_attr_setstackaddr*(a1: ptr Pthread_attr, a2: pointer): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_attr_setstacksize*(a1: ptr TPthread_attr, a2: int): cint {.
+proc pthread_attr_setstacksize*(a1: ptr Pthread_attr, a2: int): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_barrier_destroy*(a1: ptr Tpthread_barrier): cint {.
+proc pthread_barrier_destroy*(a1: ptr Pthread_barrier): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_barrier_init*(a1: ptr Tpthread_barrier,
-         a2: ptr Tpthread_barrierattr, a3: cint): cint {.
+proc pthread_barrier_init*(a1: ptr Pthread_barrier,
+         a2: ptr Pthread_barrierattr, a3: cint): cint {.
          importc, header: "<pthread.h>".}
-proc pthread_barrier_wait*(a1: ptr Tpthread_barrier): cint {.
+proc pthread_barrier_wait*(a1: ptr Pthread_barrier): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_barrierattr_destroy*(a1: ptr Tpthread_barrierattr): cint {.
+proc pthread_barrierattr_destroy*(a1: ptr Pthread_barrierattr): cint {.
   importc, header: "<pthread.h>".}
 proc pthread_barrierattr_getpshared*(
-          a1: ptr Tpthread_barrierattr, a2: var cint): cint {.
+          a1: ptr Pthread_barrierattr, a2: var cint): cint {.
           importc, header: "<pthread.h>".}
-proc pthread_barrierattr_init*(a1: ptr TPthread_barrierattr): cint {.
+proc pthread_barrierattr_init*(a1: ptr Pthread_barrierattr): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_barrierattr_setpshared*(a1: ptr TPthread_barrierattr, 
+proc pthread_barrierattr_setpshared*(a1: ptr Pthread_barrierattr,
   a2: cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_cancel*(a1: Tpthread): cint {.importc, header: "<pthread.h>".}
+proc pthread_cancel*(a1: Pthread): cint {.importc, header: "<pthread.h>".}
 proc pthread_cleanup_push*(a1: proc (x: pointer) {.noconv.}, a2: pointer) {.
   importc, header: "<pthread.h>".}
 proc pthread_cleanup_pop*(a1: cint) {.importc, header: "<pthread.h>".}
-proc pthread_cond_broadcast*(a1: ptr Tpthread_cond): cint {.
+proc pthread_cond_broadcast*(a1: ptr Pthread_cond): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_cond_destroy*(a1: ptr Tpthread_cond): cint {.importc, header: "<pthread.h>".}
-proc pthread_cond_init*(a1: ptr Tpthread_cond,
-          a2: ptr Tpthread_condattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_cond_signal*(a1: ptr Tpthread_cond): cint {.importc, header: "<pthread.h>".}
-proc pthread_cond_timedwait*(a1: ptr Tpthread_cond,
-          a2: ptr Tpthread_mutex, a3: ptr Ttimespec): cint {.importc, header: "<pthread.h>".}
-
-proc pthread_cond_wait*(a1: ptr Tpthread_cond,
-          a2: ptr Tpthread_mutex): cint {.importc, header: "<pthread.h>".}
-proc pthread_condattr_destroy*(a1: ptr Tpthread_condattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_condattr_getclock*(a1: ptr Tpthread_condattr,
-          a2: var Tclockid): cint {.importc, header: "<pthread.h>".}
-proc pthread_condattr_getpshared*(a1: ptr Tpthread_condattr,
+proc pthread_cond_destroy*(a1: ptr Pthread_cond): cint {.importc, header: "<pthread.h>".}
+proc pthread_cond_init*(a1: ptr Pthread_cond,
+          a2: ptr Pthread_condattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_cond_signal*(a1: ptr Pthread_cond): cint {.importc, header: "<pthread.h>".}
+proc pthread_cond_timedwait*(a1: ptr Pthread_cond,
+          a2: ptr Pthread_mutex, a3: ptr Timespec): cint {.importc, header: "<pthread.h>".}
+
+proc pthread_cond_wait*(a1: ptr Pthread_cond,
+          a2: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
+proc pthread_condattr_destroy*(a1: ptr Pthread_condattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_condattr_getclock*(a1: ptr Pthread_condattr,
+          a2: var ClockId): cint {.importc, header: "<pthread.h>".}
+proc pthread_condattr_getpshared*(a1: ptr Pthread_condattr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
-          
-proc pthread_condattr_init*(a1: ptr TPthread_condattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_condattr_setclock*(a1: ptr TPthread_condattr,a2: Tclockid): cint {.importc, header: "<pthread.h>".}
-proc pthread_condattr_setpshared*(a1: ptr TPthread_condattr, a2: cint): cint {.importc, header: "<pthread.h>".}
 
-proc pthread_create*(a1: ptr Tpthread, a2: ptr Tpthread_attr,
+proc pthread_condattr_init*(a1: ptr Pthread_condattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_condattr_setclock*(a1: ptr Pthread_condattr,a2: ClockId): cint {.importc, header: "<pthread.h>".}
+proc pthread_condattr_setpshared*(a1: ptr Pthread_condattr, a2: cint): cint {.importc, header: "<pthread.h>".}
+
+proc pthread_create*(a1: ptr Pthread, a2: ptr Pthread_attr,
           a3: proc (x: pointer): pointer {.noconv.}, a4: pointer): cint {.importc, header: "<pthread.h>".}
-proc pthread_detach*(a1: Tpthread): cint {.importc, header: "<pthread.h>".}
-proc pthread_equal*(a1, a2: Tpthread): cint {.importc, header: "<pthread.h>".}
+proc pthread_detach*(a1: Pthread): cint {.importc, header: "<pthread.h>".}
+proc pthread_equal*(a1, a2: Pthread): cint {.importc, header: "<pthread.h>".}
 proc pthread_exit*(a1: pointer) {.importc, header: "<pthread.h>".}
 proc pthread_getconcurrency*(): cint {.importc, header: "<pthread.h>".}
-proc pthread_getcpuclockid*(a1: Tpthread, a2: var Tclockid): cint {.importc, header: "<pthread.h>".}
-proc pthread_getschedparam*(a1: Tpthread,  a2: var cint,
-          a3: ptr Tsched_param): cint {.importc, header: "<pthread.h>".}
-proc pthread_getspecific*(a1: Tpthread_key): pointer {.importc, header: "<pthread.h>".}
-proc pthread_join*(a1: Tpthread, a2: ptr pointer): cint {.importc, header: "<pthread.h>".}
-proc pthread_key_create*(a1: ptr Tpthread_key, a2: proc (x: pointer) {.noconv.}): cint {.importc, header: "<pthread.h>".}
-proc pthread_key_delete*(a1: Tpthread_key): cint {.importc, header: "<pthread.h>".}
-
-proc pthread_mutex_destroy*(a1: ptr Tpthread_mutex): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_getprioceiling*(a1: ptr Tpthread_mutex,
+proc pthread_getcpuclockid*(a1: Pthread, a2: var ClockId): cint {.importc, header: "<pthread.h>".}
+proc pthread_getschedparam*(a1: Pthread,  a2: var cint,
+          a3: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
+proc pthread_getspecific*(a1: Pthread_key): pointer {.importc, header: "<pthread.h>".}
+proc pthread_join*(a1: Pthread, a2: ptr pointer): cint {.importc, header: "<pthread.h>".}
+proc pthread_key_create*(a1: ptr Pthread_key, a2: proc (x: pointer) {.noconv.}): cint {.importc, header: "<pthread.h>".}
+proc pthread_key_delete*(a1: Pthread_key): cint {.importc, header: "<pthread.h>".}
+
+proc pthread_mutex_destroy*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutex_getprioceiling*(a1: ptr Pthread_mutex,
          a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_init*(a1: ptr Tpthread_mutex,
-          a2: ptr Tpthread_mutexattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_lock*(a1: ptr Tpthread_mutex): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_setprioceiling*(a1: ptr Tpthread_mutex,a2: cint,
+proc pthread_mutex_init*(a1: ptr Pthread_mutex,
+          a2: ptr Pthread_mutexattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutex_lock*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutex_setprioceiling*(a1: ptr Pthread_mutex,a2: cint,
           a3: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_timedlock*(a1: ptr Tpthread_mutex,
-          a2: ptr Ttimespec): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_trylock*(a1: ptr Tpthread_mutex): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutex_unlock*(a1: ptr Tpthread_mutex): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_destroy*(a1: ptr Tpthread_mutexattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutex_timedlock*(a1: ptr Pthread_mutex,
+          a2: ptr Timespec): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutex_trylock*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutex_unlock*(a1: ptr Pthread_mutex): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_destroy*(a1: ptr Pthread_mutexattr): cint {.importc, header: "<pthread.h>".}
 
 proc pthread_mutexattr_getprioceiling*(
-          a1: ptr Tpthread_mutexattr, a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_getprotocol*(a1: ptr Tpthread_mutexattr,
+          a1: ptr Pthread_mutexattr, a2: var cint): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_getprotocol*(a1: ptr Pthread_mutexattr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_getpshared*(a1: ptr Tpthread_mutexattr,
+proc pthread_mutexattr_getpshared*(a1: ptr Pthread_mutexattr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_gettype*(a1: ptr Tpthread_mutexattr,
+proc pthread_mutexattr_gettype*(a1: ptr Pthread_mutexattr,
           a2: var cint): cint {.importc, header: "<pthread.h>".}
 
-proc pthread_mutexattr_init*(a1: ptr Tpthread_mutexattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_setprioceiling*(a1: ptr tpthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_setprotocol*(a1: ptr Tpthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_setpshared*(a1: ptr Tpthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_mutexattr_settype*(a1: ptr Tpthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
-
-proc pthread_once*(a1: ptr Tpthread_once, a2: proc {.noconv.}): cint {.importc, header: "<pthread.h>".}
-
-proc pthread_rwlock_destroy*(a1: ptr Tpthread_rwlock): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_init*(a1: ptr Tpthread_rwlock,
-          a2: ptr Tpthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_rdlock*(a1: ptr Tpthread_rwlock): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_timedrdlock*(a1: ptr Tpthread_rwlock,
-          a2: ptr Ttimespec): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_timedwrlock*(a1: ptr Tpthread_rwlock,
-          a2: ptr Ttimespec): cint {.importc, header: "<pthread.h>".}
-
-proc pthread_rwlock_tryrdlock*(a1: ptr Tpthread_rwlock): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_trywrlock*(a1: ptr Tpthread_rwlock): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_unlock*(a1: ptr Tpthread_rwlock): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlock_wrlock*(a1: ptr Tpthread_rwlock): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlockattr_destroy*(a1: ptr Tpthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_init*(a1: ptr Pthread_mutexattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_setprioceiling*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_setprotocol*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_setpshared*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
+proc pthread_mutexattr_settype*(a1: ptr Pthread_mutexattr, a2: cint): cint {.importc, header: "<pthread.h>".}
+
+proc pthread_once*(a1: ptr Pthread_once, a2: proc () {.noconv.}): cint {.importc, header: "<pthread.h>".}
+
+proc pthread_rwlock_destroy*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_init*(a1: ptr Pthread_rwlock,
+          a2: ptr Pthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_rdlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_timedrdlock*(a1: ptr Pthread_rwlock,
+          a2: ptr Timespec): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_timedwrlock*(a1: ptr Pthread_rwlock,
+          a2: ptr Timespec): cint {.importc, header: "<pthread.h>".}
+
+proc pthread_rwlock_tryrdlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_trywrlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_unlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlock_wrlock*(a1: ptr Pthread_rwlock): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlockattr_destroy*(a1: ptr Pthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
 proc pthread_rwlockattr_getpshared*(
-          a1: ptr Tpthread_rwlockattr, a2: var cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlockattr_init*(a1: ptr Tpthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
-proc pthread_rwlockattr_setpshared*(a1: ptr Tpthread_rwlockattr, a2: cint): cint {.importc, header: "<pthread.h>".}
+          a1: ptr Pthread_rwlockattr, a2: var cint): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlockattr_init*(a1: ptr Pthread_rwlockattr): cint {.importc, header: "<pthread.h>".}
+proc pthread_rwlockattr_setpshared*(a1: ptr Pthread_rwlockattr, a2: cint): cint {.importc, header: "<pthread.h>".}
 
-proc pthread_self*(): Tpthread {.importc, header: "<pthread.h>".}
+proc pthread_self*(): Pthread {.importc, header: "<pthread.h>".}
 proc pthread_setcancelstate*(a1: cint, a2: var cint): cint {.importc, header: "<pthread.h>".}
 proc pthread_setcanceltype*(a1: cint, a2: var cint): cint {.importc, header: "<pthread.h>".}
 proc pthread_setconcurrency*(a1: cint): cint {.importc, header: "<pthread.h>".}
-proc pthread_setschedparam*(a1: Tpthread, a2: cint,
-          a3: ptr Tsched_param): cint {.importc, header: "<pthread.h>".}
+proc pthread_setschedparam*(a1: Pthread, a2: cint,
+          a3: ptr Sched_param): cint {.importc, header: "<pthread.h>".}
 
-proc pthread_setschedprio*(a1: Tpthread, a2: cint): cint {.
+proc pthread_setschedprio*(a1: Pthread, a2: cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_setspecific*(a1: Tpthread_key, a2: pointer): cint {.
+proc pthread_setspecific*(a1: Pthread_key, a2: pointer): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_spin_destroy*(a1: ptr Tpthread_spinlock): cint {.
+proc pthread_spin_destroy*(a1: ptr Pthread_spinlock): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_spin_init*(a1: ptr Tpthread_spinlock, a2: cint): cint {.
+proc pthread_spin_init*(a1: ptr Pthread_spinlock, a2: cint): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_spin_lock*(a1: ptr Tpthread_spinlock): cint {.
+proc pthread_spin_lock*(a1: ptr Pthread_spinlock): cint {.
   importc, header: "<pthread.h>".}
-proc pthread_spin_trylock*(a1: ptr Tpthread_spinlock): cint{.
+proc pthread_spin_trylock*(a1: ptr Pthread_spinlock): cint{.
   importc, header: "<pthread.h>".}
-proc pthread_spin_unlock*(a1: ptr Tpthread_spinlock): cint {.
+proc pthread_spin_unlock*(a1: ptr Pthread_spinlock): cint {.
   importc, header: "<pthread.h>".}
 proc pthread_testcancel*() {.importc, header: "<pthread.h>".}
 
 
+proc exitnow*(code: int) {.importc: "_exit", header: "<unistd.h>".}
 proc access*(a1: cstring, a2: cint): cint {.importc, header: "<unistd.h>".}
 proc alarm*(a1: cint): cint {.importc, header: "<unistd.h>".}
 proc chdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
-proc chown*(a1: cstring, a2: Tuid, a3: Tgid): cint {.importc, header: "<unistd.h>".}
-proc close*(a1: cint): cint {.importc, header: "<unistd.h>".}
+proc chown*(a1: cstring, a2: Uid, a3: Gid): cint {.importc, header: "<unistd.h>".}
+proc close*(a1: cint | SocketHandle): cint {.importc, header: "<unistd.h>".}
 proc confstr*(a1: cint, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
 proc crypt*(a1, a2: cstring): cstring {.importc, header: "<unistd.h>".}
 proc ctermid*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
@@ -2048,395 +516,487 @@ proc dup*(a1: cint): cint {.importc, header: "<unistd.h>".}
 proc dup2*(a1, a2: cint): cint {.importc, header: "<unistd.h>".}
 proc encrypt*(a1: array[0..63, char], a2: cint) {.importc, header: "<unistd.h>".}
 
-proc execl*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>".}
-proc execle*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>".}
-proc execlp*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>".}
-proc execv*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>".}
+proc execl*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>", sideEffect.}
+proc execle*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>", sideEffect.}
+proc execlp*(a1, a2: cstring): cint {.varargs, importc, header: "<unistd.h>", sideEffect.}
+proc execv*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>", sideEffect.}
 proc execve*(a1: cstring, a2, a3: cstringArray): cint {.
-  importc, header: "<unistd.h>".}
-proc execvp*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>".}
-proc fchown*(a1: cint, a2: Tuid, a3: Tgid): cint {.importc, header: "<unistd.h>".}
-proc fchdir*(a1: cint): cint {.importc, header: "<unistd.h>".}
+  importc, header: "<unistd.h>", sideEffect.}
+proc execvp*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>", sideEffect.}
+proc execvpe*(a1: cstring, a2: cstringArray, a3: cstringArray): cint {.importc, header: "<unistd.h>", sideEffect.}
+proc fchown*(a1: cint, a2: Uid, a3: Gid): cint {.importc, header: "<unistd.h>", sideEffect.}
+proc fchdir*(a1: cint): cint {.importc, header: "<unistd.h>", sideEffect.}
 proc fdatasync*(a1: cint): cint {.importc, header: "<unistd.h>".}
-proc fork*(): Tpid {.importc, header: "<unistd.h>".}
+proc fork*(): Pid {.importc, header: "<unistd.h>", sideEffect.}
 proc fpathconf*(a1, a2: cint): int {.importc, header: "<unistd.h>".}
 proc fsync*(a1: cint): cint {.importc, header: "<unistd.h>".}
-proc ftruncate*(a1: cint, a2: Toff): cint {.importc, header: "<unistd.h>".}
-proc getcwd*(a1: cstring, a2: int): cstring {.importc, header: "<unistd.h>".}
-proc getegid*(): TGid {.importc, header: "<unistd.h>".}
-proc geteuid*(): TUid {.importc, header: "<unistd.h>".}
-proc getgid*(): TGid {.importc, header: "<unistd.h>".}
+ ## synchronize a file's buffer cache to the storage device
+
+proc getcwd*(a1: cstring, a2: int): cstring {.importc, header: "<unistd.h>", sideEffect.}
+proc getuid*(): Uid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns the real user ID of the calling process
+
+proc geteuid*(): Uid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns the effective user ID of the calling process
 
-proc getgroups*(a1: cint, a2: ptr array[0..255, Tgid]): cint {.
+proc getgid*(): Gid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns the real group ID of the calling process
+
+proc getegid*(): Gid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns the effective group ID of the calling process
+
+proc getgroups*(a1: cint, a2: ptr array[0..255, Gid]): cint {.
   importc, header: "<unistd.h>".}
-proc gethostid*(): int {.importc, header: "<unistd.h>".}
-proc gethostname*(a1: cstring, a2: int): cint {.importc, header: "<unistd.h>".}
-proc getlogin*(): cstring {.importc, header: "<unistd.h>".}
-proc getlogin_r*(a1: cstring, a2: int): cint {.importc, header: "<unistd.h>".}
+proc gethostid*(): int {.importc, header: "<unistd.h>", sideEffect.}
+proc gethostname*(a1: cstring, a2: int): cint {.importc, header: "<unistd.h>", sideEffect.}
+proc getlogin*(): cstring {.importc, header: "<unistd.h>", sideEffect.}
+proc getlogin_r*(a1: cstring, a2: int): cint {.importc, header: "<unistd.h>", sideEffect.}
 
 proc getopt*(a1: cint, a2: cstringArray, a3: cstring): cint {.
   importc, header: "<unistd.h>".}
-proc getpgid*(a1: Tpid): Tpid {.importc, header: "<unistd.h>".}
-proc getpgrp*(): Tpid {.importc, header: "<unistd.h>".}
-proc getpid*(): Tpid {.importc, header: "<unistd.h>".}
-proc getppid*(): Tpid {.importc, header: "<unistd.h>".}
-proc getsid*(a1: Tpid): Tpid {.importc, header: "<unistd.h>".}
-proc getuid*(): Tuid {.importc, header: "<unistd.h>".}
+proc getpgid*(a1: Pid): Pid {.importc, header: "<unistd.h>".}
+proc getpgrp*(): Pid {.importc, header: "<unistd.h>".}
+proc getpid*(): Pid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns  the process ID (PID) of the calling process
+
+proc getppid*(): Pid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns the process ID of the parent of the calling process
+
+proc getsid*(a1: Pid): Pid {.importc, header: "<unistd.h>", sideEffect.}
+ ## returns the session ID of the calling process
+
 proc getwd*(a1: cstring): cstring {.importc, header: "<unistd.h>".}
 proc isatty*(a1: cint): cint {.importc, header: "<unistd.h>".}
-proc lchown*(a1: cstring, a2: Tuid, a3: Tgid): cint {.importc, header: "<unistd.h>".}
+proc lchown*(a1: cstring, a2: Uid, a3: Gid): cint {.importc, header: "<unistd.h>".}
 proc link*(a1, a2: cstring): cint {.importc, header: "<unistd.h>".}
 
-proc lockf*(a1, a2: cint, a3: Toff): cint {.importc, header: "<unistd.h>".}
-proc lseek*(a1: cint, a2: Toff, a3: cint): Toff {.importc, header: "<unistd.h>".}
+proc lockf*(a1, a2: cint, a3: Off): cint {.importc, header: "<unistd.h>".}
+proc lseek*(a1: cint, a2: Off, a3: cint): Off {.importc, header: "<unistd.h>".}
 proc nice*(a1: cint): cint {.importc, header: "<unistd.h>".}
 proc pathconf*(a1: cstring, a2: cint): int {.importc, header: "<unistd.h>".}
 
 proc pause*(): cint {.importc, header: "<unistd.h>".}
+proc pclose*(a: File): cint {.importc, header: "<stdio.h>".}
 proc pipe*(a: array[0..1, cint]): cint {.importc, header: "<unistd.h>".}
-proc pread*(a1: cint, a2: pointer, a3: int, a4: Toff): int {.
+proc popen*(a1, a2: cstring): File {.importc, header: "<stdio.h>".}
+proc pread*(a1: cint, a2: pointer, a3: int, a4: Off): int {.
   importc, header: "<unistd.h>".}
-proc pwrite*(a1: cint, a2: pointer, a3: int, a4: Toff): int {.
+proc pwrite*(a1: cint, a2: pointer, a3: int, a4: Off): int {.
   importc, header: "<unistd.h>".}
 proc read*(a1: cint, a2: pointer, a3: int): int {.importc, header: "<unistd.h>".}
-proc readlink*(a1, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
+when not defined(nintendoswitch):
+  proc readlink*(a1, a2: cstring, a3: int): int {.importc, header: "<unistd.h>".}
+proc ioctl*(f: FileHandle, device: uint): int {.importc: "ioctl",
+      header: "<sys/ioctl.h>", varargs, tags: [WriteIOEffect].}
+  ## A system call for device-specific input/output operations and other
+  ## operations which cannot be expressed by regular system calls
 
 proc rmdir*(a1: cstring): cint {.importc, header: "<unistd.h>".}
-proc setegid*(a1: Tgid): cint {.importc, header: "<unistd.h>".}
-proc seteuid*(a1: Tuid): cint {.importc, header: "<unistd.h>".}
-proc setgid*(a1: Tgid): cint {.importc, header: "<unistd.h>".}
-
-proc setpgid*(a1, a2: Tpid): cint {.importc, header: "<unistd.h>".}
-proc setpgrp*(): Tpid {.importc, header: "<unistd.h>".}
-proc setregid*(a1, a2: Tgid): cint {.importc, header: "<unistd.h>".}
-proc setreuid*(a1, a2: Tuid): cint {.importc, header: "<unistd.h>".}
-proc setsid*(): Tpid {.importc, header: "<unistd.h>".}
-proc setuid*(a1: Tuid): cint {.importc, header: "<unistd.h>".}
+proc setegid*(a1: Gid): cint {.importc, header: "<unistd.h>".}
+proc seteuid*(a1: Uid): cint {.importc, header: "<unistd.h>".}
+proc setgid*(a1: Gid): cint {.importc, header: "<unistd.h>".}
+
+proc setpgid*(a1, a2: Pid): cint {.importc, header: "<unistd.h>".}
+proc setpgrp*(): Pid {.importc, header: "<unistd.h>".}
+proc setregid*(a1, a2: Gid): cint {.importc, header: "<unistd.h>".}
+proc setreuid*(a1, a2: Uid): cint {.importc, header: "<unistd.h>".}
+proc setsid*(): Pid {.importc, header: "<unistd.h>".}
+proc setuid*(a1: Uid): cint {.importc, header: "<unistd.h>".}
 proc sleep*(a1: cint): cint {.importc, header: "<unistd.h>".}
 proc swab*(a1, a2: pointer, a3: int) {.importc, header: "<unistd.h>".}
-proc symlink*(a1, a2: cstring): cint {.importc, header: "<unistd.h>".}
+when not defined(nintendoswitch):
+  proc symlink*(a1, a2: cstring): cint {.importc, header: "<unistd.h>".}
+else:
+  proc symlink*(a1, a2: cstring): cint = -1
 proc sync*() {.importc, header: "<unistd.h>".}
 proc sysconf*(a1: cint): int {.importc, header: "<unistd.h>".}
-proc tcgetpgrp*(a1: cint): tpid {.importc, header: "<unistd.h>".}
-proc tcsetpgrp*(a1: cint, a2: Tpid): cint {.importc, header: "<unistd.h>".}
-proc truncate*(a1: cstring, a2: Toff): cint {.importc, header: "<unistd.h>".}
+proc tcgetpgrp*(a1: cint): Pid {.importc, header: "<unistd.h>".}
+proc tcsetpgrp*(a1: cint, a2: Pid): cint {.importc, header: "<unistd.h>".}
+proc truncate*(a1: cstring, a2: Off): cint {.importc, header: "<unistd.h>".}
 proc ttyname*(a1: cint): cstring {.importc, header: "<unistd.h>".}
 proc ttyname_r*(a1: cint, a2: cstring, a3: int): cint {.
   importc, header: "<unistd.h>".}
-proc ualarm*(a1, a2: Tuseconds): Tuseconds {.importc, header: "<unistd.h>".}
+proc ualarm*(a1, a2: Useconds): Useconds {.importc, header: "<unistd.h>".}
 proc unlink*(a1: cstring): cint {.importc, header: "<unistd.h>".}
-proc usleep*(a1: Tuseconds): cint {.importc, header: "<unistd.h>".}
-proc vfork*(): tpid {.importc, header: "<unistd.h>".}
+proc usleep*(a1: Useconds): cint {.importc, header: "<unistd.h>".}
+proc vfork*(): Pid {.importc, header: "<unistd.h>".}
 proc write*(a1: cint, a2: pointer, a3: int): int {.importc, header: "<unistd.h>".}
 
-proc sem_close*(a1: ptr Tsem): cint {.importc, header: "<semaphore.h>".}
-proc sem_destroy*(a1: ptr Tsem): cint {.importc, header: "<semaphore.h>".}
-proc sem_getvalue*(a1: ptr Tsem, a2: var cint): cint {.
+proc sem_close*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
+proc sem_destroy*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
+proc sem_getvalue*(a1: ptr Sem, a2: var cint): cint {.
   importc, header: "<semaphore.h>".}
-proc sem_init*(a1: ptr Tsem, a2: cint, a3: cint): cint {.
+proc sem_init*(a1: ptr Sem, a2: cint, a3: cint): cint {.
   importc, header: "<semaphore.h>".}
-proc sem_open*(a1: cstring, a2: cint): ptr TSem {.
+proc sem_open*(a1: cstring, a2: cint): ptr Sem {.
   varargs, importc, header: "<semaphore.h>".}
-proc sem_post*(a1: ptr Tsem): cint {.importc, header: "<semaphore.h>".}
-proc sem_timedwait*(a1: ptr Tsem, a2: ptr Ttimespec): cint {.
+proc sem_post*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
+proc sem_timedwait*(a1: ptr Sem, a2: ptr Timespec): cint {.
   importc, header: "<semaphore.h>".}
-proc sem_trywait*(a1: ptr Tsem): cint {.importc, header: "<semaphore.h>".}
+proc sem_trywait*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
 proc sem_unlink*(a1: cstring): cint {.importc, header: "<semaphore.h>".}
-proc sem_wait*(a1: ptr Tsem): cint {.importc, header: "<semaphore.h>".}
+proc sem_wait*(a1: ptr Sem): cint {.importc, header: "<semaphore.h>".}
 
-proc ftok*(a1: cstring, a2: cint): Tkey {.importc, header: "<sys/ipc.h>".}
+proc ftok*(a1: cstring, a2: cint): Key {.importc, header: "<sys/ipc.h>".}
 
-proc statvfs*(a1: cstring, a2: var Tstatvfs): cint {.
+proc statvfs*(a1: cstring, a2: var Statvfs): cint {.
   importc, header: "<sys/statvfs.h>".}
-proc fstatvfs*(a1: cint, a2: var Tstatvfs): cint {.
+proc fstatvfs*(a1: cint, a2: var Statvfs): cint {.
   importc, header: "<sys/statvfs.h>".}
 
-proc chmod*(a1: cstring, a2: TMode): cint {.importc, header: "<sys/stat.h>".}
-proc fchmod*(a1: cint, a2: TMode): cint {.importc, header: "<sys/stat.h>".}
-proc fstat*(a1: cint, a2: var Tstat): cint {.importc, header: "<sys/stat.h>".}
-proc lstat*(a1: cstring, a2: var Tstat): cint {.importc, header: "<sys/stat.h>".}
-proc mkdir*(a1: cstring, a2: TMode): cint {.importc, header: "<sys/stat.h>".}
-proc mkfifo*(a1: cstring, a2: TMode): cint {.importc, header: "<sys/stat.h>".}
-proc mknod*(a1: cstring, a2: TMode, a3: Tdev): cint {.
+proc chmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
+when defined(osx) or defined(freebsd):
+  proc lchmod*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
+proc fchmod*(a1: cint, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
+proc fstat*(a1: cint, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
+proc lstat*(a1: cstring, a2: var Stat): cint {.importc, header: "<sys/stat.h>", sideEffect.}
+proc mkdir*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>", sideEffect.}
+  ## Use `os.createDir() <os.html#createDir,string>`_ and similar.
+
+proc mkfifo*(a1: cstring, a2: Mode): cint {.importc, header: "<sys/stat.h>".}
+proc mknod*(a1: cstring, a2: Mode, a3: Dev): cint {.
   importc, header: "<sys/stat.h>".}
-proc stat*(a1: cstring, a2: var Tstat): cint {.importc, header: "<sys/stat.h>".}
-proc umask*(a1: Tmode): TMode {.importc, header: "<sys/stat.h>".}
+proc stat*(a1: cstring, a2: var Stat): cint {.importc, header: "<sys/stat.h>".}
+proc umask*(a1: Mode): Mode {.importc, header: "<sys/stat.h>".}
 
-proc S_ISBLK*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISBLK*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a block special file.
-proc S_ISCHR*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISCHR*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a character special file.
-proc S_ISDIR*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISDIR*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a directory.
-proc S_ISFIFO*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISFIFO*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a pipe or FIFO special file.
-proc S_ISREG*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISREG*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a regular file.
-proc S_ISLNK*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISLNK*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a symbolic link.
-proc S_ISSOCK*(m: Tmode): bool {.importc, header: "<sys/stat.h>".}
-  ## Test for a socket. 
-    
-proc S_TYPEISMQ*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".}
+proc S_ISSOCK*(m: Mode): bool {.importc, header: "<sys/stat.h>".}
+  ## Test for a socket.
+
+proc S_TYPEISMQ*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a message queue.
-proc S_TYPEISSEM*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".}
+proc S_TYPEISSEM*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
   ## Test for a semaphore.
-proc S_TYPEISSHM*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".}
-  ## Test for a shared memory object. 
-    
-proc S_TYPEISTMO*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".}
-  ## Test macro for a typed memory object. 
-  
+proc S_TYPEISSHM*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
+  ## Test for a shared memory object.
+
+proc S_TYPEISTMO*(buf: var Stat): bool {.importc, header: "<sys/stat.h>".}
+  ## Test macro for a typed memory object.
+
 proc mlock*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".}
 proc mlockall*(a1: cint): cint {.importc, header: "<sys/mman.h>".}
-proc mmap*(a1: pointer, a2: int, a3, a4, a5: cint, a6: Toff): pointer {.
+proc mmap*(a1: pointer, a2: int, a3, a4, a5: cint, a6: Off): pointer {.
   importc, header: "<sys/mman.h>".}
 proc mprotect*(a1: pointer, a2: int, a3: cint): cint {.
   importc, header: "<sys/mman.h>".}
 proc msync*(a1: pointer, a2: int, a3: cint): cint {.importc, header: "<sys/mman.h>".}
+
 proc munlock*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".}
 proc munlockall*(): cint {.importc, header: "<sys/mman.h>".}
 proc munmap*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".}
 proc posix_madvise*(a1: pointer, a2: int, a3: cint): cint {.
   importc, header: "<sys/mman.h>".}
-proc posix_mem_offset*(a1: pointer, a2: int, a3: var Toff,
+proc posix_mem_offset*(a1: pointer, a2: int, a3: var Off,
            a4: var int, a5: var cint): cint {.importc, header: "<sys/mman.h>".}
-proc posix_typed_mem_get_info*(a1: cint, 
-  a2: var Tposix_typed_mem_info): cint {.importc, header: "<sys/mman.h>".}
+when not (defined(linux) and defined(amd64)) and not defined(nintendoswitch) and
+     not defined(haiku):
+  proc posix_typed_mem_get_info*(a1: cint,
+    a2: var Posix_typed_mem_info): cint {.importc, header: "<sys/mman.h>".}
 proc posix_typed_mem_open*(a1: cstring, a2, a3: cint): cint {.
   importc, header: "<sys/mman.h>".}
-proc shm_open*(a1: cstring, a2: cint, a3: Tmode): cint {.
+proc shm_open*(a1: cstring, a2: cint, a3: Mode): cint {.
   importc, header: "<sys/mman.h>".}
 proc shm_unlink*(a1: cstring): cint {.importc, header: "<sys/mman.h>".}
 
-proc asctime*(a1: var ttm): cstring{.importc, header: "<time.h>".}
-
-proc asctime_r*(a1: var ttm, a2: cstring): cstring {.importc, header: "<time.h>".}
-proc clock*(): Tclock {.importc, header: "<time.h>".}
-proc clock_getcpuclockid*(a1: tpid, a2: var Tclockid): cint {.
-  importc, header: "<time.h>".}
-proc clock_getres*(a1: Tclockid, a2: var Ttimespec): cint {.
-  importc, header: "<time.h>".}
-proc clock_gettime*(a1: Tclockid, a2: var Ttimespec): cint {.
-  importc, header: "<time.h>".}
-proc clock_nanosleep*(a1: Tclockid, a2: cint, a3: var Ttimespec,
-               a4: var Ttimespec): cint {.importc, header: "<time.h>".}
-proc clock_settime*(a1: Tclockid, a2: var Ttimespec): cint {.
-  importc, header: "<time.h>".}
-
-proc ctime*(a1: var Ttime): cstring {.importc, header: "<time.h>".}
-proc ctime_r*(a1: var Ttime, a2: cstring): cstring {.importc, header: "<time.h>".}
-proc difftime*(a1, a2: Ttime): cdouble {.importc, header: "<time.h>".}
-proc getdate*(a1: cstring): ptr ttm {.importc, header: "<time.h>".}
-
-proc gmtime*(a1: var ttime): ptr ttm {.importc, header: "<time.h>".}
-proc gmtime_r*(a1: var ttime, a2: var ttm): ptr ttm {.importc, header: "<time.h>".}
-proc localtime*(a1: var ttime): ptr ttm {.importc, header: "<time.h>".}
-proc localtime_r*(a1: var ttime, a2: var ttm): ptr ttm {.importc, header: "<time.h>".}
-proc mktime*(a1: var ttm): ttime  {.importc, header: "<time.h>".}
-proc nanosleep*(a1, a2: var Ttimespec): cint {.importc, header: "<time.h>".}
+proc asctime*(a1: var Tm): cstring{.importc, header: "<time.h>".}
+
+proc asctime_r*(a1: var Tm, a2: cstring): cstring {.importc, header: "<time.h>".}
+proc clock*(): Clock {.importc, header: "<time.h>", sideEffect.}
+proc clock_getcpuclockid*(a1: Pid, a2: var ClockId): cint {.
+  importc, header: "<time.h>", sideEffect.}
+proc clock_getres*(a1: ClockId, a2: var Timespec): cint {.
+  importc, header: "<time.h>", sideEffect.}
+proc clock_gettime*(a1: ClockId, a2: var Timespec): cint {.
+  importc, header: "<time.h>", sideEffect.}
+proc clock_nanosleep*(a1: ClockId, a2: cint, a3: var Timespec,
+               a4: var Timespec): cint {.importc, header: "<time.h>", sideEffect.}
+proc clock_settime*(a1: ClockId, a2: var Timespec): cint {.
+  importc, header: "<time.h>", sideEffect.}
+
+proc `==`*(a, b: Time): bool {.borrow.}
+proc `-`*(a, b: Time): Time {.borrow.}
+proc ctime*(a1: var Time): cstring {.importc, header: "<time.h>".}
+proc ctime_r*(a1: var Time, a2: cstring): cstring {.importc, header: "<time.h>".}
+proc difftime*(a1, a2: Time): cdouble {.importc, header: "<time.h>".}
+proc getdate*(a1: cstring): ptr Tm {.importc, header: "<time.h>".}
+proc gmtime*(a1: var Time): ptr Tm {.importc, header: "<time.h>".}
+proc gmtime_r*(a1: var Time, a2: var Tm): ptr Tm {.importc, header: "<time.h>".}
+proc localtime*(a1: var Time): ptr Tm {.importc, header: "<time.h>".}
+proc localtime_r*(a1: var Time, a2: var Tm): ptr Tm {.importc, header: "<time.h>".}
+proc mktime*(a1: var Tm): Time  {.importc, header: "<time.h>".}
+proc timegm*(a1: var Tm): Time  {.importc, header: "<time.h>".}
+proc nanosleep*(a1, a2: var Timespec): cint {.importc, header: "<time.h>", sideEffect.}
 proc strftime*(a1: cstring, a2: int, a3: cstring,
-           a4: var ttm): int {.importc, header: "<time.h>".}
-proc strptime*(a1, a2: cstring, a3: var ttm): cstring {.importc, header: "<time.h>".}
-proc time*(a1: var Ttime): ttime {.importc, header: "<time.h>".}
-proc timer_create*(a1: var Tclockid, a2: var Tsigevent,
-               a3: var Ttimer): cint {.importc, header: "<time.h>".}
-proc timer_delete*(a1: var Ttimer): cint {.importc, header: "<time.h>".}
-proc timer_gettime*(a1: Ttimer, a2: var Titimerspec): cint {.
+           a4: var Tm): int {.importc, header: "<time.h>".}
+proc strptime*(a1, a2: cstring, a3: var Tm): cstring {.importc, header: "<time.h>".}
+proc time*(a1: var Time): Time {.importc, header: "<time.h>", sideEffect.}
+proc timer_create*(a1: ClockId, a2: var SigEvent,
+               a3: var Timer): cint {.importc, header: "<time.h>".}
+proc timer_delete*(a1: Timer): cint {.importc, header: "<time.h>".}
+proc timer_gettime*(a1: Timer, a2: var Itimerspec): cint {.
   importc, header: "<time.h>".}
-proc timer_getoverrun*(a1: Ttimer): cint {.importc, header: "<time.h>".}
-proc timer_settime*(a1: Ttimer, a2: cint, a3: var Titimerspec,
-               a4: var titimerspec): cint {.importc, header: "<time.h>".}
+proc timer_getoverrun*(a1: Timer): cint {.importc, header: "<time.h>".}
+proc timer_settime*(a1: Timer, a2: cint, a3: var Itimerspec,
+               a4: var Itimerspec): cint {.importc, header: "<time.h>".}
 proc tzset*() {.importc, header: "<time.h>".}
 
 
-proc wait*(a1: var cint): tpid {.importc, header: "<sys/wait.h>".}
-proc waitid*(a1: cint, a2: tid, a3: var Tsiginfo, a4: cint): cint {.
-  importc, header: "<sys/wait.h>".}
-proc waitpid*(a1: tpid, a2: var cint, a3: cint): tpid {.
-  importc, header: "<sys/wait.h>".}
+proc wait*(a1: ptr cint): Pid {.importc, discardable, header: "<sys/wait.h>", sideEffect.}
+proc waitid*(a1: cint, a2: Id, a3: var SigInfo, a4: cint): cint {.
+  importc, header: "<sys/wait.h>", sideEffect.}
+proc waitpid*(a1: Pid, a2: var cint, a3: cint): Pid {.
+  importc, header: "<sys/wait.h>", sideEffect.}
+
+type Rusage* {.importc: "struct rusage", header: "<sys/resource.h>",
+               bycopy.} = object
+  ru_utime*, ru_stime*: Timeval                       # User and system time
+  ru_maxrss*, ru_ixrss*, ru_idrss*, ru_isrss*,        # memory sizes
+    ru_minflt*, ru_majflt*, ru_nswap*,                # paging activity
+    ru_inblock*, ru_oublock*, ru_msgsnd*, ru_msgrcv*, # IO activity
+    ru_nsignals*, ru_nvcsw*, ru_nivcsw*: clong        # switching activity
+
+proc wait4*(pid: Pid, status: ptr cint, options: cint, rusage: ptr Rusage): Pid
+  {.importc, header: "<sys/wait.h>", sideEffect.}
+
+const
+  RUSAGE_SELF* = cint(0)
+  RUSAGE_CHILDREN* = cint(-1)
+  RUSAGE_THREAD* = cint(1)    # This one is less std; Linux, BSD agree though.
+
+# This can only fail if `who` is invalid or `rusage` ptr is invalid.
+proc getrusage*(who: cint, rusage: ptr Rusage): cint
+  {.importc, header: "<sys/resource.h>", discardable.}
 
 proc bsd_signal*(a1: cint, a2: proc (x: pointer) {.noconv.}) {.
   importc, header: "<signal.h>".}
-proc kill*(a1: Tpid, a2: cint): cint {.importc, header: "<signal.h>".}
-proc killpg*(a1: Tpid, a2: cint): cint {.importc, header: "<signal.h>".}
-proc pthread_kill*(a1: tpthread, a2: cint): cint {.importc, header: "<signal.h>".}
-proc pthread_sigmask*(a1: cint, a2, a3: var Tsigset): cint {.
+proc kill*(a1: Pid, a2: cint): cint {.importc, header: "<signal.h>", sideEffect.}
+proc killpg*(a1: Pid, a2: cint): cint {.importc, header: "<signal.h>", sideEffect.}
+proc pthread_kill*(a1: Pthread, a2: cint): cint {.importc, header: "<signal.h>".}
+proc pthread_sigmask*(a1: cint, a2, a3: var Sigset): cint {.
   importc, header: "<signal.h>".}
 proc `raise`*(a1: cint): cint {.importc, header: "<signal.h>".}
-proc sigaction*(a1: cint, a2, a3: var Tsigaction): cint {.
+proc sigaction*(a1: cint, a2, a3: var Sigaction): cint {.
+  importc, header: "<signal.h>".}
+
+proc sigaction*(a1: cint, a2: var Sigaction; a3: ptr Sigaction = nil): cint {.
   importc, header: "<signal.h>".}
-proc sigaddset*(a1: var Tsigset, a2: cint): cint {.importc, header: "<signal.h>".}
-proc sigaltstack*(a1, a2: var Tstack): cint {.importc, header: "<signal.h>".}
-proc sigdelset*(a1: var Tsigset, a2: cint): cint {.importc, header: "<signal.h>".}
-proc sigemptyset*(a1: var Tsigset): cint {.importc, header: "<signal.h>".}
-proc sigfillset*(a1: var Tsigset): cint {.importc, header: "<signal.h>".}
+
+proc sigaddset*(a1: var Sigset, a2: cint): cint {.importc, header: "<signal.h>".}
+proc sigaltstack*(a1, a2: var Stack): cint {.importc, header: "<signal.h>".}
+proc sigdelset*(a1: var Sigset, a2: cint): cint {.importc, header: "<signal.h>".}
+proc sigemptyset*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
+proc sigfillset*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
 proc sighold*(a1: cint): cint {.importc, header: "<signal.h>".}
 proc sigignore*(a1: cint): cint {.importc, header: "<signal.h>".}
 proc siginterrupt*(a1, a2: cint): cint {.importc, header: "<signal.h>".}
-proc sigismember*(a1: var Tsigset, a2: cint): cint {.importc, header: "<signal.h>".}
-proc signal*(a1: cint, a2: proc (x: cint) {.noconv.}) {.
+proc sigismember*(a1: var Sigset, a2: cint): cint {.importc, header: "<signal.h>".}
+proc signal*(a1: cint, a2: Sighandler) {.
   importc, header: "<signal.h>".}
 proc sigpause*(a1: cint): cint {.importc, header: "<signal.h>".}
-proc sigpending*(a1: var tsigset): cint {.importc, header: "<signal.h>".}
-proc sigprocmask*(a1: cint, a2, a3: var tsigset): cint {.
+proc sigpending*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
+proc sigprocmask*(a1: cint, a2, a3: var Sigset): cint {.
   importc, header: "<signal.h>".}
-proc sigqueue*(a1: tpid, a2: cint, a3: Tsigval): cint {.
+proc sigqueue*(a1: Pid, a2: cint, a3: SigVal): cint {.
   importc, header: "<signal.h>".}
 proc sigrelse*(a1: cint): cint {.importc, header: "<signal.h>".}
 proc sigset*(a1: int, a2: proc (x: cint) {.noconv.}) {.
   importc, header: "<signal.h>".}
-proc sigsuspend*(a1: var Tsigset): cint {.importc, header: "<signal.h>".}
-proc sigtimedwait*(a1: var Tsigset, a2: var tsiginfo, 
-                   a3: var ttimespec): cint {.importc, header: "<signal.h>".}
-proc sigwait*(a1: var Tsigset, a2: var cint): cint {.
+proc sigsuspend*(a1: var Sigset): cint {.importc, header: "<signal.h>".}
+
+when defined(android):
+  proc syscall(arg: clong): clong {.varargs, importc: "syscall", header: "<unistd.h>".}
+  var NR_rt_sigtimedwait {.importc: "__NR_rt_sigtimedwait", header: "<sys/syscall.h>".}: clong
+  var NSIGMAX {.importc: "NSIG", header: "<signal.h>".}: clong
+
+  proc sigtimedwait*(a1: var Sigset, a2: var SigInfo, a3: var Timespec): cint =
+    result = cint(syscall(NR_rt_sigtimedwait, addr(a1), addr(a2), addr(a3), NSIGMAX div 8))
+else:
+  proc sigtimedwait*(a1: var Sigset, a2: var SigInfo,
+                     a3: var Timespec): cint {.importc, header: "<signal.h>".}
+
+when defined(sunos) or defined(solaris):
+  # The following compile time flag is needed on Illumos/Solaris to use the POSIX
+  # `sigwait` implementation. See the documentation here:
+  # https://docs.oracle.com/cd/E19455-01/806-5257/6je9h033k/index.html
+  # https://www.illumos.org/man/2/sigwait
+  {.passc: "-D_POSIX_PTHREAD_SEMANTICS".}
+
+proc sigwait*(a1: var Sigset, a2: var cint): cint {.
   importc, header: "<signal.h>".}
-proc sigwaitinfo*(a1: var Tsigset, a2: var tsiginfo): cint {.
+proc sigwaitinfo*(a1: var Sigset, a2: var SigInfo): cint {.
   importc, header: "<signal.h>".}
 
-
-proc catclose*(a1: Tnl_catd): cint {.importc, header: "<nl_types.h>".}
-proc catgets*(a1: Tnl_catd, a2, a3: cint, a4: cstring): cstring {.
-  importc, header: "<nl_types.h>".}
-proc catopen*(a1: cstring, a2: cint): Tnl_catd {.
-  importc, header: "<nl_types.h>".}
+when not defined(nintendoswitch):
+  proc catclose*(a1: Nl_catd): cint {.importc, header: "<nl_types.h>".}
+  proc catgets*(a1: Nl_catd, a2, a3: cint, a4: cstring): cstring {.
+    importc, header: "<nl_types.h>".}
+  proc catopen*(a1: cstring, a2: cint): Nl_catd {.
+    importc, header: "<nl_types.h>".}
 
 proc sched_get_priority_max*(a1: cint): cint {.importc, header: "<sched.h>".}
 proc sched_get_priority_min*(a1: cint): cint {.importc, header: "<sched.h>".}
-proc sched_getparam*(a1: tpid, a2: var Tsched_param): cint {.
+proc sched_getparam*(a1: Pid, a2: var Sched_param): cint {.
   importc, header: "<sched.h>".}
-proc sched_getscheduler*(a1: tpid): cint {.importc, header: "<sched.h>".}
-proc sched_rr_get_interval*(a1: tpid, a2: var Ttimespec): cint {.
+proc sched_getscheduler*(a1: Pid): cint {.importc, header: "<sched.h>".}
+proc sched_rr_get_interval*(a1: Pid, a2: var Timespec): cint {.
   importc, header: "<sched.h>".}
-proc sched_setparam*(a1: tpid, a2: var Tsched_param): cint {.
+proc sched_setparam*(a1: Pid, a2: var Sched_param): cint {.
   importc, header: "<sched.h>".}
-proc sched_setscheduler*(a1: tpid, a2: cint, a3: var tsched_param): cint {.
+proc sched_setscheduler*(a1: Pid, a2: cint, a3: var Sched_param): cint {.
   importc, header: "<sched.h>".}
 proc sched_yield*(): cint {.importc, header: "<sched.h>".}
 
-proc strerror*(errnum: cint): cstring {.importc, header: "<string.h>".}
+proc hstrerror*(herrnum: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>".}
 
-proc FD_CLR*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
-proc FD_ISSET*(a1: cint, a2: var Tfd_set): cint {.
+proc FD_CLR*(a1: cint, a2: var TFdSet) {.importc, header: "<sys/select.h>".}
+proc FD_ISSET*(a1: cint | SocketHandle, a2: var TFdSet): cint {.
   importc, header: "<sys/select.h>".}
-proc FD_SET*(a1: cint, a2: var Tfd_set) {.importc, header: "<sys/select.h>".}
-proc FD_ZERO*(a1: var Tfd_set) {.importc, header: "<sys/select.h>".}
+proc FD_SET*(a1: cint | SocketHandle, a2: var TFdSet) {.
+  importc: "FD_SET", header: "<sys/select.h>".}
+proc FD_ZERO*(a1: var TFdSet) {.importc, header: "<sys/select.h>".}
 
-proc pselect*(a1: cint, a2, a3, a4: ptr Tfd_set, a5: ptr ttimespec,
-         a6: var Tsigset): cint  {.importc, header: "<sys/select.h>".}
-proc select*(a1: cint, a2, a3, a4: ptr Tfd_set, a5: ptr ttimeval): cint {.
+proc pselect*(a1: cint, a2, a3, a4: ptr TFdSet, a5: ptr Timespec,
+         a6: var Sigset): cint  {.importc, header: "<sys/select.h>".}
+proc select*(a1: cint | SocketHandle, a2, a3, a4: ptr TFdSet, a5: ptr Timeval): cint {.
              importc, header: "<sys/select.h>".}
 
 when hasSpawnH:
-  proc posix_spawn*(a1: var tpid, a2: cstring,
+  proc posix_spawn*(a1: var Pid, a2: cstring,
             a3: var Tposix_spawn_file_actions,
-            a4: var Tposix_spawnattr, 
+            a4: var Tposix_spawnattr,
             a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawn_file_actions_addclose*(a1: var tposix_spawn_file_actions,
+  proc posix_spawn_file_actions_addclose*(a1: var Tposix_spawn_file_actions,
             a2: cint): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawn_file_actions_adddup2*(a1: var tposix_spawn_file_actions,
+  proc posix_spawn_file_actions_adddup2*(a1: var Tposix_spawn_file_actions,
             a2, a3: cint): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawn_file_actions_addopen*(a1: var tposix_spawn_file_actions,
-            a2: cint, a3: cstring, a4: cint, a5: tmode): cint {.
+  proc posix_spawn_file_actions_addopen*(a1: var Tposix_spawn_file_actions,
+            a2: cint, a3: cstring, a4: cint, a5: Mode): cint {.
             importc, header: "<spawn.h>".}
   proc posix_spawn_file_actions_destroy*(
-    a1: var tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
+    a1: var Tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
   proc posix_spawn_file_actions_init*(
-    a1: var tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_destroy*(a1: var tposix_spawnattr): cint {.
+    a1: var Tposix_spawn_file_actions): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnattr_destroy*(a1: var Tposix_spawnattr): cint {.
     importc, header: "<spawn.h>".}
-  proc posix_spawnattr_getsigdefault*(a1: var tposix_spawnattr,
-            a2: var Tsigset): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_getflags*(a1: var tposix_spawnattr,
+  proc posix_spawnattr_getsigdefault*(a1: var Tposix_spawnattr,
+            a2: var Sigset): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnattr_getflags*(a1: var Tposix_spawnattr,
             a2: var cshort): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_getpgroup*(a1: var tposix_spawnattr,
-            a2: var tpid): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_getschedparam*(a1: var tposix_spawnattr,
-            a2: var tsched_param): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_getschedpolicy*(a1: var tposix_spawnattr,
+  proc posix_spawnattr_getpgroup*(a1: var Tposix_spawnattr,
+            a2: var Pid): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnattr_getschedparam*(a1: var Tposix_spawnattr,
+            a2: var Sched_param): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnattr_getschedpolicy*(a1: var Tposix_spawnattr,
             a2: var cint): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_getsigmask*(a1: var tposix_spawnattr,
-            a2: var tsigset): cint {.importc, header: "<spawn.h>".}
-  
-  proc posix_spawnattr_init*(a1: var tposix_spawnattr): cint {.
+  proc posix_spawnattr_getsigmask*(a1: var Tposix_spawnattr,
+            a2: var Sigset): cint {.importc, header: "<spawn.h>".}
+
+  proc posix_spawnattr_init*(a1: var Tposix_spawnattr): cint {.
     importc, header: "<spawn.h>".}
-  proc posix_spawnattr_setsigdefault*(a1: var tposix_spawnattr,
-            a2: var tsigset): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_setflags*(a1: var tposix_spawnattr, a2: cshort): cint {.
+  proc posix_spawnattr_setsigdefault*(a1: var Tposix_spawnattr,
+            a2: var Sigset): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnattr_setflags*(a1: var Tposix_spawnattr, a2: cint): cint {.
     importc, header: "<spawn.h>".}
-  proc posix_spawnattr_setpgroup*(a1: var tposix_spawnattr, a2: tpid): cint {.
+  proc posix_spawnattr_setpgroup*(a1: var Tposix_spawnattr, a2: Pid): cint {.
     importc, header: "<spawn.h>".}
-  
-  proc posix_spawnattr_setschedparam*(a1: var tposix_spawnattr,
-            a2: var tsched_param): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnattr_setschedpolicy*(a1: var tposix_spawnattr, 
+
+  proc posix_spawnattr_setschedparam*(a1: var Tposix_spawnattr,
+            a2: var Sched_param): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnattr_setschedpolicy*(a1: var Tposix_spawnattr,
                                        a2: cint): cint {.
                                        importc, header: "<spawn.h>".}
-  proc posix_spawnattr_setsigmask*(a1: var tposix_spawnattr,
-            a2: var tsigset): cint {.importc, header: "<spawn.h>".}
-  proc posix_spawnp*(a1: var tpid, a2: cstring,
-            a3: var tposix_spawn_file_actions,
-            a4: var tposix_spawnattr,
+  proc posix_spawnattr_setsigmask*(a1: var Tposix_spawnattr,
+            a2: var Sigset): cint {.importc, header: "<spawn.h>".}
+  proc posix_spawnp*(a1: var Pid, a2: cstring,
+            a3: var Tposix_spawn_file_actions,
+            a4: var Tposix_spawnattr,
             a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".}
 
-proc getcontext*(a1: var Tucontext): cint {.importc, header: "<ucontext.h>".}
-proc makecontext*(a1: var Tucontext, a4: proc (){.noconv.}, a3: cint) {.
-  varargs, importc, header: "<ucontext.h>".}
-proc setcontext*(a1: var Tucontext): cint {.importc, header: "<ucontext.h>".}
-proc swapcontext*(a1, a2: var Tucontext): cint {.importc, header: "<ucontext.h>".}
+when not defined(nintendoswitch):
+  proc getcontext*(a1: var Ucontext): cint {.importc, header: "<ucontext.h>".}
+  proc makecontext*(a1: var Ucontext, a4: proc (){.noconv.}, a3: cint) {.
+    varargs, importc, header: "<ucontext.h>".}
+  proc setcontext*(a1: var Ucontext): cint {.importc, header: "<ucontext.h>".}
+  proc swapcontext*(a1, a2: var Ucontext): cint {.importc, header: "<ucontext.h>".}
 
-proc readv*(a1: cint, a2: ptr TIOVec, a3: cint): int {.
+proc readv*(a1: cint, a2: ptr IOVec, a3: cint): int {.
   importc, header: "<sys/uio.h>".}
-proc writev*(a1: cint, a2: ptr TIOVec, a3: cint): int {.
+proc writev*(a1: cint, a2: ptr IOVec, a3: cint): int {.
   importc, header: "<sys/uio.h>".}
 
 proc CMSG_DATA*(cmsg: ptr Tcmsghdr): cstring {.
   importc, header: "<sys/socket.h>".}
 
-proc CMSG_NXTHDR*(mhdr: ptr TMsgHdr, cmsg: ptr TCMsgHdr): ptr TCmsgHdr {.
+proc CMSG_NXTHDR*(mhdr: ptr Tmsghdr, cmsg: ptr Tcmsghdr): ptr Tcmsghdr {.
   importc, header: "<sys/socket.h>".}
 
-proc CMSG_FIRSTHDR*(mhdr: ptr TMsgHdr): ptr TCMsgHdr {.
+proc CMSG_FIRSTHDR*(mhdr: ptr Tmsghdr): ptr Tcmsghdr {.
   importc, header: "<sys/socket.h>".}
 
-proc accept*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
+proc CMSG_SPACE*(len: csize_t): csize_t {.
   importc, header: "<sys/socket.h>".}
 
-proc bindSocket*(a1: cint, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
-  importc: "bind", header: "<sys/socket.h>".}
-  ## is Posix's ``bind``, because ``bind`` is a reserved word
-  
-proc connect*(a1: cint, a2: ptr Tsockaddr, a3: Tsocklen): cint {.
-  importc, header: "<sys/socket.h>".}
-proc getpeername*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
-  importc, header: "<sys/socket.h>".}
-proc getsockname*(a1: cint, a2: ptr Tsockaddr, a3: ptr Tsocklen): cint {.
+proc CMSG_LEN*(len: csize_t): csize_t {.
   importc, header: "<sys/socket.h>".}
 
-proc getsockopt*(a1, a2, a3: cint, a4: pointer, a5: ptr Tsocklen): cint {.
-  importc, header: "<sys/socket.h>".}
+const
+  INVALID_SOCKET* = SocketHandle(-1)
 
-proc listen*(a1, a2: cint): cint {.
-  importc, header: "<sys/socket.h>".}
-proc recv*(a1: cint, a2: pointer, a3: int, a4: cint): int {.
-  importc, header: "<sys/socket.h>".}
-proc recvfrom*(a1: cint, a2: pointer, a3: int, a4: cint,
-        a5: ptr Tsockaddr, a6: ptr Tsocklen): int {.
-  importc, header: "<sys/socket.h>".}
-proc recvmsg*(a1: cint, a2: ptr Tmsghdr, a3: cint): int {.
+proc `==`*(x, y: SocketHandle): bool {.borrow.}
+
+proc accept*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): SocketHandle {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+
+when defined(linux) or defined(bsd) or defined(nuttx):
+  proc accept4*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen,
+                flags: cint): SocketHandle {.importc, header: "<sys/socket.h>".}
+
+proc bindSocket*(a1: SocketHandle, a2: ptr SockAddr, a3: SockLen): cint {.
+  importc: "bind", header: "<sys/socket.h>".}
+  ## is Posix's `bind`, because `bind` is a reserved word
+
+proc connect*(a1: SocketHandle, a2: ptr SockAddr, a3: SockLen): cint {.
   importc, header: "<sys/socket.h>".}
-proc send*(a1: cint, a2: pointer, a3: int, a4: cint): int {.
+proc getpeername*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): cint {.
   importc, header: "<sys/socket.h>".}
-proc sendmsg*(a1: cint, a2: ptr Tmsghdr, a3: cint): int {.
+proc getsockname*(a1: SocketHandle, a2: ptr SockAddr, a3: ptr SockLen): cint {.
   importc, header: "<sys/socket.h>".}
-proc sendto*(a1: cint, a2: pointer, a3: int, a4: cint, a5: ptr Tsockaddr,
-             a6: Tsocklen): int {.
+
+proc getsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: ptr SockLen): cint {.
   importc, header: "<sys/socket.h>".}
-proc setsockopt*(a1, a2, a3: cint, a4: pointer, a5: Tsocklen): cint {.
+
+proc listen*(a1: SocketHandle, a2: cint): cint {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc recv*(a1: SocketHandle, a2: pointer, a3: int, a4: cint): int {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc recvfrom*(a1: SocketHandle, a2: pointer, a3: int, a4: cint,
+        a5: ptr SockAddr, a6: ptr SockLen): int {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc recvmsg*(a1: SocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc send*(a1: SocketHandle, a2: pointer, a3: int, a4: cint): int {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc sendmsg*(a1: SocketHandle, a2: ptr Tmsghdr, a3: cint): int {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc sendto*(a1: SocketHandle, a2: pointer, a3: int, a4: cint, a5: ptr SockAddr,
+             a6: SockLen): int {.
+  importc, header: "<sys/socket.h>", sideEffect.}
+proc setsockopt*(a1: SocketHandle, a2, a3: cint, a4: pointer, a5: SockLen): cint {.
   importc, header: "<sys/socket.h>".}
-proc shutdown*(a1, a2: cint): cint {.
+proc shutdown*(a1: SocketHandle, a2: cint): cint {.
   importc, header: "<sys/socket.h>".}
-proc socket*(a1, a2, a3: cint): cint {.
+proc socket*(a1, a2, a3: cint): SocketHandle {.
   importc, header: "<sys/socket.h>".}
 proc sockatmark*(a1: cint): cint {.
   importc, header: "<sys/socket.h>".}
@@ -2449,40 +1009,46 @@ proc if_indextoname*(a1: cint, a2: cstring): cstring {.
 proc if_nameindex*(): ptr Tif_nameindex {.importc, header: "<net/if.h>".}
 proc if_freenameindex*(a1: ptr Tif_nameindex) {.importc, header: "<net/if.h>".}
 
-proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_UNSPECIFIED* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Unspecified address.
-proc IN6_IS_ADDR_LOOPBACK* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_LOOPBACK* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Loopback address.
-proc IN6_IS_ADDR_MULTICAST* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_MULTICAST* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Multicast address.
-proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_LINKLOCAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Unicast link-local address.
-proc IN6_IS_ADDR_SITELOCAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_SITELOCAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Unicast site-local address.
-proc IN6_IS_ADDR_V4MAPPED* (a1: ptr TIn6Addr): cint {.
-  importc, header: "<netinet/in.h>".}
-  ## IPv4 mapped address.
-proc IN6_IS_ADDR_V4COMPAT* (a1: ptr TIn6Addr): cint {.
+when defined(lwip):
+  proc IN6_IS_ADDR_V4MAPPED*(ipv6_address: ptr In6Addr): cint =
+    var bits32: ptr array[4, uint32] = cast[ptr array[4, uint32]](ipv6_address)
+    return (bits32[1] == 0'u32 and bits32[2] == htonl(0x0000FFFF)).cint
+else:
+  proc IN6_IS_ADDR_V4MAPPED* (a1: ptr In6Addr): cint {.
+    importc, header: "<netinet/in.h>".}
+    ## IPv4 mapped address.
+
+proc IN6_IS_ADDR_V4COMPAT* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## IPv4-compatible address.
-proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_MC_NODELOCAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Multicast node-local address.
-proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_MC_LINKLOCAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Multicast link-local address.
-proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_MC_SITELOCAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Multicast site-local address.
-proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_MC_ORGLOCAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Multicast organization-local address.
-proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr TIn6Addr): cint {.
+proc IN6_IS_ADDR_MC_GLOBAL* (a1: ptr In6Addr): cint {.
   importc, header: "<netinet/in.h>".}
   ## Multicast global address.
 
@@ -2490,44 +1056,121 @@ proc endhostent*() {.importc, header: "<netdb.h>".}
 proc endnetent*() {.importc, header: "<netdb.h>".}
 proc endprotoent*() {.importc, header: "<netdb.h>".}
 proc endservent*() {.importc, header: "<netdb.h>".}
-proc freeaddrinfo*(a1: ptr Taddrinfo) {.importc, header: "<netdb.h>".}
+proc freeAddrInfo*(a1: ptr AddrInfo) {.importc: "freeaddrinfo", header: "<netdb.h>".}
 
-proc gai_strerror*(a1: cint): cstring {.importc, header: "<netdb.h>".}
+proc gai_strerror*(a1: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>".}
 
-proc getaddrinfo*(a1, a2: cstring, a3: ptr TAddrInfo, 
-                  a4: var ptr TAddrInfo): cint {.importc, header: "<netdb.h>".}
-                  
-proc gethostbyaddr*(a1: pointer, a2: Tsocklen, a3: cint): ptr THostent {.
-                    importc, header: "<netdb.h>".}
-proc gethostbyname*(a1: cstring): ptr THostent {.importc, header: "<netdb.h>".}
-proc gethostent*(): ptr THostent {.importc, header: "<netdb.h>".}
+proc getaddrinfo*(a1, a2: cstring, a3: ptr AddrInfo,
+                  a4: var ptr AddrInfo): cint {.importc, header: "<netdb.h>".}
 
-proc getnameinfo*(a1: ptr Tsockaddr, a2: Tsocklen,
-                  a3: cstring, a4: Tsocklen, a5: cstring,
-                  a6: Tsocklen, a7: cint): cint {.importc, header: "<netdb.h>".}
+when not defined(android4):
+  proc gethostbyaddr*(a1: pointer, a2: SockLen, a3: cint): ptr Hostent {.
+                      importc, header: "<netdb.h>".}
+else:
+  proc gethostbyaddr*(a1: cstring, a2: cint, a3: cint): ptr Hostent {.
+                      importc, header: "<netdb.h>".}
+proc gethostbyname*(a1: cstring): ptr Hostent {.importc, header: "<netdb.h>".}
+proc gethostent*(): ptr Hostent {.importc, header: "<netdb.h>".}
 
-proc getnetbyaddr*(a1: int32, a2: cint): ptr TNetent {.importc, header: "<netdb.h>".}
-proc getnetbyname*(a1: cstring): ptr TNetent {.importc, header: "<netdb.h>".}
-proc getnetent*(): ptr TNetent {.importc, header: "<netdb.h>".}
+proc getnameinfo*(a1: ptr SockAddr, a2: SockLen,
+                  a3: cstring, a4: SockLen, a5: cstring,
+                  a6: SockLen, a7: cint): cint {.importc, header: "<netdb.h>".}
 
-proc getprotobyname*(a1: cstring): ptr TProtoent {.importc, header: "<netdb.h>".}
-proc getprotobynumber*(a1: cint): ptr TProtoent {.importc, header: "<netdb.h>".}
-proc getprotoent*(): ptr TProtoent {.importc, header: "<netdb.h>".}
+proc getnetbyaddr*(a1: int32, a2: cint): ptr Tnetent {.importc, header: "<netdb.h>".}
+proc getnetbyname*(a1: cstring): ptr Tnetent {.importc, header: "<netdb.h>".}
+proc getnetent*(): ptr Tnetent {.importc, header: "<netdb.h>".}
 
-proc getservbyname*(a1, a2: cstring): ptr TServent {.importc, header: "<netdb.h>".}
-proc getservbyport*(a1: cint, a2: cstring): ptr TServent {.
+proc getprotobyname*(a1: cstring): ptr Protoent {.importc, header: "<netdb.h>".}
+proc getprotobynumber*(a1: cint): ptr Protoent {.importc, header: "<netdb.h>".}
+proc getprotoent*(): ptr Protoent {.importc, header: "<netdb.h>".}
+
+proc getservbyname*(a1, a2: cstring): ptr Servent {.importc, header: "<netdb.h>".}
+proc getservbyport*(a1: cint, a2: cstring): ptr Servent {.
   importc, header: "<netdb.h>".}
-proc getservent*(): ptr TServent {.importc, header: "<netdb.h>".}
+proc getservent*(): ptr Servent {.importc, header: "<netdb.h>".}
 
 proc sethostent*(a1: cint) {.importc, header: "<netdb.h>".}
 proc setnetent*(a1: cint) {.importc, header: "<netdb.h>".}
 proc setprotoent*(a1: cint) {.importc, header: "<netdb.h>".}
 proc setservent*(a1: cint) {.importc, header: "<netdb.h>".}
 
-proc poll*(a1: ptr Tpollfd, a2: Tnfds, a3: int): cint {.
-  importc, header: "<poll.h>".}
+when not defined(lwip):
+  proc poll*(a1: ptr TPollfd, a2: Tnfds, a3: int): cint {.
+    importc, header: "<poll.h>", sideEffect.}
 
-proc realpath*(name, resolved: CString): CString {.
+proc realpath*(name, resolved: cstring): cstring {.
   importc: "realpath", header: "<stdlib.h>".}
 
+proc mkstemp*(tmpl: cstring): cint {.importc, header: "<stdlib.h>", sideEffect.}
+  ## Creates a unique temporary file.
+  ##
+  ## .. warning:: The `tmpl` argument is written to by `mkstemp` and thus
+  ##   can't be a string literal. If in doubt make a copy of the cstring before
+  ##   passing it in.
+
+proc mkstemps*(tmpl: cstring, suffixlen: int): cint {.importc, header: "<stdlib.h>", sideEffect.}
+  ## Creates a unique temporary file.
+  ##
+  ## .. warning:: The `tmpl` argument is written to by `mkstemps` and thus
+  ##   can't be a string literal. If in doubt make a copy of the cstring before
+  ##   passing it in.
+
+proc mkdtemp*(tmpl: cstring): pointer {.importc, header: "<stdlib.h>", sideEffect.}
+
+when defined(linux) or defined(bsd) or defined(osx):
+  proc mkostemp*(tmpl: cstring, oflags: cint): cint {.importc, header: "<stdlib.h>", sideEffect.}
+  proc mkostemps*(tmpl: cstring, suffixlen: cint, oflags: cint): cint {.importc, header: "<stdlib.h>", sideEffect.}
+
+  proc posix_memalign*(memptr: pointer, alignment: csize_t, size: csize_t): cint {.importc, header: "<stdlib.h>".}
+
+proc utimes*(path: cstring, times: ptr array[2, Timeval]): int {.
+  importc: "utimes", header: "<sys/time.h>", sideEffect.}
+  ## Sets file access and modification times.
+  ##
+  ## Pass the filename and an array of times to set the access and modification
+  ## times respectively. If you pass nil as the array both attributes will be
+  ## set to the current time.
+  ##
+  ## Returns zero on success.
+  ##
+  ## For more information read http://www.unix.com/man-page/posix/3/utimes/.
+
+proc handle_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.importc: "signal", header: "<signal.h>".}
+
+template onSignal*(signals: varargs[cint], body: untyped) =
+  ## Setup code to be executed when Unix signals are received. The
+  ## currently handled signal is injected as `sig` into the calling
+  ## scope.
+  ##
+  ## Example:
+  ##   ```Nim
+  ##   from std/posix import SIGINT, SIGTERM, onSignal
+  ##   onSignal(SIGINT, SIGTERM):
+  ##     echo "bye from signal ", sig
+  ##   ```
+
+  for s in signals:
+    handle_signal(s,
+      proc (signal: cint) {.noconv.} =
+        let sig {.inject.} = signal
+        body
+    )
 
+type
+  RLimit* {.importc: "struct rlimit",
+            header: "<sys/resource.h>", pure, final.} = object
+    rlim_cur*: int
+    rlim_max*: int
+  ## The getrlimit() and setrlimit() system calls get and set resource limits respectively.
+  ## Each resource has an associated soft and hard limit, as defined by the RLimit structure
+
+proc setrlimit*(resource: cint, rlp: var RLimit): cint {.
+  importc: "setrlimit", header: "<sys/resource.h>".}
+  ## The setrlimit() system calls sets resource limits.
+
+proc getrlimit*(resource: cint, rlp: var RLimit): cint {.
+  importc: "getrlimit", header: "<sys/resource.h>".}
+  ## The getrlimit() system call gets resource limits.
+
+when defined(nimHasStyleChecks):
+  {.pop.} # {.push styleChecks: off.}
diff --git a/lib/posix/posix_freertos_consts.nim b/lib/posix/posix_freertos_consts.nim
new file mode 100644
index 000000000..0f0fc0aae
--- /dev/null
+++ b/lib/posix/posix_freertos_consts.nim
@@ -0,0 +1,506 @@
+# Generated by detect.nim
+
+
+
+# <errno.h>
+var E2BIG* {.importc: "E2BIG", header: "<errno.h>".}: cint
+var EACCES* {.importc: "EACCES", header: "<errno.h>".}: cint
+var EADDRINUSE* {.importc: "EADDRINUSE", header: "<errno.h>".}: cint
+var EADDRNOTAVAIL* {.importc: "EADDRNOTAVAIL", header: "<errno.h>".}: cint
+var EAFNOSUPPORT* {.importc: "EAFNOSUPPORT", header: "<errno.h>".}: cint
+var EAGAIN* {.importc: "EAGAIN", header: "<errno.h>".}: cint
+var EALREADY* {.importc: "EALREADY", header: "<errno.h>".}: cint
+var EBADF* {.importc: "EBADF", header: "<errno.h>".}: cint
+var EBADMSG* {.importc: "EBADMSG", header: "<errno.h>".}: cint
+var EBUSY* {.importc: "EBUSY", header: "<errno.h>".}: cint
+var ECANCELED* {.importc: "ECANCELED", header: "<errno.h>".}: cint
+var ECHILD* {.importc: "ECHILD", header: "<errno.h>".}: cint
+var ECONNABORTED* {.importc: "ECONNABORTED", header: "<errno.h>".}: cint
+var ECONNREFUSED* {.importc: "ECONNREFUSED", header: "<errno.h>".}: cint
+var ECONNRESET* {.importc: "ECONNRESET", header: "<errno.h>".}: cint
+var EDEADLK* {.importc: "EDEADLK", header: "<errno.h>".}: cint
+var EDESTADDRREQ* {.importc: "EDESTADDRREQ", header: "<errno.h>".}: cint
+var EDOM* {.importc: "EDOM", header: "<errno.h>".}: cint
+var EDQUOT* {.importc: "EDQUOT", header: "<errno.h>".}: cint
+var EEXIST* {.importc: "EEXIST", header: "<errno.h>".}: cint
+var EFAULT* {.importc: "EFAULT", header: "<errno.h>".}: cint
+var EFBIG* {.importc: "EFBIG", header: "<errno.h>".}: cint
+var EHOSTUNREACH* {.importc: "EHOSTUNREACH", header: "<errno.h>".}: cint
+var EIDRM* {.importc: "EIDRM", header: "<errno.h>".}: cint
+var EILSEQ* {.importc: "EILSEQ", header: "<errno.h>".}: cint
+var EINPROGRESS* {.importc: "EINPROGRESS", header: "<errno.h>".}: cint
+var EINTR* {.importc: "EINTR", header: "<errno.h>".}: cint
+var EINVAL* {.importc: "EINVAL", header: "<errno.h>".}: cint
+var EIO* {.importc: "EIO", header: "<errno.h>".}: cint
+var EISCONN* {.importc: "EISCONN", header: "<errno.h>".}: cint
+var EISDIR* {.importc: "EISDIR", header: "<errno.h>".}: cint
+var ELOOP* {.importc: "ELOOP", header: "<errno.h>".}: cint
+var EMFILE* {.importc: "EMFILE", header: "<errno.h>".}: cint
+var EMLINK* {.importc: "EMLINK", header: "<errno.h>".}: cint
+var EMSGSIZE* {.importc: "EMSGSIZE", header: "<errno.h>".}: cint
+var EMULTIHOP* {.importc: "EMULTIHOP", header: "<errno.h>".}: cint
+var ENAMETOOLONG* {.importc: "ENAMETOOLONG", header: "<errno.h>".}: cint
+var ENETDOWN* {.importc: "ENETDOWN", header: "<errno.h>".}: cint
+var ENETRESET* {.importc: "ENETRESET", header: "<errno.h>".}: cint
+var ENETUNREACH* {.importc: "ENETUNREACH", header: "<errno.h>".}: cint
+var ENFILE* {.importc: "ENFILE", header: "<errno.h>".}: cint
+var ENOBUFS* {.importc: "ENOBUFS", header: "<errno.h>".}: cint
+var ENODATA* {.importc: "ENODATA", header: "<errno.h>".}: cint
+var ENODEV* {.importc: "ENODEV", header: "<errno.h>".}: cint
+var ENOENT* {.importc: "ENOENT", header: "<errno.h>".}: cint
+var ENOEXEC* {.importc: "ENOEXEC", header: "<errno.h>".}: cint
+var ENOLCK* {.importc: "ENOLCK", header: "<errno.h>".}: cint
+var ENOLINK* {.importc: "ENOLINK", header: "<errno.h>".}: cint
+var ENOMEM* {.importc: "ENOMEM", header: "<errno.h>".}: cint
+var ENOMSG* {.importc: "ENOMSG", header: "<errno.h>".}: cint
+var ENOPROTOOPT* {.importc: "ENOPROTOOPT", header: "<errno.h>".}: cint
+var ENOSPC* {.importc: "ENOSPC", header: "<errno.h>".}: cint
+var ENOSR* {.importc: "ENOSR", header: "<errno.h>".}: cint
+var ENOSTR* {.importc: "ENOSTR", header: "<errno.h>".}: cint
+var ENOSYS* {.importc: "ENOSYS", header: "<errno.h>".}: cint
+var ENOTCONN* {.importc: "ENOTCONN", header: "<errno.h>".}: cint
+var ENOTDIR* {.importc: "ENOTDIR", header: "<errno.h>".}: cint
+var ENOTEMPTY* {.importc: "ENOTEMPTY", header: "<errno.h>".}: cint
+var ENOTSOCK* {.importc: "ENOTSOCK", header: "<errno.h>".}: cint
+var ENOTSUP* {.importc: "ENOTSUP", header: "<errno.h>".}: cint
+var ENOTTY* {.importc: "ENOTTY", header: "<errno.h>".}: cint
+var ENXIO* {.importc: "ENXIO", header: "<errno.h>".}: cint
+var EOPNOTSUPP* {.importc: "EOPNOTSUPP", header: "<errno.h>".}: cint
+var EOVERFLOW* {.importc: "EOVERFLOW", header: "<errno.h>".}: cint
+var EPERM* {.importc: "EPERM", header: "<errno.h>".}: cint
+var EPIPE* {.importc: "EPIPE", header: "<errno.h>".}: cint
+var EPROTO* {.importc: "EPROTO", header: "<errno.h>".}: cint
+var EPROTONOSUPPORT* {.importc: "EPROTONOSUPPORT", header: "<errno.h>".}: cint
+var EPROTOTYPE* {.importc: "EPROTOTYPE", header: "<errno.h>".}: cint
+var ERANGE* {.importc: "ERANGE", header: "<errno.h>".}: cint
+var EROFS* {.importc: "EROFS", header: "<errno.h>".}: cint
+var ESPIPE* {.importc: "ESPIPE", header: "<errno.h>".}: cint
+var ESRCH* {.importc: "ESRCH", header: "<errno.h>".}: cint
+var ESTALE* {.importc: "ESTALE", header: "<errno.h>".}: cint
+var ETIME* {.importc: "ETIME", header: "<errno.h>".}: cint
+var ETIMEDOUT* {.importc: "ETIMEDOUT", header: "<errno.h>".}: cint
+var ETXTBSY* {.importc: "ETXTBSY", header: "<errno.h>".}: cint
+var EWOULDBLOCK* {.importc: "EWOULDBLOCK", header: "<errno.h>".}: cint
+var EXDEV* {.importc: "EXDEV", header: "<errno.h>".}: cint
+
+# <sys/fcntl.h>
+var F_GETFD* {.importc: "F_GETFD", header: "<sys/fcntl.h>".}: cint
+# var F_SETFD* {.importc: "F_SETFD", header: "<sys/fcntl.h>".}: cint
+var F_GETFL* {.importc: "F_GETFL", header: "<sys/fcntl.h>".}: cint
+var F_SETFL* {.importc: "F_SETFL", header: "<sys/fcntl.h>".}: cint
+# var F_GETLK* {.importc: "F_GETLK", header: "<sys/fcntl.h>".}: cint
+# var F_SETLK* {.importc: "F_SETLK", header: "<sys/fcntl.h>".}: cint
+# var F_SETLKW* {.importc: "F_SETLKW", header: "<sys/fcntl.h>".}: cint
+# var F_GETOWN* {.importc: "F_GETOWN", header: "<sys/fcntl.h>".}: cint
+# var F_SETOWN* {.importc: "F_SETOWN", header: "<sys/fcntl.h>".}: cint
+# var FD_CLOEXEC* {.importc: "FD_CLOEXEC", header: "<sys/fcntl.h>".}: cint
+# var F_RDLCK* {.importc: "F_RDLCK", header: "<sys/fcntl.h>".}: cint
+# var F_UNLCK* {.importc: "F_UNLCK", header: "<sys/fcntl.h>".}: cint
+# var F_WRLCK* {.importc: "F_WRLCK", header: "<sys/fcntl.h>".}: cint
+var O_CREAT* {.importc: "O_CREAT", header: "<sys/fcntl.h>".}: cint
+var O_EXCL* {.importc: "O_EXCL", header: "<sys/fcntl.h>".}: cint
+# var O_NOCTTY* {.importc: "O_NOCTTY", header: "<sys/fcntl.h>".}: cint
+var O_TRUNC* {.importc: "O_TRUNC", header: "<sys/fcntl.h>".}: cint
+var O_APPEND* {.importc: "O_APPEND", header: "<sys/fcntl.h>".}: cint
+# var O_DSYNC* {.importc: "O_DSYNC", header: "<sys/fcntl.h>".}: cint
+var O_NONBLOCK* {.importc: "O_NONBLOCK", header: "<sys/fcntl.h>".}: cint
+# var O_RSYNC* {.importc: "O_RSYNC", header: "<sys/fcntl.h>".}: cint
+# var O_SYNC* {.importc: "O_SYNC", header: "<sys/fcntl.h>".}: cint
+# var O_ACCMODE* {.importc: "O_ACCMODE", header: "<sys/fcntl.h>".}: cint
+var O_RDONLY* {.importc: "O_RDONLY", header: "<sys/fcntl.h>".}: cint
+var O_RDWR* {.importc: "O_RDWR", header: "<sys/fcntl.h>".}: cint
+var O_WRONLY* {.importc: "O_WRONLY", header: "<sys/fcntl.h>".}: cint
+# var O_CLOEXEC* {.importc: "O_CLOEXEC", header: "<sys/fcntl.h>".}: cint
+
+# # <locale.h>
+# var LC_ALL* {.importc: "LC_ALL", header: "<locale.h>".}: cint
+# var LC_COLLATE* {.importc: "LC_COLLATE", header: "<locale.h>".}: cint
+# var LC_CTYPE* {.importc: "LC_CTYPE", header: "<locale.h>".}: cint
+# var LC_MESSAGES* {.importc: "LC_MESSAGES", header: "<locale.h>".}: cint
+# var LC_MONETARY* {.importc: "LC_MONETARY", header: "<locale.h>".}: cint
+# var LC_NUMERIC* {.importc: "LC_NUMERIC", header: "<locale.h>".}: cint
+# var LC_TIME* {.importc: "LC_TIME", header: "<locale.h>".}: cint
+
+# <netdb.h>
+var HOST_NOT_FOUND* {.importc: "HOST_NOT_FOUND", header: "<netdb.h>".}: cint
+var NO_DATA* {.importc: "NO_DATA", header: "<netdb.h>".}: cint
+var NO_RECOVERY* {.importc: "NO_RECOVERY", header: "<netdb.h>".}: cint
+var TRY_AGAIN* {.importc: "TRY_AGAIN", header: "<netdb.h>".}: cint
+var AI_PASSIVE* {.importc: "AI_PASSIVE", header: "<netdb.h>".}: cint
+var AI_CANONNAME* {.importc: "AI_CANONNAME", header: "<netdb.h>".}: cint
+var AI_NUMERICHOST* {.importc: "AI_NUMERICHOST", header: "<netdb.h>".}: cint
+var AI_NUMERICSERV* {.importc: "AI_NUMERICSERV", header: "<netdb.h>".}: cint
+var AI_V4MAPPED* {.importc: "AI_V4MAPPED", header: "<netdb.h>".}: cint
+var AI_ALL* {.importc: "AI_ALL", header: "<netdb.h>".}: cint
+var AI_ADDRCONFIG* {.importc: "AI_ADDRCONFIG", header: "<netdb.h>".}: cint
+var NI_NOFQDN* {.importc: "NI_NOFQDN", header: "<netdb.h>".}: cint
+var NI_NUMERICHOST* {.importc: "NI_NUMERICHOST", header: "<netdb.h>".}: cint
+var NI_NAMEREQD* {.importc: "NI_NAMEREQD", header: "<netdb.h>".}: cint
+var NI_NUMERICSERV* {.importc: "NI_NUMERICSERV", header: "<netdb.h>".}: cint
+var NI_DGRAM* {.importc: "NI_DGRAM", header: "<netdb.h>".}: cint
+var EAI_AGAIN* {.importc: "EAI_AGAIN", header: "<netdb.h>".}: cint
+var EAI_BADFLAGS* {.importc: "EAI_BADFLAGS", header: "<netdb.h>".}: cint
+var EAI_FAIL* {.importc: "EAI_FAIL", header: "<netdb.h>".}: cint
+var EAI_FAMILY* {.importc: "EAI_FAMILY", header: "<netdb.h>".}: cint
+var EAI_MEMORY* {.importc: "EAI_MEMORY", header: "<netdb.h>".}: cint
+var EAI_NONAME* {.importc: "EAI_NONAME", header: "<netdb.h>".}: cint
+var EAI_SERVICE* {.importc: "EAI_SERVICE", header: "<netdb.h>".}: cint
+var EAI_SOCKTYPE* {.importc: "EAI_SOCKTYPE", header: "<netdb.h>".}: cint
+
+var LWIP_DNS_API_DECLARE_H_ERRNO* {.importc: "LWIP_DNS_API_DECLARE_H_ERRNO", header: "<netdb.h>".}: cint
+var LWIP_DNS_API_DEFINE_ERRORS* {.importc: "LWIP_DNS_API_DEFINE_ERRORS", header: "<netdb.h>".}: cint
+var LWIP_DNS_API_DEFINE_FLAGS* {.importc: "LWIP_DNS_API_DEFINE_FLAGS", header: "<netdb.h>".}: cint
+var LWIP_DNS_API_DECLARE_STRUCTS* {.importc: "LWIP_DNS_API_DECLARE_STRUCTS", header: "<netdb.h>".}: cint
+var NETDB_ELEM_SIZE* {.importc: "NETDB_ELEM_SIZE", header: "<netdb.h>".}: cint
+
+
+# <netif.h>
+var ENABLE_LOOPBACK* {.importc: "ENABLE_LOOPBACK", header: "<netif.h>".}: cint
+var NETIF_MAX_HWADDR_LEN* {.importc: "NETIF_MAX_HWADDR_LEN", header: "<netif.h>".}: cint
+var NETIF_NAMESIZE* {.importc: "NETIF_NAMESIZE", header: "<netif.h>".}: cint
+var NETIF_FLAG_UP* {.importc: "NETIF_FLAG_UP", header: "<netif.h>".}: cint
+var NETIF_FLAG_BROADCAST* {.importc: "NETIF_FLAG_BROADCAST", header: "<netif.h>".}: cint
+var NETIF_FLAG_LINK_UP* {.importc: "NETIF_FLAG_LINK_UP", header: "<netif.h>".}: cint
+var NETIF_FLAG_ETHARP* {.importc: "NETIF_FLAG_ETHARP", header: "<netif.h>".}: cint
+var NETIF_FLAG_ETHERNET* {.importc: "NETIF_FLAG_ETHERNET", header: "<netif.h>".}: cint
+var NETIF_FLAG_IGMP* {.importc: "NETIF_FLAG_IGMP", header: "<netif.h>".}: cint
+var NETIF_FLAG_MLD6* {.importc: "NETIF_FLAG_MLD6", header: "<netif.h>".}: cint
+var NETIF_FLAG_GARP* {.importc: "NETIF_FLAG_GARP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_GEN_IP* {.importc: "NETIF_CHECKSUM_GEN_IP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_GEN_UDP* {.importc: "NETIF_CHECKSUM_GEN_UDP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_GEN_TCP* {.importc: "NETIF_CHECKSUM_GEN_TCP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_GEN_ICMP* {.importc: "NETIF_CHECKSUM_GEN_ICMP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_GEN_ICMP6* {.importc: "NETIF_CHECKSUM_GEN_ICMP6", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_CHECK_IP* {.importc: "NETIF_CHECKSUM_CHECK_IP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_CHECK_UDP* {.importc: "NETIF_CHECKSUM_CHECK_UDP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_CHECK_TCP* {.importc: "NETIF_CHECKSUM_CHECK_TCP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_CHECK_ICMP* {.importc: "NETIF_CHECKSUM_CHECK_ICMP", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_CHECK_ICMP6* {.importc: "NETIF_CHECKSUM_CHECK_ICMP6", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_ENABLE_ALL* {.importc: "NETIF_CHECKSUM_ENABLE_ALL", header: "<netif.h>".}: cint
+var NETIF_CHECKSUM_DISABLE_ALL* {.importc: "NETIF_CHECKSUM_DISABLE_ALL", header: "<netif.h>".}: cint
+var NETIF_ADDR_IDX_MAX* {.importc: "NETIF_ADDR_IDX_MAX", header: "<netif.h>".}: cint
+var LWIP_NETIF_USE_HINTS* {.importc: "LWIP_NETIF_USE_HINTS", header: "<netif.h>".}: cint
+var NETIF_NO_INDEX* {.importc: "NETIF_NO_INDEX", header: "<netif.h>".}: cint
+var LWIP_NSC_NONE* {.importc: "LWIP_NSC_NONE", header: "<netif.h>".}: cint
+var LWIP_NSC_NETIF_ADDED* {.importc: "LWIP_NSC_NETIF_ADDED", header: "<netif.h>".}: cint
+var LWIP_NSC_NETIF_REMOVED* {.importc: "LWIP_NSC_NETIF_REMOVED", header: "<netif.h>".}: cint
+var LWIP_NSC_LINK_CHANGED* {.importc: "LWIP_NSC_LINK_CHANGED", header: "<netif.h>".}: cint
+var LWIP_NSC_STATUS_CHANGED* {.importc: "LWIP_NSC_STATUS_CHANGED", header: "<netif.h>".}: cint
+var LWIP_NSC_IPV4_ADDRESS_CHANGED* {.importc: "LWIP_NSC_IPV4_ADDRESS_CHANGED", header: "<netif.h>".}: cint
+var LWIP_NSC_IPV4_GATEWAY_CHANGED* {.importc: "LWIP_NSC_IPV4_GATEWAY_CHANGED", header: "<netif.h>".}: cint
+var LWIP_NSC_IPV4_NETMASK_CHANGED* {.importc: "LWIP_NSC_IPV4_NETMASK_CHANGED", header: "<netif.h>".}: cint
+var LWIP_NSC_IPV4_SETTINGS_CHANGED* {.importc: "LWIP_NSC_IPV4_SETTINGS_CHANGED", header: "<netif.h>".}: cint
+var LWIP_NSC_IPV6_SET* {.importc: "LWIP_NSC_IPV6_SET", header: "<netif.h>".}: cint
+var LWIP_NSC_IPV6_ADDR_STATE_CHANGED* {.importc: "LWIP_NSC_IPV6_ADDR_STATE_CHANGED", header: "<netif.h>".}: cint
+#define NETIF_DECLARE_EXT_CALLBACK(name)
+
+
+# <net/if.h>
+var IF_NAMESIZE* {.importc: "IF_NAMESIZE", header: "<net/if.h>".}: cint
+
+# <sys/socket.h>
+var IPPROTO_IP* {.importc: "IPPROTO_IP", header: "<sys/socket.h>".}: cint
+var IPPROTO_IPV6* {.importc: "IPPROTO_IPV6", header: "<sys/socket.h>".}: cint
+var IPPROTO_ICMP* {.importc: "IPPROTO_ICMP", header: "<sys/socket.h>".}: cint
+var IPPROTO_ICMPV6* {.importc: "IPPROTO_ICMPV6", header: "<sys/socket.h>".}: cint
+var IPPROTO_RAW* {.importc: "IPPROTO_RAW", header: "<sys/socket.h>".}: cint
+var IPPROTO_TCP* {.importc: "IPPROTO_TCP", header: "<sys/socket.h>".}: cint
+var IPPROTO_UDP* {.importc: "IPPROTO_UDP", header: "<sys/socket.h>".}: cint
+var INADDR_ANY* {.importc: "INADDR_ANY", header: "<sys/socket.h>".}: InAddrScalar
+var INADDR_LOOPBACK* {.importc: "INADDR_LOOPBACK", header: "<sys/socket.h>".}: InAddrScalar
+var INADDR_BROADCAST* {.importc: "INADDR_BROADCAST", header: "<sys/socket.h>".}: InAddrScalar
+var INET_ADDRSTRLEN* {.importc: "INET_ADDRSTRLEN", header: "<sys/socket.h>".}: cint
+var INET6_ADDRSTRLEN* {.importc: "INET6_ADDRSTRLEN", header: "<sys/socket.h>".}: cint
+var IPV6_JOIN_GROUP* {.importc: "IPV6_JOIN_GROUP", header: "<sys/socket.h>".}: cint
+var IPV6_LEAVE_GROUP* {.importc: "IPV6_LEAVE_GROUP", header: "<sys/socket.h>".}: cint
+var IPV6_MULTICAST_HOPS* {.importc: "IPV6_MULTICAST_HOPS", header: "<sys/socket.h>".}: cint
+var IPV6_MULTICAST_IF* {.importc: "IPV6_MULTICAST_IF", header: "<sys/socket.h>".}: cint
+var IPV6_MULTICAST_LOOP* {.importc: "IPV6_MULTICAST_LOOP", header: "<sys/socket.h>".}: cint
+var IPV6_UNICAST_HOPS* {.importc: "IPV6_UNICAST_HOPS", header: "<sys/socket.h>".}: cint
+var IPV6_V6ONLY* {.importc: "IPV6_V6ONLY", header: "<sys/socket.h>".}: cint
+
+# <netinet/tcp.h>
+const TCP_NODELAY*    = 0x01    # don't delay send to coalesce packets
+const TCP_KEEPALIVE*  = 0x02    # send KEEPALIVE probes when idle for pcb->keep_idle milliseconds
+const TCP_KEEPIDLE*   = 0x03    # set pcb->keep_idle  - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt
+const TCP_KEEPINTVL*  = 0x04    # set pcb->keep_intvl - Use seconds for get/setsockopt
+const TCP_KEEPCNT*    = 0x05    # set pcb->keep_cnt   - Use number of probes sent for get/setsockopt
+
+# <nl_types.h>
+# var NL_SETD* {.importc: "NL_SETD", header: "<nl_types.h>".}: cint
+# var NL_CAT_LOCALE* {.importc: "NL_CAT_LOCALE", header: "<nl_types.h>".}: cint
+
+# <sys/poll.h>
+# var POLLIN* {.importc: "POLLIN", header: "<sys/poll.h>".}: cshort
+# var POLLRDNORM* {.importc: "POLLRDNORM", header: "<sys/poll.h>".}: cshort
+# var POLLRDBAND* {.importc: "POLLRDBAND", header: "<sys/poll.h>".}: cshort
+# var POLLPRI* {.importc: "POLLPRI", header: "<sys/poll.h>".}: cshort
+# var POLLOUT* {.importc: "POLLOUT", header: "<sys/poll.h>".}: cshort
+# var POLLWRNORM* {.importc: "POLLWRNORM", header: "<sys/poll.h>".}: cshort
+# var POLLWRBAND* {.importc: "POLLWRBAND", header: "<sys/poll.h>".}: cshort
+# var POLLERR* {.importc: "POLLERR", header: "<sys/poll.h>".}: cshort
+# var POLLHUP* {.importc: "POLLHUP", header: "<sys/poll.h>".}: cshort
+# var POLLNVAL* {.importc: "POLLNVAL", header: "<sys/poll.h>".}: cshort
+
+# <pthread.h>
+var PTHREAD_STACK_MIN* {.importc: "PTHREAD_STACK_MIN", header: "<pthread.h>".}: cint
+# var PTHREAD_BARRIER_SERIAL_THREAD* {.importc: "PTHREAD_BARRIER_SERIAL_THREAD", header: "<pthread.h>".}: cint
+# var PTHREAD_CANCEL_ASYNCHRONOUS* {.importc: "PTHREAD_CANCEL_ASYNCHRONOUS", header: "<pthread.h>".}: cint
+# var PTHREAD_CANCEL_ENABLE* {.importc: "PTHREAD_CANCEL_ENABLE", header: "<pthread.h>".}: cint
+# var PTHREAD_CANCEL_DEFERRED* {.importc: "PTHREAD_CANCEL_DEFERRED", header: "<pthread.h>".}: cint
+# var PTHREAD_CANCEL_DISABLE* {.importc: "PTHREAD_CANCEL_DISABLE", header: "<pthread.h>".}: cint
+# var PTHREAD_CREATE_DETACHED* {.importc: "PTHREAD_CREATE_DETACHED", header: "<pthread.h>".}: cint
+# var PTHREAD_CREATE_JOINABLE* {.importc: "PTHREAD_CREATE_JOINABLE", header: "<pthread.h>".}: cint
+# var PTHREAD_EXPLICIT_SCHED* {.importc: "PTHREAD_EXPLICIT_SCHED", header: "<pthread.h>".}: cint
+# var PTHREAD_INHERIT_SCHED* {.importc: "PTHREAD_INHERIT_SCHED", header: "<pthread.h>".}: cint
+# var PTHREAD_MUTEX_DEFAULT* {.importc: "PTHREAD_MUTEX_DEFAULT", header: "<pthread.h>".}: cint
+# var PTHREAD_MUTEX_ERRORCHECK* {.importc: "PTHREAD_MUTEX_ERRORCHECK", header: "<pthread.h>".}: cint
+# var PTHREAD_MUTEX_NORMAL* {.importc: "PTHREAD_MUTEX_NORMAL", header: "<pthread.h>".}: cint
+# var PTHREAD_MUTEX_RECURSIVE* {.importc: "PTHREAD_MUTEX_RECURSIVE", header: "<pthread.h>".}: cint
+# var PTHREAD_PRIO_INHERIT* {.importc: "PTHREAD_PRIO_INHERIT", header: "<pthread.h>".}: cint
+# var PTHREAD_PRIO_NONE* {.importc: "PTHREAD_PRIO_NONE", header: "<pthread.h>".}: cint
+# var PTHREAD_PRIO_PROTECT* {.importc: "PTHREAD_PRIO_PROTECT", header: "<pthread.h>".}: cint
+# var PTHREAD_PROCESS_SHARED* {.importc: "PTHREAD_PROCESS_SHARED", header: "<pthread.h>".}: cint
+# var PTHREAD_PROCESS_PRIVATE* {.importc: "PTHREAD_PROCESS_PRIVATE", header: "<pthread.h>".}: cint
+# var PTHREAD_SCOPE_PROCESS* {.importc: "PTHREAD_SCOPE_PROCESS", header: "<pthread.h>".}: cint
+# var PTHREAD_SCOPE_SYSTEM* {.importc: "PTHREAD_SCOPE_SYSTEM", header: "<pthread.h>".}: cint
+
+# # <sched.h>
+# var SCHED_FIFO* {.importc: "SCHED_FIFO", header: "<sched.h>".}: cint
+# var SCHED_RR* {.importc: "SCHED_RR", header: "<sched.h>".}: cint
+# var SCHED_SPORADIC* {.importc: "SCHED_SPORADIC", header: "<sched.h>".}: cint
+# var SCHED_OTHER* {.importc: "SCHED_OTHER", header: "<sched.h>".}: cint
+
+# <semaphore.h>
+var SEM_FAILED* {.importc: "SEM_FAILED", header: "<semaphore.h>".}: pointer
+
+# # <signal.h>
+# var SIGEV_NONE* {.importc: "SIGEV_NONE", header: "<signal.h>".}: cint
+# var SIGEV_SIGNAL* {.importc: "SIGEV_SIGNAL", header: "<signal.h>".}: cint
+# var SIGEV_THREAD* {.importc: "SIGEV_THREAD", header: "<signal.h>".}: cint
+# var SIGABRT* {.importc: "SIGABRT", header: "<signal.h>".}: cint
+# var SIGALRM* {.importc: "SIGALRM", header: "<signal.h>".}: cint
+# var SIGBUS* {.importc: "SIGBUS", header: "<signal.h>".}: cint
+# var SIGCHLD* {.importc: "SIGCHLD", header: "<signal.h>".}: cint
+# var SIGCONT* {.importc: "SIGCONT", header: "<signal.h>".}: cint
+# var SIGFPE* {.importc: "SIGFPE", header: "<signal.h>".}: cint
+# var SIGHUP* {.importc: "SIGHUP", header: "<signal.h>".}: cint
+# var SIGILL* {.importc: "SIGILL", header: "<signal.h>".}: cint
+# var SIGINT* {.importc: "SIGINT", header: "<signal.h>".}: cint
+# var SIGKILL* {.importc: "SIGKILL", header: "<signal.h>".}: cint
+# var SIGPIPE* {.importc: "SIGPIPE", header: "<signal.h>".}: cint
+# var SIGQUIT* {.importc: "SIGQUIT", header: "<signal.h>".}: cint
+# var SIGSEGV* {.importc: "SIGSEGV", header: "<signal.h>".}: cint
+# var SIGSTOP* {.importc: "SIGSTOP", header: "<signal.h>".}: cint
+# var SIGTERM* {.importc: "SIGTERM", header: "<signal.h>".}: cint
+# var SIGTSTP* {.importc: "SIGTSTP", header: "<signal.h>".}: cint
+# var SIGTTIN* {.importc: "SIGTTIN", header: "<signal.h>".}: cint
+# var SIGTTOU* {.importc: "SIGTTOU", header: "<signal.h>".}: cint
+# var SIGUSR1* {.importc: "SIGUSR1", header: "<signal.h>".}: cint
+# var SIGUSR2* {.importc: "SIGUSR2", header: "<signal.h>".}: cint
+# var SIGPOLL* {.importc: "SIGPOLL", header: "<signal.h>".}: cint
+# var SIGPROF* {.importc: "SIGPROF", header: "<signal.h>".}: cint
+# var SIGSYS* {.importc: "SIGSYS", header: "<signal.h>".}: cint
+# var SIGTRAP* {.importc: "SIGTRAP", header: "<signal.h>".}: cint
+# var SIGURG* {.importc: "SIGURG", header: "<signal.h>".}: cint
+# var SIGVTALRM* {.importc: "SIGVTALRM", header: "<signal.h>".}: cint
+# var SIGXCPU* {.importc: "SIGXCPU", header: "<signal.h>".}: cint
+# var SIGXFSZ* {.importc: "SIGXFSZ", header: "<signal.h>".}: cint
+# var SA_NOCLDSTOP* {.importc: "SA_NOCLDSTOP", header: "<signal.h>".}: cint
+# var SIG_BLOCK* {.importc: "SIG_BLOCK", header: "<signal.h>".}: cint
+# var SIG_UNBLOCK* {.importc: "SIG_UNBLOCK", header: "<signal.h>".}: cint
+# var SIG_SETMASK* {.importc: "SIG_SETMASK", header: "<signal.h>".}: cint
+# var SA_ONSTACK* {.importc: "SA_ONSTACK", header: "<signal.h>".}: cint
+# var SA_RESETHAND* {.importc: "SA_RESETHAND", header: "<signal.h>".}: cint
+# var SA_RESTART* {.importc: "SA_RESTART", header: "<signal.h>".}: cint
+# var SA_SIGINFO* {.importc: "SA_SIGINFO", header: "<signal.h>".}: cint
+# var SA_NOCLDWAIT* {.importc: "SA_NOCLDWAIT", header: "<signal.h>".}: cint
+# var SA_NODEFER* {.importc: "SA_NODEFER", header: "<signal.h>".}: cint
+# var SS_ONSTACK* {.importc: "SS_ONSTACK", header: "<signal.h>".}: cint
+# var SS_DISABLE* {.importc: "SS_DISABLE", header: "<signal.h>".}: cint
+# var MINSIGSTKSZ* {.importc: "MINSIGSTKSZ", header: "<signal.h>".}: cint
+# var SIGSTKSZ* {.importc: "SIGSTKSZ", header: "<signal.h>".}: cint
+# var SIG_HOLD* {.importc: "SIG_HOLD", header: "<signal.h>".}: Sighandler
+# var SIG_DFL* {.importc: "SIG_DFL", header: "<signal.h>".}: Sighandler
+# var SIG_ERR* {.importc: "SIG_ERR", header: "<signal.h>".}: Sighandler
+# var SIG_IGN* {.importc: "SIG_IGN", header: "<signal.h>".}: Sighandler
+
+# # <sys/ipc.h>
+# var IPC_CREAT* {.importc: "IPC_CREAT", header: "<sys/ipc.h>".}: cint
+# var IPC_EXCL* {.importc: "IPC_EXCL", header: "<sys/ipc.h>".}: cint
+# var IPC_NOWAIT* {.importc: "IPC_NOWAIT", header: "<sys/ipc.h>".}: cint
+# var IPC_PRIVATE* {.importc: "IPC_PRIVATE", header: "<sys/ipc.h>".}: cint
+# var IPC_RMID* {.importc: "IPC_RMID", header: "<sys/ipc.h>".}: cint
+# var IPC_SET* {.importc: "IPC_SET", header: "<sys/ipc.h>".}: cint
+# var IPC_STAT* {.importc: "IPC_STAT", header: "<sys/ipc.h>".}: cint
+
+# # <sys/mman.h>
+# var PROT_READ* {.importc: "PROT_READ", header: "<sys/mman.h>".}: cint
+# var PROT_WRITE* {.importc: "PROT_WRITE", header: "<sys/mman.h>".}: cint
+# var PROT_EXEC* {.importc: "PROT_EXEC", header: "<sys/mman.h>".}: cint
+# var PROT_NONE* {.importc: "PROT_NONE", header: "<sys/mman.h>".}: cint
+# var MAP_ANONYMOUS* {.importc: "MAP_ANONYMOUS", header: "<sys/mman.h>".}: cint
+# var MAP_FIXED_NOREPLACE* {.importc: "MAP_FIXED_NOREPLACE", header: "<sys/mman.h>".}: cint
+# var MAP_NORESERVE* {.importc: "MAP_NORESERVE", header: "<sys/mman.h>".}: cint
+# var MAP_SHARED* {.importc: "MAP_SHARED", header: "<sys/mman.h>".}: cint
+# var MAP_PRIVATE* {.importc: "MAP_PRIVATE", header: "<sys/mman.h>".}: cint
+# var MAP_FIXED* {.importc: "MAP_FIXED", header: "<sys/mman.h>".}: cint
+# var MS_ASYNC* {.importc: "MS_ASYNC", header: "<sys/mman.h>".}: cint
+# var MS_SYNC* {.importc: "MS_SYNC", header: "<sys/mman.h>".}: cint
+# var MS_INVALIDATE* {.importc: "MS_INVALIDATE", header: "<sys/mman.h>".}: cint
+# var MCL_CURRENT* {.importc: "MCL_CURRENT", header: "<sys/mman.h>".}: cint
+# var MCL_FUTURE* {.importc: "MCL_FUTURE", header: "<sys/mman.h>".}: cint
+# var MAP_FAILED* {.importc: "MAP_FAILED", header: "<sys/mman.h>".}: pointer
+# var POSIX_MADV_NORMAL* {.importc: "POSIX_MADV_NORMAL", header: "<sys/mman.h>".}: cint
+# var POSIX_MADV_SEQUENTIAL* {.importc: "POSIX_MADV_SEQUENTIAL", header: "<sys/mman.h>".}: cint
+# var POSIX_MADV_RANDOM* {.importc: "POSIX_MADV_RANDOM", header: "<sys/mman.h>".}: cint
+# var POSIX_MADV_WILLNEED* {.importc: "POSIX_MADV_WILLNEED", header: "<sys/mman.h>".}: cint
+# var POSIX_MADV_DONTNEED* {.importc: "POSIX_MADV_DONTNEED", header: "<sys/mman.h>".}: cint
+# var POSIX_TYPED_MEM_ALLOCATE* {.importc: "POSIX_TYPED_MEM_ALLOCATE", header: "<sys/mman.h>".}: cint
+# var POSIX_TYPED_MEM_ALLOCATE_CONTIG* {.importc: "POSIX_TYPED_MEM_ALLOCATE_CONTIG", header: "<sys/mman.h>".}: cint
+# var POSIX_TYPED_MEM_MAP_ALLOCATABLE* {.importc: "POSIX_TYPED_MEM_MAP_ALLOCATABLE", header: "<sys/mman.h>".}: cint
+
+# <sys/resource.h>
+# var RLIMIT_NOFILE* {.importc: "RLIMIT_NOFILE", header: "<sys/resource.h>".}: cint
+
+var FD_MAX* {.importc: "CONFIG_LWIP_MAX_SOCKETS", header: "<lwipopts.h>".}: cint
+
+# <sys/select.h>
+var FD_SETSIZE* {.importc: "FD_SETSIZE", header: "<sys/select.h>".}: cint
+
+# <sys/socket.h>
+# struct msghdr->msg_flags bit field values 
+const MSG_TRUNC*   = 0x04
+const MSG_CTRUNC*  = 0x08
+
+# Flags we can use with send and recv.
+const MSG_PEEK*       = 0x01    # Peeks at an incoming message
+const MSG_WAITALL*    = 0x02    # Unimplemented: Requests that the function block until the full amount of data requested can be returned
+const MSG_OOB*        = 0x04    # Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific
+const MSG_DONTWAIT*   = 0x08    # Nonblocking i/o for this operation only
+const MSG_MORE*       = 0x10    # Sender will send more
+# const MSG_NOSIGNAL*   = 0x20    # Uninmplemented: Requests not to send the SIGPIPE signal if an attempt to send is made on a stream-oriented socket that is no longer connected.
+
+# Alternately, they can defined like this, but the above seems better when they're known/stable values:
+# var MSG_TRUNC* {.importc: "MSG_TRUNC", header: "<sys/socket.h>".}: cint
+# var MSG_CTRUNC* {.importc: "MSG_CTRUNC", header: "<sys/socket.h>".}: cint
+# var MSG_DONTROUTE* {.importc: "MSG_DONTROUTE", header: "<sys/socket.h>".}: cint # not defined in lwip
+# var MSG_EOR* {.importc: "MSG_EOR", header: "<sys/socket.h>".}: cint # not defined in lwip
+# var MSG_OOB* {.importc: "MSG_OOB", header: "<sys/socket.h>".}: cint
+
+
+# var SCM_RIGHTS* {.importc: "SCM_RIGHTS", header: "<sys/socket.h>".}: cint
+var SO_ACCEPTCONN* {.importc: "SO_ACCEPTCONN", header: "<sys/socket.h>".}: cint
+var SO_BROADCAST* {.importc: "SO_BROADCAST", header: "<sys/socket.h>".}: cint
+var SO_DEBUG* {.importc: "SO_DEBUG", header: "<sys/socket.h>".}: cint
+var SO_DONTROUTE* {.importc: "SO_DONTROUTE", header: "<sys/socket.h>".}: cint
+var SO_ERROR* {.importc: "SO_ERROR", header: "<sys/socket.h>".}: cint
+var SO_KEEPALIVE* {.importc: "SO_KEEPALIVE", header: "<sys/socket.h>".}: cint
+var SO_LINGER* {.importc: "SO_LINGER", header: "<sys/socket.h>".}: cint
+var SO_OOBINLINE* {.importc: "SO_OOBINLINE", header: "<sys/socket.h>".}: cint
+var SO_RCVBUF* {.importc: "SO_RCVBUF", header: "<sys/socket.h>".}: cint
+var SO_RCVLOWAT* {.importc: "SO_RCVLOWAT", header: "<sys/socket.h>".}: cint
+var SO_RCVTIMEO* {.importc: "SO_RCVTIMEO", header: "<sys/socket.h>".}: cint
+var SO_REUSEADDR* {.importc: "SO_REUSEADDR", header: "<sys/socket.h>".}: cint
+var SO_SNDBUF* {.importc: "SO_SNDBUF", header: "<sys/socket.h>".}: cint
+var SO_SNDLOWAT* {.importc: "SO_SNDLOWAT", header: "<sys/socket.h>".}: cint
+var SO_SNDTIMEO* {.importc: "SO_SNDTIMEO", header: "<sys/socket.h>".}: cint
+var SO_TYPE* {.importc: "SO_TYPE", header: "<sys/socket.h>".}: cint
+var SOCK_DGRAM* {.importc: "SOCK_DGRAM", header: "<sys/socket.h>".}: cint
+var SOCK_RAW* {.importc: "SOCK_RAW", header: "<sys/socket.h>".}: cint
+
+# var SOCK_SEQPACKET* {.importc: "SOCK_SEQPACKET", header: "<sys/socket.h>".}: cint
+const SOCK_SEQPACKET* = cint(5)
+
+var SOCK_STREAM* {.importc: "SOCK_STREAM", header: "<sys/socket.h>".}: cint
+var SOL_SOCKET* {.importc: "SOL_SOCKET", header: "<sys/socket.h>".}: cint
+
+const SocketMaxConnections {.intdefine.}: int = 32
+var SOMAXCONN*: cint = SocketMaxConnections.cint
+
+var AF_INET* {.importc: "AF_INET", header: "<sys/socket.h>".}: cint
+var AF_INET6* {.importc: "AF_INET6", header: "<sys/socket.h>".}: cint
+# var AF_UNIX* {.importc: "AF_UNIX", header: "<sys/socket.h>".}: cint
+const AF_UNIX*: cint = 1 # for compat with Nim libraries, doesn't exist on freertos
+var AF_UNSPEC* {.importc: "AF_UNSPEC", header: "<sys/socket.h>".}: cint
+var SHUT_RD* {.importc: "SHUT_RD", header: "<sys/socket.h>".}: cint
+var SHUT_RDWR* {.importc: "SHUT_RDWR", header: "<sys/socket.h>".}: cint
+var SHUT_WR* {.importc: "SHUT_WR", header: "<sys/socket.h>".}: cint
+
+# # <sys/stat.h>
+# <sys/stat.h>
+
+# var S_IFBLK* {.importc: "S_IFBLK", header: "<sys/stat.h>".}: cint
+# var S_IFCHR* {.importc: "S_IFCHR", header: "<sys/stat.h>".}: cint
+# var S_IFDIR* {.importc: "S_IFDIR", header: "<sys/stat.h>".}: cint
+# var S_IFIFO* {.importc: "S_IFIFO", header: "<sys/stat.h>".}: cint
+# var S_IFLNK* {.importc: "S_IFLNK", header: "<sys/stat.h>".}: cint
+# var S_IFMT* {.importc: "S_IFMT", header: "<sys/stat.h>".}: cint
+# var S_IFREG* {.importc: "S_IFREG", header: "<sys/stat.h>".}: cint
+# var S_IFSOCK* {.importc: "S_IFSOCK", header: "<sys/stat.h>".}: cint
+var S_IRGRP* {.importc: "S_IRGRP", header: "<sys/stat.h>".}: cint
+var S_IROTH* {.importc: "S_IROTH", header: "<sys/stat.h>".}: cint
+var S_IRUSR* {.importc: "S_IRUSR", header: "<sys/stat.h>".}: cint
+# var S_IRWXG* {.importc: "S_IRWXG", header: "<sys/stat.h>".}: cint
+# var S_IRWXO* {.importc: "S_IRWXO", header: "<sys/stat.h>".}: cint
+# var S_IRWXU* {.importc: "S_IRWXU", header: "<sys/stat.h>".}: cint
+# var S_ISGID* {.importc: "S_ISGID", header: "<sys/stat.h>".}: cint
+# var S_ISUID* {.importc: "S_ISUID", header: "<sys/stat.h>".}: cint
+# var S_ISVTX* {.importc: "S_ISVTX", header: "<sys/stat.h>".}: cint
+var S_IWGRP* {.importc: "S_IWGRP", header: "<sys/stat.h>".}: cint
+var S_IWOTH* {.importc: "S_IWOTH", header: "<sys/stat.h>".}: cint
+var S_IWUSR* {.importc: "S_IWUSR", header: "<sys/stat.h>".}: cint
+var S_IXGRP* {.importc: "S_IXGRP", header: "<sys/stat.h>".}: cint
+var S_IXOTH* {.importc: "S_IXOTH", header: "<sys/stat.h>".}: cint
+var S_IXUSR* {.importc: "S_IXUSR", header: "<sys/stat.h>".}: cint
+
+# # <sys/statvfs.h>
+# var ST_RDONLY* {.importc: "ST_RDONLY", header: "<sys/statvfs.h>".}: cint
+# var ST_NOSUID* {.importc: "ST_NOSUID", header: "<sys/statvfs.h>".}: cint
+
+# # <sys/wait.h>
+# var WNOHANG* {.importc: "WNOHANG", header: "<sys/wait.h>".}: cint
+# var WUNTRACED* {.importc: "WUNTRACED", header: "<sys/wait.h>".}: cint
+# var WEXITED* {.importc: "WEXITED", header: "<sys/wait.h>".}: cint
+# var WSTOPPED* {.importc: "WSTOPPED", header: "<sys/wait.h>".}: cint
+# var WCONTINUED* {.importc: "WCONTINUED", header: "<sys/wait.h>".}: cint
+# var WNOWAIT* {.importc: "WNOWAIT", header: "<sys/wait.h>".}: cint
+# var P_ALL* {.importc: "P_ALL", header: "<sys/wait.h>".}: cint
+# var P_PID* {.importc: "P_PID", header: "<sys/wait.h>".}: cint
+# var P_PGID* {.importc: "P_PGID", header: "<sys/wait.h>".}: cint
+
+# # <spawn.h>
+# var POSIX_SPAWN_RESETIDS* {.importc: "POSIX_SPAWN_RESETIDS", header: "<spawn.h>".}: cint
+# var POSIX_SPAWN_SETPGROUP* {.importc: "POSIX_SPAWN_SETPGROUP", header: "<spawn.h>".}: cint
+# var POSIX_SPAWN_SETSCHEDPARAM* {.importc: "POSIX_SPAWN_SETSCHEDPARAM", header: "<spawn.h>".}: cint
+# var POSIX_SPAWN_SETSCHEDULER* {.importc: "POSIX_SPAWN_SETSCHEDULER", header: "<spawn.h>".}: cint
+# var POSIX_SPAWN_SETSIGDEF* {.importc: "POSIX_SPAWN_SETSIGDEF", header: "<spawn.h>".}: cint
+# var POSIX_SPAWN_SETSIGMASK* {.importc: "POSIX_SPAWN_SETSIGMASK", header: "<spawn.h>".}: cint
+
+## <stdio.h>
+# var IOFBF* {.importc: "_IOFBF", header: "<stdio.h>".}: cint
+# var IONBF* {.importc: "_IONBF", header: "<stdio.h>".}: cint
+
+# <time.h>
+var CLOCKS_PER_SEC* {.importc: "CLOCKS_PER_SEC", header: "<time.h>".}: clong
+var CLOCK_PROCESS_CPUTIME_ID* {.importc: "CLOCK_PROCESS_CPUTIME_ID", header: "<time.h>".}: cint
+var CLOCK_THREAD_CPUTIME_ID* {.importc: "CLOCK_THREAD_CPUTIME_ID", header: "<time.h>".}: cint
+var CLOCK_REALTIME* {.importc: "CLOCK_REALTIME", header: "<time.h>".}: cint
+var TIMER_ABSTIME* {.importc: "TIMER_ABSTIME", header: "<time.h>".}: cint
+var CLOCK_MONOTONIC* {.importc: "CLOCK_MONOTONIC", header: "<time.h>".}: cint
+
+# <unistd.h>
+
+const F_OK* = cint(0)
+const R_OK* = cint(4)
+const W_OK* = cint(2)
+const X_OK* = cint(1)
+const F_LOCK* = cint(1)
+const F_TEST* = cint(3)
+const F_TLOCK* = cint(2)
+const F_ULOCK* = cint(0)
+
+# <stdio.h>
+const SEEK_SET* = cint(0)
+const SEEK_CUR* = cint(1)
+const SEEK_END* = cint(2)
diff --git a/lib/posix/posix_haiku.nim b/lib/posix/posix_haiku.nim
new file mode 100644
index 000000000..32a6d24e2
--- /dev/null
+++ b/lib/posix/posix_haiku.nim
@@ -0,0 +1,603 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2020 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+const
+  hasSpawnH = true # should exist for every Posix system nowadays
+  hasAioH = defined(linux)
+
+when defined(linux) and not defined(android):
+  # On Linux:
+  # timer_{create,delete,settime,gettime},
+  # clock_{getcpuclockid, getres, gettime, nanosleep, settime} lives in librt
+  {.passl: "-lrt".}
+when defined(solaris):
+  # On Solaris hstrerror lives in libresolv
+  {.passl: "-lresolv".}
+
+type
+  DIR* {.importc: "DIR", header: "<dirent.h>",
+          incompleteStruct.} = object
+    ## A type representing a directory stream.
+
+type
+  SocketHandle* = distinct cint # The type used to represent socket descriptors
+
+type
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct (
+    when defined(i386):
+      int32
+    else:
+      int64
+  )
+  Timespec* {.importc: "struct timespec",
+               header: "<time.h>", final, pure.} = object ## struct timespec
+    tv_sec*: Time  ## Seconds.
+    tv_nsec*: int  ## Nanoseconds.
+
+  Dirent* {.importc: "struct dirent",
+             header: "<dirent.h>", final, pure.} = object ## dirent_t struct
+    when defined(haiku):
+      d_dev*: Dev ## Device (not POSIX)
+      d_pdev*: Dev ## Parent device (only for queries) (not POSIX)
+    d_ino*: Ino  ## File serial number.
+    when defined(dragonfly):
+      # DragonflyBSD doesn't have `d_reclen` field.
+      d_type*: uint8
+    elif defined(linux) or defined(macosx) or defined(freebsd) or
+         defined(netbsd) or defined(openbsd) or defined(genode):
+      d_reclen*: cshort ## Length of this record. (not POSIX)
+      d_type*: int8 ## Type of file; not supported by all filesystem types.
+                    ## (not POSIX)
+      when defined(linux) or defined(openbsd):
+        d_off*: Off  ## Not an offset. Value that `telldir()` would return.
+    elif defined(haiku):
+      d_pino*: Ino ## Parent inode (only for queries) (not POSIX)
+      d_reclen*: cushort ## Length of this record. (not POSIX)
+
+    when not defined(haiku):
+      d_name*: array[0..255, char] ## Name of entry.
+    else:
+      d_name*: UncheckedArray[char] ## Name of entry (NUL terminated).
+
+  Tflock* {.importc: "struct flock", final, pure,
+            header: "<fcntl.h>".} = object ## flock type
+    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+    l_whence*: cshort ## Flag for starting offset.
+    l_start*: Off     ## Relative offset in bytes.
+    l_len*: Off       ## Size; if 0 then until EOF.
+    l_pid*: Pid      ## Process ID of the process holding the lock;
+                      ## returned with F_GETLK.
+
+  FTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
+    base*: cint
+    level*: cint
+
+  Glob* {.importc: "glob_t", header: "<glob.h>",
+           final, pure.} = object ## glob_t
+    gl_pathc*: int          ## Count of paths matched by pattern.
+    gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
+    gl_offs*: int           ## Slots to reserve at the beginning of gl_pathv.
+
+  Group* {.importc: "struct group", header: "<grp.h>",
+            final, pure.} = object ## struct group
+    gr_name*: cstring     ## The name of the group.
+    gr_gid*: Gid         ## Numerical group ID.
+    gr_mem*: cstringArray ## Pointer to a null-terminated array of character
+                          ## pointers to member names.
+
+  Iconv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} =
+    object ## Identifies the conversion from one codeset to another.
+
+  Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
+            pure.} = object
+    currency_symbol*: cstring
+    decimal_point*: cstring
+    frac_digits*: char
+    grouping*: cstring
+    int_curr_symbol*: cstring
+    int_frac_digits*: char
+    int_n_cs_precedes*: char
+    int_n_sep_by_space*: char
+    int_n_sign_posn*: char
+    int_p_cs_precedes*: char
+    int_p_sep_by_space*: char
+    int_p_sign_posn*: char
+    mon_decimal_point*: cstring
+    mon_grouping*: cstring
+    mon_thousands_sep*: cstring
+    negative_sign*: cstring
+    n_cs_precedes*: char
+    n_sep_by_space*: char
+    n_sign_posn*: char
+    positive_sign*: cstring
+    p_cs_precedes*: char
+    p_sep_by_space*: char
+    p_sign_posn*: char
+    thousands_sep*: cstring
+
+  Mqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
+  MqAttr* {.importc: "struct mq_attr",
+             header: "<mqueue.h>",
+             final, pure.} = object ## message queue attribute
+    mq_flags*: int   ## Message queue flags.
+    mq_maxmsg*: int  ## Maximum number of messages.
+    mq_msgsize*: int ## Maximum message size.
+    mq_curmsgs*: int ## Number of messages currently queued.
+
+  Passwd* {.importc: "struct passwd", header: "<pwd.h>",
+             final, pure.} = object ## struct passwd
+    pw_name*: cstring   ## User's login name.
+    pw_uid*: Uid        ## Numerical user ID.
+    pw_gid*: Gid        ## Numerical group ID.
+    pw_dir*: cstring    ## Initial working directory.
+    pw_shell*: cstring  ## Program to use as shell.
+
+  Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int64
+    ## used for file block counts
+  Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int32
+    ## used for block sizes
+  Clock* {.importc: "clock_t", header: "<time.h>".} = int32
+  ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int32
+  Dev* {.importc: "dev_t", header: "<sys/types.h>".} = int32
+  Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int64
+  Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int64
+  Gid* {.importc: "gid_t", header: "<sys/types.h>".} = uint32
+  Id* {.importc: "id_t", header: "<sys/types.h>".} = int32
+  Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int64
+  Key* {.importc: "key_t", header: "<sys/types.h>".} = int32
+  Mode* {.importc: "mode_t", header: "<sys/types.h>".} = (
+    when defined(android) or defined(macos) or defined(macosx) or
+        (defined(bsd) and not defined(openbsd) and not defined(netbsd)):
+      uint16
+    else:
+      uint32
+  )
+  Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int32
+  Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
+  Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
+  Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = object
+  Pthread_barrier* {.importc: "pthread_barrier_t",
+                      header: "<sys/types.h>".} = object
+  Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
+                          header: "<sys/types.h>".} = object
+  Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = object
+  Pthread_condattr* {.importc: "pthread_condattr_t",
+                       header: "<sys/types.h>".} = object
+  Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = object
+  Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = object
+  Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
+                        header: "<sys/types.h>".} = object
+  Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = object
+  Pthread_rwlock* {.importc: "pthread_rwlock_t",
+                     header: "<sys/types.h>".} = object
+  Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
+                         header: "<sys/types.h>".} = object
+  Pthread_spinlock* {.importc: "pthread_spinlock_t",
+                       header: "<sys/types.h>".} = object
+  Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = object
+  Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int32
+  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
+  Timer* {.importc: "timer_t", header: "<sys/types.h>".} = object
+  Uid* {.importc: "uid_t", header: "<sys/types.h>".} = uint32
+  Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = uint32
+
+  Utsname* {.importc: "struct utsname",
+              header: "<sys/utsname.h>",
+              final, pure.} = object ## struct utsname
+    sysname*,        ## Name of this implementation of the operating system.
+      nodename*,     ## Name of this node within the communications
+                     ## network to which this node is attached, if any.
+      release*,      ## Current release level of this implementation.
+      version*,      ## Current version level of this release.
+      machine*: array[32, char] ## Name of the hardware type on which the
+                                ## system is running.
+
+  Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
+  Ipc_perm* {.importc: "struct ipc_perm",
+               header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
+    uid*: Uid    ## Owner's user ID.
+    gid*: Gid    ## Owner's group ID.
+    cuid*: Uid   ## Creator's user ID.
+    cgid*: Gid   ## Creator's group ID.
+    mode*: Mode  ## Read/write permission.
+
+  Stat* {.importc: "struct stat",
+           header: "<sys/stat.h>", final, pure.} = object ## struct stat
+    st_dev*: Dev          ## Device ID of device containing file.
+    st_ino*: Ino          ## File serial number.
+    st_mode*: Mode        ## Mode of file (see below).
+    st_nlink*: Nlink      ## Number of hard links to the file.
+    st_uid*: Uid          ## User ID of file.
+    st_gid*: Gid          ## Group ID of file.
+    st_rdev*: Dev         ## Device ID (if file is character or block special).
+    st_size*: Off         ## For regular files, the file size in bytes.
+                          ## For symbolic links, the length in bytes of the
+                          ## pathname contained in the symbolic link.
+                          ## For a shared memory object, the length in bytes.
+                          ## For a typed memory object, the length in bytes.
+                          ## For other file types, the use of this field is
+                          ## unspecified.
+    when StatHasNanoseconds:
+      st_atim*: Timespec  ## Time of last access.
+      st_mtim*: Timespec  ## Time of last data modification.
+      st_ctim*: Timespec  ## Time of last status change.
+    else:
+      st_atime*: Time     ## Time of last access.
+      st_mtime*: Time     ## Time of last data modification.
+      st_ctime*: Time     ## Time of last status change.
+    st_blksize*: Blksize  ## A file system-specific preferred I/O block size
+                          ## for this object. In some file system types, this
+                          ## may vary from file to file.
+    st_blocks*: Blkcnt    ## Number of blocks allocated for this object.
+
+
+  Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
+              final, pure.} = object ## struct statvfs
+    f_bsize*: culong        ## File system block size.
+    f_frsize*: culong       ## Fundamental file system block size.
+    f_blocks*: Fsblkcnt     ## Total number of blocks on file system
+                            ## in units of f_frsize.
+    f_bfree*: Fsblkcnt      ## Total number of free blocks.
+    f_bavail*: Fsblkcnt     ## Number of free blocks available to
+                            ## non-privileged process.
+    f_files*: Fsfilcnt      ## Total number of file serial numbers.
+    f_ffree*: Fsfilcnt      ## Total number of free file serial numbers.
+    f_favail*: Fsfilcnt     ## Number of file serial numbers available to
+                            ## non-privileged process.
+    f_fsid*: culong         ## File system ID.
+    f_flag*: culong         ## Bit mask of f_flag values.
+    f_namemax*: culong      ## Maximum filename length.
+
+  Tm* {.importc: "struct tm", header: "<time.h>",
+         final, pure.} = object ## struct tm
+    tm_sec*: cint   ## Seconds [0,60].
+    tm_min*: cint   ## Minutes [0,59].
+    tm_hour*: cint  ## Hour [0,23].
+    tm_mday*: cint  ## Day of month [1,31].
+    tm_mon*: cint   ## Month of year [0,11].
+    tm_year*: cint  ## Years since 1900.
+    tm_wday*: cint  ## Day of week [0,6] (Sunday =0).
+    tm_yday*: cint  ## Day of year [0,365].
+    tm_isdst*: cint ## Daylight Savings flag.
+  Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
+                 final, pure.} = object ## struct itimerspec
+    it_interval*: Timespec  ## Timer period.
+    it_value*: Timespec     ## Timer expiration.
+
+  Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
+    ## Possibly volatile-qualified integer type of an object that can be
+    ## accessed as an atomic entity, even in the presence of asynchronous
+    ## interrupts.
+  Sigset* {.importc: "sigset_t", header: "<signal.h>".} = uint64
+
+  SigEvent* {.importc: "struct sigevent",
+               header: "<signal.h>", final, pure.} = object ## struct sigevent
+    sigev_notify*: cint           ## Notification type.
+    sigev_signo*: cint            ## Signal number.
+    sigev_value*: SigVal          ## Signal value.
+    sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
+    sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
+
+  SigVal* {.importc: "union sigval",
+             header: "<signal.h>", final, pure.} = object ## struct sigval
+    sival_ptr*: pointer ## pointer signal value;
+                        ## integer signal value not defined!
+  Sigaction* {.importc: "struct sigaction",
+                header: "<signal.h>", final, pure.} = object ## struct sigaction
+    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
+                                            ## function or one of the macros
+                                            ## SIG_IGN or SIG_DFL.
+    sa_mask*: Sigset ## Set of signals to be blocked during execution of
+                      ## the signal handling function.
+    sa_flags*: cint   ## Special flags.
+    sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
+
+  Stack* {.importc: "stack_t",
+            header: "<signal.h>", final, pure.} = object ## stack_t
+    ss_sp*: pointer  ## Stack base or pointer.
+    ss_size*: csize_t ## Stack size.
+    ss_flags*: cint  ## Flags.
+
+  SigInfo* {.importc: "siginfo_t",
+              header: "<signal.h>", final, pure.} = object ## siginfo_t
+    si_signo*: cint    ## Signal number.
+    si_code*: cint     ## Signal code.
+    si_errno*: cint    ## If non-zero, an errno value associated with
+                       ## this signal, as defined in <errno.h>.
+    si_pid*: Pid       ## Sending process ID.
+    si_uid*: Uid       ## Real user ID of sending process.
+    si_addr*: pointer  ## Address of faulting instruction.
+    si_status*: cint   ## Exit value or signal.
+    si_band*: int      ## Band event for SIGPOLL.
+    si_value*: SigVal  ## Signal value.
+
+  Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
+  Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
+
+  Sched_param* {.importc: "struct sched_param",
+                  header: "<sched.h>",
+                  final, pure.} = object ## struct sched_param
+    sched_priority*: cint
+
+  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+             final, pure.} = object ## struct timeval
+    tv_sec*: Time ## Seconds.
+    tv_usec*: Suseconds ## Microseconds.
+  TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
+           final, pure.} = object
+  Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
+               final, pure.} = object
+  Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
+               final, pure.} = object ## ucontext_t
+    uc_link*: ptr Ucontext  ## Pointer to the context that is resumed
+                            ## when this context returns.
+    uc_sigmask*: Sigset     ## The set of signals that are blocked when this
+                            ## context is active.
+    uc_stack*: Stack        ## The stack used by this context.
+    uc_mcontext*: Mcontext  ## A machine-specific representation of the saved
+                            ## context.
+
+when hasAioH:
+  type
+    Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
+              final, pure.} = object ## struct aiocb
+      aio_fildes*: cint         ## File descriptor.
+      aio_offset*: Off          ## File offset.
+      aio_buf*: pointer         ## Location of buffer.
+      aio_nbytes*: int          ## Length of transfer.
+      aio_reqprio*: cint        ## Request priority offset.
+      aio_sigevent*: SigEvent   ## Signal number and value.
+      aio_lio_opcode: cint      ## Operation to be performed.
+
+when hasSpawnH:
+  type
+    Tposix_spawnattr* {.importc: "posix_spawnattr_t",
+                        header: "<spawn.h>", final, pure.} = object
+    Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
+                                 header: "<spawn.h>", final, pure.} = object
+
+when defined(linux):
+  # from sys/un.h
+  const Sockaddr_un_path_length* = 108
+elif defined(haiku):
+  # from sys/un.h
+  const Sockaddr_un_path_length* = 126
+else:
+  # according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html
+  # this is >=92
+  const Sockaddr_un_path_length* = 92
+
+type
+  SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = uint32
+  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8
+
+  SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+              pure, final.} = object ## struct sockaddr
+    sa_family*: TSa_Family         ## Address family.
+    sa_data*: array[0..255, char] ## Socket address (variable-length data).
+
+  Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
+              pure, final.} = object ## struct sockaddr_un
+    sun_family*: TSa_Family         ## Address family.
+    sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path
+
+  Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                       header: "<sys/socket.h>",
+                       pure, final.} = object ## struct sockaddr_storage
+    ss_family*: TSa_Family ## Address family.
+
+  Tif_nameindex* {.importc: "struct if_nameindex", final,
+                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
+    if_index*: cuint   ## Numeric index of the interface.
+    if_name*: cstring ## Null-terminated name of the interface.
+
+
+  IOVec* {.importc: "struct iovec", pure, final,
+            header: "<sys/uio.h>".} = object ## struct iovec
+    iov_base*: pointer ## Base address of a memory region for input or output.
+    iov_len*: csize_t  ## The size of the memory pointed to by iov_base.
+
+  Tmsghdr* {.importc: "struct msghdr", pure, final,
+             header: "<sys/socket.h>".} = object  ## struct msghdr
+    msg_name*: pointer     ## Optional address.
+    msg_namelen*: SockLen  ## Size of address.
+    msg_iov*: ptr IOVec    ## Scatter/gather array.
+    msg_iovlen*: cint      ## Members in msg_iov.
+    msg_control*: pointer  ## Ancillary data; see below.
+    msg_controllen*: SockLen ## Ancillary data buffer len.
+    msg_flags*: cint ## Flags on received message.
+
+
+  Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
+              header: "<sys/socket.h>".} = object ## struct cmsghdr
+    cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
+    cmsg_level*: cint   ## Originating protocol.
+    cmsg_type*: cint    ## Protocol-specific type.
+
+  TLinger* {.importc: "struct linger", pure, final,
+             header: "<sys/socket.h>".} = object ## struct linger
+    l_onoff*: cint  ## Indicates whether linger option is enabled.
+    l_linger*: cint ## Linger time, in seconds.
+
+  InPort* = uint16
+  InAddrScalar* = uint32
+
+  InAddrT* {.importc: "in_addr_t", pure, final,
+             header: "<netinet/in.h>".} = uint32
+
+  InAddr* {.importc: "struct in_addr", pure, final,
+             header: "<netinet/in.h>".} = object ## struct in_addr
+    s_addr*: InAddrScalar
+
+  Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
+                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
+    sin_family*: TSa_Family ## AF_INET.
+    sin_port*: InPort      ## Port number.
+    sin_addr*: InAddr      ## IP address.
+
+  In6Addr* {.importc: "struct in6_addr", pure, final,
+              header: "<netinet/in.h>".} = object ## struct in6_addr
+    s6_addr*: array[0..15, char]
+
+  Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
+                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
+    sin6_family*: TSa_Family ## AF_INET6.
+    sin6_port*: InPort      ## Port number.
+    sin6_flowinfo*: int32    ## IPv6 traffic class and flow information.
+    sin6_addr*: In6Addr     ## IPv6 address.
+    sin6_scope_id*: int32    ## Set of interfaces for a scope.
+
+  Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
+                header: "<netinet/in.h>".} = object ## struct ipv6_mreq
+    ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
+    ipv6mr_interface*: cuint     ## Interface index.
+
+  Hostent* {.importc: "struct hostent", pure, final,
+              header: "<netdb.h>".} = object ## struct hostent
+    h_name*: cstring           ## Official name of the host.
+    h_aliases*: cstringArray   ## A pointer to an array of pointers to
+                               ## alternative host names, terminated by a
+                               ## null pointer.
+    h_addrtype*: cint          ## Address type.
+    h_length*: cint            ## The length, in bytes, of the address.
+    h_addr_list*: cstringArray ## A pointer to an array of pointers to network
+                               ## addresses (in network byte order) for the
+                               ## host, terminated by a null pointer.
+
+  Tnetent* {.importc: "struct netent", pure, final,
+              header: "<netdb.h>".} = object ## struct netent
+    n_name*: cstring         ## Official, fully-qualified (including the
+                             ## domain) name of the host.
+    n_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative network names, terminated by a
+                             ## null pointer.
+    n_addrtype*: cint        ## The address type of the network.
+    n_net*: InAddrT          ## The network number, in host byte order.
+
+  Protoent* {.importc: "struct protoent", pure, final,
+              header: "<netdb.h>".} = object ## struct protoent
+    p_name*: cstring         ## Official name of the protocol.
+    p_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative protocol names, terminated by
+                             ## a null pointer.
+    p_proto*: cint           ## The protocol number.
+
+  Servent* {.importc: "struct servent", pure, final,
+             header: "<netdb.h>".} = object ## struct servent
+    s_name*: cstring         ## Official name of the service.
+    s_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative service names, terminated by
+                             ## a null pointer.
+    s_port*: cint            ## The port number at which the service
+                             ## resides, in network byte order.
+    s_proto*: cstring        ## The name of the protocol to use when
+                             ## contacting the service.
+
+  AddrInfo* {.importc: "struct addrinfo", pure, final,
+              header: "<netdb.h>".} = object ## struct addrinfo
+    ai_flags*: cint         ## Input flags.
+    ai_family*: cint        ## Address family of socket.
+    ai_socktype*: cint      ## Socket type.
+    ai_protocol*: cint      ## Protocol of socket.
+    ai_addrlen*: SockLen   ## Length of socket address.
+    ai_addr*: ptr SockAddr ## Socket address of socket.
+    ai_canonname*: cstring  ## Canonical name of service location.
+    ai_next*: ptr AddrInfo ## Pointer to next in list.
+
+  TPollfd* {.importc: "struct pollfd", pure, final,
+             header: "<poll.h>".} = object ## struct pollfd
+    fd*: cint        ## The following descriptor being polled.
+    events*: cshort  ## The input event flags (see below).
+    revents*: cshort ## The output event flags (see below).
+
+  Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
+
+var
+  errno* {.importc, header: "<errno.h>".}: cint ## error variable
+  h_errno* {.importc, header: "<netdb.h>".}: cint
+  daylight* {.importc, header: "<time.h>".}: cint
+  timezone* {.importc, header: "<time.h>".}: int
+
+# Regenerate using detect.nim!
+include posix_other_consts
+
+when defined(linux):
+  var
+    MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
+      ## Populate (prefault) page tables for a mapping.
+else:
+  var
+    MAP_POPULATE*: cint = 0
+
+when defined(linux) or defined(nimdoc):
+  when defined(alpha) or defined(mips) or defined(mipsel) or
+      defined(mips64) or defined(mips64el) or defined(parisc) or
+      defined(sparc) or defined(sparc64) or defined(nimdoc):
+    const SO_REUSEPORT* = cint(0x0200)
+      ## Multiple binding: load balancing on incoming TCP connections
+      ## or UDP packets. (Requires Linux kernel > 3.9)
+  else:
+    const SO_REUSEPORT* = cint(15)
+else:
+  var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint
+
+when defined(macosx):
+  # We can't use the NOSIGNAL flag in the `send` function, it has no effect
+  # Instead we should use SO_NOSIGPIPE in setsockopt
+  const
+    MSG_NOSIGNAL* = 0'i32
+  var
+    SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
+elif defined(solaris):
+  # Solaris doesn't have MSG_NOSIGNAL
+  const
+    MSG_NOSIGNAL* = 0'i32
+else:
+  var
+    MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
+      ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected.
+
+when defined(haiku):
+  const
+    SIGKILLTHR* = 21 ## BeOS specific: Kill just the thread, not team
+
+when hasSpawnH:
+  when defined(linux):
+    # better be safe than sorry; Linux has this flag, macosx doesn't, don't
+    # know about the other OSes
+
+    # Non-GNU systems like TCC and musl-libc  don't define __USE_GNU, so we
+    # can't get the magic number from spawn.h
+    const POSIX_SPAWN_USEVFORK* = cint(0x40)
+  else:
+    # macosx lacks this, so we define the constant to be 0 to not affect
+    # OR'ing of flags:
+    const POSIX_SPAWN_USEVFORK* = cint(0)
+
+# <sys/wait.h>
+proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Exit code, if WIFEXITED(s)
+proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Termination signal, if WIFSIGNALED(s)
+proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Stop signal, if WIFSTOPPED(s)
+proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited normally.
+proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited due to uncaught signal.
+proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child is currently stopped.
+proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child has been continued.
+
+when defined(nimHasStyleChecks):
+  {.pop.}
diff --git a/lib/posix/posix_linux_amd64.nim b/lib/posix/posix_linux_amd64.nim
new file mode 100644
index 000000000..8d11c507d
--- /dev/null
+++ b/lib/posix/posix_linux_amd64.nim
@@ -0,0 +1,587 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2012 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+# Types here should conform to the glibc ABI on linux / x86_64
+# When adding a type, the order and size of fields must match
+
+# To be included from posix.nim!
+
+const
+  hasSpawnH = not defined(haiku) # should exist for every Posix system nowadays
+  hasAioH = defined(linux)
+
+# On Linux:
+# timer_{create,delete,settime,gettime},
+# clock_{getcpuclockid, getres, gettime, nanosleep, settime} lives in librt
+{.passl: "-lrt".}
+
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+# Types
+
+type
+  DIR* {.importc: "DIR", header: "<dirent.h>",
+          incompleteStruct.} = object
+    ## A type representing a directory stream.
+
+type
+  SocketHandle* = distinct cint # The type used to represent socket descriptors
+
+type
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct clong
+
+  Timespec* {.importc: "struct timespec",
+               header: "<time.h>", final, pure.} = object ## struct timespec
+    tv_sec*: Time  ## Seconds.
+    tv_nsec*: clong  ## Nanoseconds.
+
+  Dirent* {.importc: "struct dirent",
+            header: "<dirent.h>", final, pure.} = object ## dirent_t struct
+    d_ino*: Ino
+    d_off*: Off
+    d_reclen*: cushort
+    d_type*: int8  # uint8 really!
+    d_name*: array[256, cchar]
+
+  Tflock* {.importc: "struct flock", final, pure,
+            header: "<fcntl.h>".} = object ## flock type
+    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+    l_whence*: cshort ## Flag for starting offset.
+    l_start*: Off     ## Relative offset in bytes.
+    l_len*: Off       ## Size; if 0 then until EOF.
+    l_pid*: Pid      ## Process ID of the process holding the lock;
+                      ## returned with F_GETLK.
+
+  # no struct FTW on linux
+
+  Glob* {.importc: "glob_t", header: "<glob.h>",
+           final, pure.} = object ## glob_t
+    gl_pathc*: csize_t            ## Count of paths matched by pattern.
+    gl_pathv*: cstringArray       ## Pointer to a list of matched pathnames.
+    gl_offs*: csize_t             ## Slots to reserve at the beginning of gl_pathv.
+    gl_flags*: cint
+    gl_closedir*: pointer
+    gl_readdir*: pointer
+    gl_opendir*: pointer
+    gl_lstat*: pointer
+    gl_stat*: pointer
+
+  Group* {.importc: "struct group", header: "<grp.h>",
+            final, pure.} = object ## struct group
+    gr_name*: cstring     ## The name of the group.
+    gr_passwd*: cstring
+    gr_gid*: Gid         ## Numerical group ID.
+    gr_mem*: cstringArray ## Pointer to a null-terminated array of character
+                          ## pointers to member names.
+
+  Iconv* {.importc: "iconv_t", header: "<iconv.h>".} = pointer
+     ## Identifies the conversion from one codeset to another.
+
+  Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
+            pure.} = object
+    decimal_point*: cstring
+    thousands_sep*: cstring
+    grouping*: cstring
+    int_curr_symbol*: cstring
+    currency_symbol*: cstring
+    mon_decimal_point*: cstring
+    mon_thousands_sep*: cstring
+    mon_grouping*: cstring
+    positive_sign*: cstring
+    negative_sign*: cstring
+    int_frac_digits*: char
+    frac_digits*: char
+    p_cs_precedes*: char
+    p_sep_by_space*: char
+    n_cs_precedes*: char
+    n_sep_by_space*: char
+    p_sign_posn*: char
+    n_sign_posn*: char
+    int_p_cs_precedes*: char
+    int_p_sep_by_space*: char
+    int_n_cs_precedes*: char
+    int_n_sep_by_space*: char
+    int_p_sign_posn*: char
+    int_n_sign_posn*: char
+
+  Mqd* {.importc: "mqd_t", header: "<mqueue.h>".} = cint
+  MqAttr* {.importc: "struct mq_attr",
+             header: "<mqueue.h>",
+             final, pure.} = object ## message queue attribute
+    mq_flags*: clong   ## Message queue flags.
+    mq_maxmsg*: clong  ## Maximum number of messages.
+    mq_msgsize*: clong ## Maximum message size.
+    mq_curmsgs*: clong ## Number of messages currently queued.
+    pad: array[4, clong]
+
+  Passwd* {.importc: "struct passwd", header: "<pwd.h>",
+             final, pure.} = object ## struct passwd
+    pw_name*: cstring   ## User's login name.
+    pw_passwd*: cstring
+    pw_uid*: Uid        ## Numerical user ID.
+    pw_gid*: Gid        ## Numerical group ID.
+    pw_gecos*: cstring
+    pw_dir*: cstring    ## Initial working directory.
+    pw_shell*: cstring  ## Program to use as shell.
+
+  Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = clong
+    ## used for file block counts
+  Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = clong
+    ## used for block sizes
+  Clock* {.importc: "clock_t", header: "<sys/types.h>".} = clong
+  ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = cint
+  Dev* {.importc: "dev_t", header: "<sys/types.h>".} = culong
+  Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = culong
+  Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = culong
+  Gid* {.importc: "gid_t", header: "<sys/types.h>".} = cuint
+  Id* {.importc: "id_t", header: "<sys/types.h>".} = cuint
+  Ino* {.importc: "ino_t", header: "<sys/types.h>".} = culong
+  Key* {.importc: "key_t", header: "<sys/types.h>".} = cint
+  Mode* {.importc: "mode_t", header: "<sys/types.h>".} = uint32
+  Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = culong
+  Off* {.importc: "off_t", header: "<sys/types.h>".} = clong
+  Pid* {.importc: "pid_t", header: "<sys/types.h>".} = cint
+  Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>",
+                  pure, final.} = object
+    abi: array[56 div sizeof(clong), clong]
+
+  Pthread_barrier* {.importc: "pthread_barrier_t",
+                      header: "<sys/types.h>", pure, final.} = object
+    abi: array[32 div sizeof(clong), clong]
+  Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
+                          header: "<sys/types.h>", pure, final.} = object
+    abi: array[4 div sizeof(cint), cint]
+
+  Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>",
+                  pure, final.} = object
+    abi: array[48 div sizeof(clonglong), clonglong]
+  Pthread_condattr* {.importc: "pthread_condattr_t",
+                       header: "<sys/types.h>", pure, final.} = object
+    abi: array[4 div sizeof(cint), cint]
+  Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = cuint
+  Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>",
+                   pure, final.} = object
+    abi: array[40 div sizeof(clong), clong]
+  Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
+                        header: "<sys/types.h>", pure, final.} = object
+    abi: array[4 div sizeof(cint), cint]
+  Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = cint
+  Pthread_rwlock* {.importc: "pthread_rwlock_t",
+                     header: "<sys/types.h>", pure, final.} = object
+    abi: array[56 div sizeof(clong), clong]
+  Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
+                         header: "<sys/types.h>".} = object
+    abi: array[8 div sizeof(clong), clong]
+  Pthread_spinlock* {.importc: "pthread_spinlock_t",
+                       header: "<sys/types.h>".} = cint
+  Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = culong
+  Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = clong
+  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
+  Timer* {.importc: "timer_t", header: "<sys/types.h>".} = pointer
+  Uid* {.importc: "uid_t", header: "<sys/types.h>".} = cuint
+  Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = cuint
+
+  Utsname* {.importc: "struct utsname",
+              header: "<sys/utsname.h>",
+              final, pure.} = object ## struct utsname
+    sysname*,      ## Name of this implementation of the operating system.
+      nodename*,   ## Name of this node within the communications
+                   ## network to which this node is attached, if any.
+      release*,    ## Current release level of this implementation.
+      version*,    ## Current version level of this release.
+      machine*,    ## Name of the hardware type on which the
+                   ## system is running.
+      domainname*: array[65, char]
+
+  Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
+    abi: array[32 div sizeof(clong), clong]
+
+  Ipc_perm* {.importc: "struct ipc_perm",
+               header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
+    key: Key
+    uid*: Uid    ## Owner's user ID.
+    gid*: Gid    ## Owner's group ID.
+    cuid*: Uid   ## Creator's user ID.
+    cgid*: Gid   ## Creator's group ID.
+    mode*: cshort  ## Read/write permission.
+    pad1: cshort
+    seq1: cshort
+    pad2: cshort
+    reserved1: culong
+    reserved2: culong
+
+  Stat* {.importc: "struct stat",
+           header: "<sys/stat.h>", final, pure.} = object ## struct stat
+    st_dev*: Dev          ## Device ID of device containing file.
+    st_ino*: Ino          ## File serial number.
+    st_nlink*: Nlink      ## Number of hard links to the file.
+    st_mode*: Mode        ## Mode of file (see below).
+    st_uid*: Uid          ## User ID of file.
+    st_gid*: Gid          ## Group ID of file.
+    pad0 {.importc: "__pad0".}: cint
+    st_rdev*: Dev         ## Device ID (if file is character or block special).
+    st_size*: Off         ## For regular files, the file size in bytes.
+                           ## For symbolic links, the length in bytes of the
+                           ## pathname contained in the symbolic link.
+                           ## For a shared memory object, the length in bytes.
+                           ## For a typed memory object, the length in bytes.
+                           ## For other file types, the use of this field is
+                           ## unspecified.
+    st_blksize*: Blksize   ## A file system-specific preferred I/O block size
+                           ## for this object. In some file system types, this
+                           ## may vary from file to file.
+    st_blocks*: Blkcnt     ## Number of blocks allocated for this object.
+    st_atim*: Timespec   ## Time of last access.
+    st_mtim*: Timespec   ## Time of last data modification.
+    st_ctim*: Timespec   ## Time of last status change.
+
+  Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
+              final, pure.} = object ## struct statvfs
+    f_bsize*: culong        ## File system block size.
+    f_frsize*: culong       ## Fundamental file system block size.
+    f_blocks*: Fsblkcnt  ## Total number of blocks on file system
+                         ## in units of f_frsize.
+    f_bfree*: Fsblkcnt   ## Total number of free blocks.
+    f_bavail*: Fsblkcnt  ## Number of free blocks available to
+                         ## non-privileged process.
+    f_files*: Fsfilcnt   ## Total number of file serial numbers.
+    f_ffree*: Fsfilcnt   ## Total number of free file serial numbers.
+    f_favail*: Fsfilcnt  ## Number of file serial numbers available to
+                         ## non-privileged process.
+    f_fsid*: culong         ## File system ID.
+    f_flag*: culong         ## Bit mask of f_flag values.
+    f_namemax*: culong      ## Maximum filename length.
+    f_spare: array[6, cint]
+
+  # No Posix_typed_mem_info
+
+  Tm* {.importc: "struct tm", header: "<time.h>",
+         final, pure.} = object ## struct tm
+    tm_sec*: cint   ## Seconds [0,60].
+    tm_min*: cint   ## Minutes [0,59].
+    tm_hour*: cint  ## Hour [0,23].
+    tm_mday*: cint  ## Day of month [1,31].
+    tm_mon*: cint   ## Month of year [0,11].
+    tm_year*: cint  ## Years since 1900.
+    tm_wday*: cint  ## Day of week [0,6] (Sunday =0).
+    tm_yday*: cint  ## Day of year [0,365].
+    tm_isdst*: cint ## Daylight Savings flag.
+    tm_gmtoff*: clong
+    tm_zone*: cstring
+
+  Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
+                 final, pure.} = object ## struct itimerspec
+    it_interval*: Timespec  ## Timer period.
+    it_value*: Timespec     ## Timer expiration.
+
+  Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
+    ## Possibly volatile-qualified integer type of an object that can be
+    ## accessed as an atomic entity, even in the presence of asynchronous
+    ## interrupts.
+  Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
+    abi: array[1024 div (8 * sizeof(culong)), culong]
+
+  SigEvent* {.importc: "struct sigevent",
+               header: "<signal.h>", final, pure.} = object ## struct sigevent
+    sigev_value*: SigVal          ## Signal value.
+    sigev_signo*: cint            ## Signal number.
+    sigev_notify*: cint           ## Notification type.
+    sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
+    sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
+    abi: array[12, int]
+
+  SigVal* {.importc: "union sigval",
+             header: "<signal.h>", final, pure.} = object ## struct sigval
+    sival_ptr*: pointer ## pointer signal value;
+                        ## integer signal value not defined!
+  Sigaction* {.importc: "struct sigaction",
+                header: "<signal.h>", final, pure.} = object ## struct sigaction
+    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
+                                            ## function or one of the macros
+                                            ## SIG_IGN or SIG_DFL.
+    sa_mask*: Sigset ## Set of signals to be blocked during execution of
+                      ## the signal handling function.
+    sa_flags*: cint   ## Special flags.
+    sa_restorer: proc() {.noconv.}   ## not intended for application use.
+
+  Stack* {.importc: "stack_t",
+            header: "<signal.h>", final, pure.} = object ## stack_t
+    ss_sp*: pointer  ## Stack base or pointer.
+    ss_size*: int    ## Stack size.
+    ss_flags*: cint  ## Flags.
+
+  SigStack* {.importc: "struct sigstack",
+               header: "<signal.h>", final, pure.} = object ## struct sigstack
+    ss_onstack*: cint ## Non-zero when signal stack is in use.
+    ss_sp*: pointer   ## Signal stack pointer.
+
+  SigInfo* {.importc: "siginfo_t",
+              header: "<signal.h>", final, pure.} = object ## siginfo_t
+    si_signo*: cint    ## Signal number.
+    si_errno*: cint    ## If non-zero, an errno value associated with
+                       ## this signal, as defined in <errno.h>.
+    si_code*: cint     ## Signal code.
+    si_pid*: Pid       ## Sending process ID.
+    si_uid*: Uid       ## Real user ID of sending process.
+    si_addr*: pointer  ## Address of faulting instruction.
+    si_status*: cint   ## Exit value or signal.
+    si_band*: int      ## Band event for SIGPOLL.
+    si_value*: SigVal  ## Signal value.
+    pad {.importc: "_pad".}: array[128 - 56, uint8]
+
+template sa_sigaction*(v: Sigaction): proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.} =
+  cast[proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}](v.sa_handler)
+proc `sa_sigaction=`*(v: var Sigaction, x: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}) =
+  v.sa_handler = cast[proc (x: cint) {.noconv.}](x)
+
+type
+  Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
+  Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = pointer
+
+  Sched_param* {.importc: "struct sched_param",
+                  header: "<sched.h>",
+                  final, pure.} = object ## struct sched_param
+    sched_priority*: cint
+
+  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+             final, pure.} = object ## struct timeval
+    tv_sec*: Time       ## Seconds.
+    tv_usec*: Suseconds ## Microseconds.
+  TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
+           final, pure.} = object
+    abi: array[1024 div (8 * sizeof(clong)), clong]
+
+  Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
+               final, pure.} = object
+    gregs: array[23, clonglong]
+    fpregs: pointer
+    reserved1: array[8, clonglong]
+
+  Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
+               final, pure.} = object ## ucontext_t
+    uc_flags: clong
+    uc_link*: ptr Ucontext  ## Pointer to the context that is resumed
+                            ## when this context returns.
+    uc_stack*: Stack        ## The stack used by this context.
+    uc_mcontext*: Mcontext  ## A machine-specific representation of the saved
+                            ## context.
+    uc_sigmask*: Sigset     ## The set of signals that are blocked when this
+                            ## context is active.
+    # todo fpregds_mem
+
+type
+  Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
+            final, pure.} = object ## struct aiocb
+    aio_fildes*: cint         ## File descriptor.
+    aio_lio_opcode*: cint     ## Operation to be performed.
+    aio_reqprio*: cint        ## Request priority offset.
+    aio_buf*: pointer         ## Location of buffer.
+    aio_nbytes*: csize_t        ## Length of transfer.
+    aio_sigevent*: SigEvent   ## Signal number and value.
+    next_prio: pointer
+    abs_prio: cint
+    policy: cint
+    error_Code: cint
+    return_value: clong
+    aio_offset*: Off          ## File offset.
+    reserved: array[32, uint8]
+
+
+when hasSpawnH:
+  type
+    Tposix_spawnattr* {.importc: "posix_spawnattr_t",
+                        header: "<spawn.h>", final, pure.} = object
+      flags: cshort
+      pgrp: Pid
+      sd: Sigset
+      ss: Sigset
+      sp: Sched_param
+      policy: cint
+      pad: array[16, cint]
+
+    Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
+                                 header: "<spawn.h>", final, pure.} = object
+      allocated: cint
+      used: cint
+      actions: pointer
+      pad: array[16, cint]
+
+# from sys/un.h
+const Sockaddr_un_path_length* = 108
+
+type
+  SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
+  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cushort
+
+  SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+              pure, final.} = object ## struct sockaddr
+    sa_family*: TSa_Family         ## Address family.
+    sa_data*: array[14, char] ## Socket address (variable-length data).
+
+  Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
+              pure, final.} = object ## struct sockaddr_un
+    sun_family*: TSa_Family         ## Address family.
+    sun_path*: array[108, char] ## Socket path
+
+  Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                       header: "<sys/socket.h>",
+                       pure, final.} = object ## struct sockaddr_storage
+    ss_family*: TSa_Family ## Address family.
+    ss_padding {.importc: "__ss_padding".}: array[128 - sizeof(cshort) - sizeof(culong), char]
+    ss_align {.importc: "__ss_align".}: clong
+
+  Tif_nameindex* {.importc: "struct if_nameindex", final,
+                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
+    if_index*: cuint   ## Numeric index of the interface.
+    if_name*: cstring ## Null-terminated name of the interface.
+
+
+  IOVec* {.importc: "struct iovec", pure, final,
+            header: "<sys/uio.h>".} = object ## struct iovec
+    iov_base*: pointer ## Base address of a memory region for input or output.
+    iov_len*: csize_t    ## The size of the memory pointed to by iov_base.
+
+  Tmsghdr* {.importc: "struct msghdr", pure, final,
+             header: "<sys/socket.h>".} = object  ## struct msghdr
+    msg_name*: pointer  ## Optional address.
+    msg_namelen*: SockLen  ## Size of address.
+    msg_iov*: ptr IOVec    ## Scatter/gather array.
+    msg_iovlen*: csize_t   ## Members in msg_iov.
+    msg_control*: pointer  ## Ancillary data; see below.
+    msg_controllen*: csize_t ## Ancillary data buffer len.
+    msg_flags*: cint ## Flags on received message.
+
+
+  Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
+              header: "<sys/socket.h>".} = object ## struct cmsghdr
+    cmsg_len*: csize_t ## Data byte count, including the cmsghdr.
+    cmsg_level*: cint   ## Originating protocol.
+    cmsg_type*: cint    ## Protocol-specific type.
+
+  TLinger* {.importc: "struct linger", pure, final,
+             header: "<sys/socket.h>".} = object ## struct linger
+    l_onoff*: cint  ## Indicates whether linger option is enabled.
+    l_linger*: cint ## Linger time, in seconds.
+    # data follows...
+
+  InPort* = uint16
+  InAddrScalar* = uint32
+
+  InAddrT* {.importc: "in_addr_t", pure, final,
+             header: "<netinet/in.h>".} = uint32
+
+  InAddr* {.importc: "struct in_addr", pure, final,
+             header: "<netinet/in.h>".} = object ## struct in_addr
+    s_addr*: InAddrScalar
+
+  Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
+                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
+    sin_family*: TSa_Family ## AF_INET.
+    sin_port*: InPort      ## Port number.
+    sin_addr*: InAddr      ## IP address.
+    sin_zero: array[16 - 2 - 2 - 4, uint8]
+
+  In6Addr* {.importc: "struct in6_addr", pure, final,
+              header: "<netinet/in.h>".} = object ## struct in6_addr
+    s6_addr*: array[0..15, char]
+
+  Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
+                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
+    sin6_family*: TSa_Family ## AF_INET6.
+    sin6_port*: InPort      ## Port number.
+    sin6_flowinfo*: uint32    ## IPv6 traffic class and flow information.
+    sin6_addr*: In6Addr     ## IPv6 address.
+    sin6_scope_id*: uint32    ## Set of interfaces for a scope.
+
+  Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
+                header: "<netinet/in.h>".} = object ## struct ipv6_mreq
+    ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
+    ipv6mr_interface*: cuint     ## Interface index.
+
+  Hostent* {.importc: "struct hostent", pure, final,
+              header: "<netdb.h>".} = object ## struct hostent
+    h_name*: cstring           ## Official name of the host.
+    h_aliases*: cstringArray   ## A pointer to an array of pointers to
+                               ## alternative host names, terminated by a
+                               ## null pointer.
+    h_addrtype*: cint          ## Address type.
+    h_length*: cint            ## The length, in bytes, of the address.
+    h_addr_list*: cstringArray ## A pointer to an array of pointers to network
+                               ## addresses (in network byte order) for the
+                               ## host, terminated by a null pointer.
+
+  Tnetent* {.importc: "struct netent", pure, final,
+              header: "<netdb.h>".} = object ## struct netent
+    n_name*: cstring         ## Official, fully-qualified (including the
+                             ## domain) name of the host.
+    n_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative network names, terminated by a
+                             ## null pointer.
+    n_addrtype*: cint        ## The address type of the network.
+    n_net*: uint32            ## The network number, in host byte order.
+
+  Protoent* {.importc: "struct protoent", pure, final,
+              header: "<netdb.h>".} = object ## struct protoent
+    p_name*: cstring         ## Official name of the protocol.
+    p_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative protocol names, terminated by
+                             ## a null pointer.
+    p_proto*: cint           ## The protocol number.
+
+  Servent* {.importc: "struct servent", pure, final,
+             header: "<netdb.h>".} = object ## struct servent
+    s_name*: cstring         ## Official name of the service.
+    s_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative service names, terminated by
+                             ## a null pointer.
+    s_port*: cint            ## The port number at which the service
+                             ## resides, in network byte order.
+    s_proto*: cstring        ## The name of the protocol to use when
+                             ## contacting the service.
+
+  AddrInfo* {.importc: "struct addrinfo", pure, final,
+              header: "<netdb.h>".} = object ## struct addrinfo
+    ai_flags*: cint         ## Input flags.
+    ai_family*: cint        ## Address family of socket.
+    ai_socktype*: cint      ## Socket type.
+    ai_protocol*: cint      ## Protocol of socket.
+    ai_addrlen*: SockLen   ## Length of socket address.
+    ai_addr*: ptr SockAddr ## Socket address of socket.
+    ai_canonname*: cstring  ## Canonical name of service location.
+    ai_next*: ptr AddrInfo ## Pointer to next in list.
+
+  TPollfd* {.importc: "struct pollfd", pure, final,
+             header: "<poll.h>".} = object ## struct pollfd
+    fd*: cint        ## The following descriptor being polled.
+    events*: cshort  ## The input event flags (see below).
+    revents*: cshort ## The output event flags (see below).
+
+  Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
+
+var
+  errno* {.importc, header: "<errno.h>".}: cint ## error variable
+  h_errno* {.importc, header: "<netdb.h>".}: cint
+  daylight* {.importc, header: "<time.h>".}: cint
+  timezone* {.importc, header: "<time.h>".}: clong
+
+# Regenerate using detect.nim!
+include posix_linux_amd64_consts
+
+# <sys/wait.h>
+proc WEXITSTATUS*(s: cint): cint =  (s and 0xff00) shr 8
+proc WTERMSIG*(s:cint): cint = s and 0x7f
+proc WSTOPSIG*(s:cint): cint = WEXITSTATUS(s)
+proc WIFEXITED*(s:cint) : bool = WTERMSIG(s) == 0
+proc WIFSIGNALED*(s:cint) : bool = (cast[int8]((s and 0x7f) + 1) shr 1) > 0
+proc WIFSTOPPED*(s:cint) : bool = (s and 0xff) == 0x7f
+proc WIFCONTINUED*(s:cint) : bool = s == WCONTINUED
+
+when defined(nimHasStyleChecks):
+  {.pop.} # {.push styleChecks: off.}
diff --git a/lib/posix/posix_linux_amd64_consts.nim b/lib/posix/posix_linux_amd64_consts.nim
new file mode 100644
index 000000000..fbe8d0666
--- /dev/null
+++ b/lib/posix/posix_linux_amd64_consts.nim
@@ -0,0 +1,730 @@
+# Generated by detect.nim
+
+
+# <aio.h>
+const AIO_ALLDONE* = cint(2)
+const AIO_CANCELED* = cint(0)
+const AIO_NOTCANCELED* = cint(1)
+const LIO_NOP* = cint(2)
+const LIO_NOWAIT* = cint(1)
+const LIO_READ* = cint(0)
+const LIO_WAIT* = cint(0)
+const LIO_WRITE* = cint(1)
+
+# <dlfcn.h>
+const RTLD_LAZY* = cint(1)
+const RTLD_NOW* = cint(2)
+const RTLD_GLOBAL* = cint(256)
+const RTLD_LOCAL* = cint(0)
+
+# <errno.h>
+const E2BIG* = cint(7)
+const EACCES* = cint(13)
+const EADDRINUSE* = cint(98)
+const EADDRNOTAVAIL* = cint(99)
+const EAFNOSUPPORT* = cint(97)
+const EAGAIN* = cint(11)
+const EALREADY* = cint(114)
+const EBADF* = cint(9)
+const EBADMSG* = cint(74)
+const EBUSY* = cint(16)
+const ECANCELED* = cint(125)
+const ECHILD* = cint(10)
+const ECONNABORTED* = cint(103)
+const ECONNREFUSED* = cint(111)
+const ECONNRESET* = cint(104)
+const EDEADLK* = cint(35)
+const EDESTADDRREQ* = cint(89)
+const EDOM* = cint(33)
+const EDQUOT* = cint(122)
+const EEXIST* = cint(17)
+const EFAULT* = cint(14)
+const EFBIG* = cint(27)
+const EHOSTUNREACH* = cint(113)
+const EIDRM* = cint(43)
+const EILSEQ* = cint(84)
+const EINPROGRESS* = cint(115)
+const EINTR* = cint(4)
+const EINVAL* = cint(22)
+const EIO* = cint(5)
+const EISCONN* = cint(106)
+const EISDIR* = cint(21)
+const ELOOP* = cint(40)
+const EMFILE* = cint(24)
+const EMLINK* = cint(31)
+const EMSGSIZE* = cint(90)
+const EMULTIHOP* = cint(72)
+const ENAMETOOLONG* = cint(36)
+const ENETDOWN* = cint(100)
+const ENETRESET* = cint(102)
+const ENETUNREACH* = cint(101)
+const ENFILE* = cint(23)
+const ENOBUFS* = cint(105)
+const ENODATA* = cint(61)
+const ENODEV* = cint(19)
+const ENOENT* = cint(2)
+const ENOEXEC* = cint(8)
+const ENOLCK* = cint(37)
+const ENOLINK* = cint(67)
+const ENOMEM* = cint(12)
+const ENOMSG* = cint(42)
+const ENOPROTOOPT* = cint(92)
+const ENOSPC* = cint(28)
+const ENOSR* = cint(63)
+const ENOSTR* = cint(60)
+const ENOSYS* = cint(38)
+const ENOTCONN* = cint(107)
+const ENOTDIR* = cint(20)
+const ENOTEMPTY* = cint(39)
+const ENOTSOCK* = cint(88)
+const ENOTSUP* = cint(95)
+const ENOTTY* = cint(25)
+const ENXIO* = cint(6)
+const EOPNOTSUPP* = cint(95)
+const EOVERFLOW* = cint(75)
+const EPERM* = cint(1)
+const EPIPE* = cint(32)
+const EPROTO* = cint(71)
+const EPROTONOSUPPORT* = cint(93)
+const EPROTOTYPE* = cint(91)
+const ERANGE* = cint(34)
+const EROFS* = cint(30)
+const ESPIPE* = cint(29)
+const ESRCH* = cint(3)
+const ESTALE* = cint(116)
+const ETIME* = cint(62)
+const ETIMEDOUT* = cint(110)
+const ETXTBSY* = cint(26)
+const EWOULDBLOCK* = cint(11)
+const EXDEV* = cint(18)
+
+# <fcntl.h>
+const F_DUPFD* = cint(0)
+const F_DUPFD_CLOEXEC* = cint(1030)
+const F_GETFD* = cint(1)
+const F_SETFD* = cint(2)
+const F_GETFL* = cint(3)
+const F_SETFL* = cint(4)
+const F_GETLK* = cint(5)
+const F_SETLK* = cint(6)
+const F_SETLKW* = cint(7)
+const F_GETOWN* = cint(9)
+const F_SETOWN* = cint(8)
+const FD_CLOEXEC* = cint(1)
+const F_RDLCK* = cint(0)
+const F_UNLCK* = cint(2)
+const F_WRLCK* = cint(1)
+const O_CREAT* = cint(64)
+const O_EXCL* = cint(128)
+const O_NOCTTY* = cint(256)
+const O_TRUNC* = cint(512)
+const O_APPEND* = cint(1024)
+const O_DSYNC* = cint(4096)
+const O_NONBLOCK* = cint(2048)
+const O_RSYNC* = cint(1052672)
+const O_SYNC* = cint(1052672)
+const O_ACCMODE* = cint(3)
+const O_RDONLY* = cint(0)
+const O_RDWR* = cint(2)
+const O_WRONLY* = cint(1)
+const O_CLOEXEC* = cint(524288)
+const O_DIRECT* = cint(16384)
+const O_PATH* = cint(2097152)
+const O_NOATIME* = cint(262144)
+const O_TMPFILE* = cint(4259840)
+const POSIX_FADV_NORMAL* = cint(0)
+const POSIX_FADV_SEQUENTIAL* = cint(2)
+const POSIX_FADV_RANDOM* = cint(1)
+const POSIX_FADV_WILLNEED* = cint(3)
+const POSIX_FADV_DONTNEED* = cint(4)
+const POSIX_FADV_NOREUSE* = cint(5)
+
+# <fenv.h>
+const FE_DIVBYZERO* = cint(4)
+const FE_INEXACT* = cint(32)
+const FE_INVALID* = cint(1)
+const FE_OVERFLOW* = cint(8)
+const FE_UNDERFLOW* = cint(16)
+const FE_ALL_EXCEPT* = cint(61)
+const FE_DOWNWARD* = cint(1024)
+const FE_TONEAREST* = cint(0)
+const FE_TOWARDZERO* = cint(3072)
+const FE_UPWARD* = cint(2048)
+const FE_DFL_ENV* = cint(-1)
+
+# <fmtmsg.h>
+const MM_HARD* = cint(1)
+const MM_SOFT* = cint(2)
+const MM_FIRM* = cint(4)
+const MM_APPL* = cint(8)
+const MM_UTIL* = cint(16)
+const MM_OPSYS* = cint(32)
+const MM_RECOVER* = cint(64)
+const MM_NRECOV* = cint(128)
+const MM_HALT* = cint(1)
+const MM_ERROR* = cint(2)
+const MM_WARNING* = cint(3)
+const MM_INFO* = cint(4)
+const MM_NOSEV* = cint(0)
+const MM_PRINT* = cint(256)
+const MM_CONSOLE* = cint(512)
+const MM_OK* = cint(0)
+const MM_NOTOK* = cint(-1)
+const MM_NOMSG* = cint(1)
+const MM_NOCON* = cint(4)
+
+# <fnmatch.h>
+const FNM_NOMATCH* = cint(1)
+const FNM_PATHNAME* = cint(1)
+const FNM_PERIOD* = cint(4)
+const FNM_NOESCAPE* = cint(2)
+const FNM_NOSYS* = cint(-1)
+
+# <ftw.h>
+const FTW_F* = cint(0)
+const FTW_D* = cint(1)
+const FTW_DNR* = cint(2)
+const FTW_DP* = cint(5)
+const FTW_NS* = cint(3)
+const FTW_SL* = cint(4)
+const FTW_SLN* = cint(6)
+const FTW_PHYS* = cint(1)
+const FTW_MOUNT* = cint(2)
+const FTW_DEPTH* = cint(8)
+const FTW_CHDIR* = cint(4)
+
+# <glob.h>
+const GLOB_APPEND* = cint(32)
+const GLOB_DOOFFS* = cint(8)
+const GLOB_ERR* = cint(1)
+const GLOB_MARK* = cint(2)
+const GLOB_NOCHECK* = cint(16)
+const GLOB_NOESCAPE* = cint(64)
+const GLOB_NOSORT* = cint(4)
+const GLOB_ABORTED* = cint(2)
+const GLOB_NOMATCH* = cint(3)
+const GLOB_NOSPACE* = cint(1)
+const GLOB_NOSYS* = cint(4)
+
+# <langinfo.h>
+const CODESET* = cint(14)
+const D_T_FMT* = cint(131112)
+const D_FMT* = cint(131113)
+const T_FMT* = cint(131114)
+const T_FMT_AMPM* = cint(131115)
+const AM_STR* = cint(131110)
+const PM_STR* = cint(131111)
+const DAY_1* = cint(131079)
+const DAY_2* = cint(131080)
+const DAY_3* = cint(131081)
+const DAY_4* = cint(131082)
+const DAY_5* = cint(131083)
+const DAY_6* = cint(131084)
+const DAY_7* = cint(131085)
+const ABDAY_1* = cint(131072)
+const ABDAY_2* = cint(131073)
+const ABDAY_3* = cint(131074)
+const ABDAY_4* = cint(131075)
+const ABDAY_5* = cint(131076)
+const ABDAY_6* = cint(131077)
+const ABDAY_7* = cint(131078)
+const MON_1* = cint(131098)
+const MON_2* = cint(131099)
+const MON_3* = cint(131100)
+const MON_4* = cint(131101)
+const MON_5* = cint(131102)
+const MON_6* = cint(131103)
+const MON_7* = cint(131104)
+const MON_8* = cint(131105)
+const MON_9* = cint(131106)
+const MON_10* = cint(131107)
+const MON_11* = cint(131108)
+const MON_12* = cint(131109)
+const ABMON_1* = cint(131086)
+const ABMON_2* = cint(131087)
+const ABMON_3* = cint(131088)
+const ABMON_4* = cint(131089)
+const ABMON_5* = cint(131090)
+const ABMON_6* = cint(131091)
+const ABMON_7* = cint(131092)
+const ABMON_8* = cint(131093)
+const ABMON_9* = cint(131094)
+const ABMON_10* = cint(131095)
+const ABMON_11* = cint(131096)
+const ABMON_12* = cint(131097)
+const ERA* = cint(131116)
+const ERA_D_FMT* = cint(131118)
+const ERA_D_T_FMT* = cint(131120)
+const ERA_T_FMT* = cint(131121)
+const ALT_DIGITS* = cint(131119)
+const RADIXCHAR* = cint(65536)
+const THOUSEP* = cint(65537)
+const YESEXPR* = cint(327680)
+const NOEXPR* = cint(327681)
+const CRNCYSTR* = cint(262159)
+
+# <locale.h>
+const LC_ALL* = cint(6)
+const LC_COLLATE* = cint(3)
+const LC_CTYPE* = cint(0)
+const LC_MESSAGES* = cint(5)
+const LC_MONETARY* = cint(4)
+const LC_NUMERIC* = cint(1)
+const LC_TIME* = cint(2)
+
+# <netdb.h>
+const IPPORT_RESERVED* = cint(1024)
+const HOST_NOT_FOUND* = cint(1)
+const NO_DATA* = cint(4)
+const NO_RECOVERY* = cint(3)
+const TRY_AGAIN* = cint(2)
+const AI_PASSIVE* = cint(1)
+const AI_CANONNAME* = cint(2)
+const AI_NUMERICHOST* = cint(4)
+const AI_NUMERICSERV* = cint(1024)
+const AI_V4MAPPED* = cint(8)
+const AI_ALL* = cint(16)
+const AI_ADDRCONFIG* = cint(32)
+const NI_NOFQDN* = cint(4)
+const NI_NUMERICHOST* = cint(1)
+const NI_NAMEREQD* = cint(8)
+const NI_NUMERICSERV* = cint(2)
+const NI_DGRAM* = cint(16)
+const EAI_AGAIN* = cint(-3)
+const EAI_BADFLAGS* = cint(-1)
+const EAI_FAIL* = cint(-4)
+const EAI_FAMILY* = cint(-6)
+const EAI_MEMORY* = cint(-10)
+const EAI_NONAME* = cint(-2)
+const EAI_SERVICE* = cint(-8)
+const EAI_SOCKTYPE* = cint(-7)
+const EAI_SYSTEM* = cint(-11)
+const EAI_OVERFLOW* = cint(-12)
+
+# <net/if.h>
+const IF_NAMESIZE* = cint(16)
+
+# <netinet/in.h>
+const IPPROTO_IP* = cint(0)
+const IPPROTO_IPV6* = cint(41)
+const IPPROTO_ICMP* = cint(1)
+const IPPROTO_ICMPV6* = cint(58)
+const IPPROTO_RAW* = cint(255)
+const IPPROTO_TCP* = cint(6)
+const IPPROTO_UDP* = cint(17)
+const INADDR_ANY* = InAddrScalar(0)
+const INADDR_LOOPBACK* = InAddrScalar(2130706433)
+const INADDR_BROADCAST* = InAddrScalar(4294967295)
+const INET_ADDRSTRLEN* = cint(16)
+const INET6_ADDRSTRLEN* = cint(46)
+const IPV6_JOIN_GROUP* = cint(20)
+const IPV6_LEAVE_GROUP* = cint(21)
+const IPV6_MULTICAST_HOPS* = cint(18)
+const IPV6_MULTICAST_IF* = cint(17)
+const IPV6_MULTICAST_LOOP* = cint(19)
+const IPV6_UNICAST_HOPS* = cint(16)
+const IPV6_V6ONLY* = cint(26)
+
+# <netinet/tcp.h>
+const TCP_NODELAY* = cint(1)
+
+# <nl_types.h>
+const NL_SETD* = cint(1)
+const NL_CAT_LOCALE* = cint(1)
+
+# <poll.h>
+const POLLIN* = cshort(1)
+const POLLRDNORM* = cshort(64)
+const POLLRDBAND* = cshort(128)
+const POLLPRI* = cshort(2)
+const POLLOUT* = cshort(4)
+const POLLWRNORM* = cshort(256)
+const POLLWRBAND* = cshort(512)
+const POLLERR* = cshort(8)
+const POLLHUP* = cshort(16)
+const POLLNVAL* = cshort(32)
+
+# <pthread.h>
+const PTHREAD_BARRIER_SERIAL_THREAD* = cint(-1)
+const PTHREAD_CANCEL_ASYNCHRONOUS* = cint(1)
+const PTHREAD_CANCEL_ENABLE* = cint(0)
+const PTHREAD_CANCEL_DEFERRED* = cint(0)
+const PTHREAD_CANCEL_DISABLE* = cint(1)
+const PTHREAD_CREATE_DETACHED* = cint(1)
+const PTHREAD_CREATE_JOINABLE* = cint(0)
+const PTHREAD_EXPLICIT_SCHED* = cint(1)
+const PTHREAD_INHERIT_SCHED* = cint(0)
+const PTHREAD_PROCESS_SHARED* = cint(1)
+const PTHREAD_PROCESS_PRIVATE* = cint(0)
+const PTHREAD_SCOPE_PROCESS* = cint(1)
+const PTHREAD_SCOPE_SYSTEM* = cint(0)
+
+# <sched.h>
+const SCHED_FIFO* = cint(1)
+const SCHED_RR* = cint(2)
+const SCHED_OTHER* = cint(0)
+
+# <semaphore.h>
+const SEM_FAILED* = cast[pointer]((nil))
+
+# <signal.h>
+const SIGEV_NONE* = cint(1)
+const SIGEV_SIGNAL* = cint(0)
+const SIGEV_THREAD* = cint(2)
+const SIGABRT* = cint(6)
+const SIGALRM* = cint(14)
+const SIGBUS* = cint(7)
+const SIGCHLD* = cint(17)
+const SIGCONT* = cint(18)
+const SIGFPE* = cint(8)
+const SIGHUP* = cint(1)
+const SIGILL* = cint(4)
+const SIGINT* = cint(2)
+const SIGKILL* = cint(9)
+const SIGPIPE* = cint(13)
+const SIGQUIT* = cint(3)
+const SIGSEGV* = cint(11)
+const SIGSTOP* = cint(19)
+const SIGTERM* = cint(15)
+const SIGTSTP* = cint(20)
+const SIGTTIN* = cint(21)
+const SIGTTOU* = cint(22)
+const SIGUSR1* = cint(10)
+const SIGUSR2* = cint(12)
+const SIGPOLL* = cint(29)
+const SIGPROF* = cint(27)
+const SIGSYS* = cint(31)
+const SIGTRAP* = cint(5)
+const SIGURG* = cint(23)
+const SIGVTALRM* = cint(26)
+const SIGXCPU* = cint(24)
+const SIGXFSZ* = cint(25)
+const SA_NOCLDSTOP* = cint(1)
+const SIG_BLOCK* = cint(0)
+const SIG_UNBLOCK* = cint(1)
+const SIG_SETMASK* = cint(2)
+const SA_ONSTACK* = cint(134217728)
+const SA_RESETHAND* = cint(-2147483648)
+const SA_RESTART* = cint(268435456)
+const SA_SIGINFO* = cint(4)
+const SA_NOCLDWAIT* = cint(2)
+const SA_NODEFER* = cint(1073741824)
+const SS_ONSTACK* = cint(1)
+const SS_DISABLE* = cint(2)
+const MINSIGSTKSZ* = cint(2048)
+const SIGSTKSZ* = cint(8192)
+const SIG_HOLD* = cast[Sighandler](2)
+const SIG_DFL* = cast[Sighandler](0)
+const SIG_ERR* = cast[Sighandler](-1)
+const SIG_IGN* = cast[Sighandler](1)
+
+# <sys/ipc.h>
+const IPC_CREAT* = cint(512)
+const IPC_EXCL* = cint(1024)
+const IPC_NOWAIT* = cint(2048)
+const IPC_PRIVATE* = cint(0)
+const IPC_RMID* = cint(0)
+const IPC_SET* = cint(1)
+const IPC_STAT* = cint(2)
+
+# <sys/mman.h>
+const PROT_READ* = cint(1)
+const PROT_WRITE* = cint(2)
+const PROT_EXEC* = cint(4)
+const PROT_NONE* = cint(0)
+const MAP_ANONYMOUS* = cint(32)
+const MAP_FIXED_NOREPLACE* = cint(1048576)
+const MAP_NORESERVE* = cint(16384)
+const MAP_SHARED* = cint(1)
+const MAP_PRIVATE* = cint(2)
+const MAP_FIXED* = cint(16)
+const MS_ASYNC* = cint(1)
+const MS_SYNC* = cint(4)
+const MS_INVALIDATE* = cint(2)
+const MCL_CURRENT* = cint(1)
+const MCL_FUTURE* = cint(2)
+const MAP_FAILED* = cast[pointer](0xffffffffffffffff)
+const POSIX_MADV_NORMAL* = cint(0)
+const POSIX_MADV_SEQUENTIAL* = cint(2)
+const POSIX_MADV_RANDOM* = cint(1)
+const POSIX_MADV_WILLNEED* = cint(3)
+const POSIX_MADV_DONTNEED* = cint(4)
+const MAP_POPULATE* = cint(32768)
+
+# <sys/resource.h>
+const RLIMIT_NOFILE* = cint(7)
+const RLIMIT_STACK* = cint(3)
+
+# <sys/select.h>
+const FD_SETSIZE* = cint(1024)
+
+# <sys/socket.h>
+const MSG_CTRUNC* = cint(8)
+const MSG_DONTROUTE* = cint(4)
+const MSG_EOR* = cint(128)
+const MSG_OOB* = cint(1)
+const SCM_RIGHTS* = cint(1)
+const SO_ACCEPTCONN* = cint(30)
+const SO_BINDTODEVICE* = cint(25)
+const SO_BROADCAST* = cint(6)
+const SO_DEBUG* = cint(1)
+const SO_DONTROUTE* = cint(5)
+const SO_ERROR* = cint(4)
+const SO_KEEPALIVE* = cint(9)
+const SO_LINGER* = cint(13)
+const SO_OOBINLINE* = cint(10)
+const SO_RCVBUF* = cint(8)
+const SO_RCVLOWAT* = cint(18)
+const SO_RCVTIMEO* = cint(20)
+const SO_REUSEADDR* = cint(2)
+const SO_SNDBUF* = cint(7)
+const SO_SNDLOWAT* = cint(19)
+const SO_SNDTIMEO* = cint(21)
+const SO_TYPE* = cint(3)
+const SOCK_DGRAM* = cint(2)
+const SOCK_RAW* = cint(3)
+const SOCK_SEQPACKET* = cint(5)
+const SOCK_STREAM* = cint(1)
+const SOCK_CLOEXEC* = cint(524288)
+const SOL_SOCKET* = cint(1)
+const SOMAXCONN* = cint(4096)
+const SO_REUSEPORT* = cint(15)
+const MSG_NOSIGNAL* = cint(16384)
+const MSG_PEEK* = cint(2)
+const MSG_TRUNC* = cint(32)
+const MSG_WAITALL* = cint(256)
+const AF_INET* = cint(2)
+const AF_INET6* = cint(10)
+const AF_UNIX* = cint(1)
+const AF_UNSPEC* = cint(0)
+const SHUT_RD* = cint(0)
+const SHUT_RDWR* = cint(2)
+const SHUT_WR* = cint(1)
+
+# <sys/stat.h>
+const S_IFBLK* = cint(24576)
+const S_IFCHR* = cint(8192)
+const S_IFDIR* = cint(16384)
+const S_IFIFO* = cint(4096)
+const S_IFLNK* = cint(40960)
+const S_IFMT* = cint(61440)
+const S_IFREG* = cint(32768)
+const S_IFSOCK* = cint(49152)
+const S_IRGRP* = cint(32)
+const S_IROTH* = cint(4)
+const S_IRUSR* = cint(256)
+const S_IRWXG* = cint(56)
+const S_IRWXO* = cint(7)
+const S_IRWXU* = cint(448)
+const S_ISGID* = cint(1024)
+const S_ISUID* = cint(2048)
+const S_ISVTX* = cint(512)
+const S_IWGRP* = cint(16)
+const S_IWOTH* = cint(2)
+const S_IWUSR* = cint(128)
+const S_IXGRP* = cint(8)
+const S_IXOTH* = cint(1)
+const S_IXUSR* = cint(64)
+
+# <sys/statvfs.h>
+const ST_RDONLY* = cint(1)
+const ST_NOSUID* = cint(2)
+
+# <sys/wait.h>
+const WNOHANG* = cint(1)
+const WUNTRACED* = cint(2)
+const WEXITED* = cint(4)
+const WSTOPPED* = cint(2)
+const WCONTINUED* = cint(8)
+const WNOWAIT* = cint(16777216)
+
+# <spawn.h>
+const POSIX_SPAWN_RESETIDS* = cint(1)
+const POSIX_SPAWN_SETPGROUP* = cint(2)
+const POSIX_SPAWN_SETSCHEDPARAM* = cint(16)
+const POSIX_SPAWN_SETSCHEDULER* = cint(32)
+const POSIX_SPAWN_SETSIGDEF* = cint(4)
+const POSIX_SPAWN_SETSIGMASK* = cint(8)
+const POSIX_SPAWN_USEVFORK* = cint(64)
+
+# <stdio.h>
+const IOFBF* = cint(0)
+const IONBF* = cint(2)
+
+# <time.h>
+const CLOCKS_PER_SEC* = clong(1000000)
+const CLOCK_PROCESS_CPUTIME_ID* = cint(2)
+const CLOCK_THREAD_CPUTIME_ID* = cint(3)
+const CLOCK_REALTIME* = cint(0)
+const TIMER_ABSTIME* = cint(1)
+const CLOCK_MONOTONIC* = cint(1)
+
+# <unistd.h>
+const POSIX_ASYNC_IO* = cint(1)
+const F_OK* = cint(0)
+const R_OK* = cint(4)
+const W_OK* = cint(2)
+const X_OK* = cint(1)
+const CS_PATH* = cint(0)
+const CS_POSIX_V6_ILP32_OFF32_CFLAGS* = cint(1116)
+const CS_POSIX_V6_ILP32_OFF32_LDFLAGS* = cint(1117)
+const CS_POSIX_V6_ILP32_OFF32_LIBS* = cint(1118)
+const CS_POSIX_V6_ILP32_OFFBIG_CFLAGS* = cint(1120)
+const CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS* = cint(1121)
+const CS_POSIX_V6_ILP32_OFFBIG_LIBS* = cint(1122)
+const CS_POSIX_V6_LP64_OFF64_CFLAGS* = cint(1124)
+const CS_POSIX_V6_LP64_OFF64_LDFLAGS* = cint(1125)
+const CS_POSIX_V6_LP64_OFF64_LIBS* = cint(1126)
+const CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS* = cint(1128)
+const CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS* = cint(1129)
+const CS_POSIX_V6_LPBIG_OFFBIG_LIBS* = cint(1130)
+const CS_POSIX_V6_WIDTH_RESTRICTED_ENVS* = cint(1)
+const F_LOCK* = cint(1)
+const F_TEST* = cint(3)
+const F_TLOCK* = cint(2)
+const F_ULOCK* = cint(0)
+const PC_2_SYMLINKS* = cint(20)
+const PC_ALLOC_SIZE_MIN* = cint(18)
+const PC_ASYNC_IO* = cint(10)
+const PC_CHOWN_RESTRICTED* = cint(6)
+const PC_FILESIZEBITS* = cint(13)
+const PC_LINK_MAX* = cint(0)
+const PC_MAX_CANON* = cint(1)
+const PC_MAX_INPUT* = cint(2)
+const PC_NAME_MAX* = cint(3)
+const PC_NO_TRUNC* = cint(7)
+const PC_PATH_MAX* = cint(4)
+const PC_PIPE_BUF* = cint(5)
+const PC_PRIO_IO* = cint(11)
+const PC_REC_INCR_XFER_SIZE* = cint(14)
+const PC_REC_MIN_XFER_SIZE* = cint(16)
+const PC_REC_XFER_ALIGN* = cint(17)
+const PC_SYMLINK_MAX* = cint(19)
+const PC_SYNC_IO* = cint(9)
+const PC_VDISABLE* = cint(8)
+const SC_2_C_BIND* = cint(47)
+const SC_2_C_DEV* = cint(48)
+const SC_2_CHAR_TERM* = cint(95)
+const SC_2_FORT_DEV* = cint(49)
+const SC_2_FORT_RUN* = cint(50)
+const SC_2_LOCALEDEF* = cint(52)
+const SC_2_PBS* = cint(168)
+const SC_2_PBS_ACCOUNTING* = cint(169)
+const SC_2_PBS_CHECKPOINT* = cint(175)
+const SC_2_PBS_LOCATE* = cint(170)
+const SC_2_PBS_MESSAGE* = cint(171)
+const SC_2_PBS_TRACK* = cint(172)
+const SC_2_SW_DEV* = cint(51)
+const SC_2_UPE* = cint(97)
+const SC_2_VERSION* = cint(46)
+const SC_ADVISORY_INFO* = cint(132)
+const SC_AIO_LISTIO_MAX* = cint(23)
+const SC_AIO_MAX* = cint(24)
+const SC_AIO_PRIO_DELTA_MAX* = cint(25)
+const SC_ARG_MAX* = cint(0)
+const SC_ASYNCHRONOUS_IO* = cint(12)
+const SC_ATEXIT_MAX* = cint(87)
+const SC_BARRIERS* = cint(133)
+const SC_BC_BASE_MAX* = cint(36)
+const SC_BC_DIM_MAX* = cint(37)
+const SC_BC_SCALE_MAX* = cint(38)
+const SC_BC_STRING_MAX* = cint(39)
+const SC_CHILD_MAX* = cint(1)
+const SC_CLK_TCK* = cint(2)
+const SC_CLOCK_SELECTION* = cint(137)
+const SC_COLL_WEIGHTS_MAX* = cint(40)
+const SC_CPUTIME* = cint(138)
+const SC_DELAYTIMER_MAX* = cint(26)
+const SC_EXPR_NEST_MAX* = cint(42)
+const SC_FSYNC* = cint(15)
+const SC_GETGR_R_SIZE_MAX* = cint(69)
+const SC_GETPW_R_SIZE_MAX* = cint(70)
+const SC_HOST_NAME_MAX* = cint(180)
+const SC_IOV_MAX* = cint(60)
+const SC_IPV6* = cint(235)
+const SC_JOB_CONTROL* = cint(7)
+const SC_LINE_MAX* = cint(43)
+const SC_LOGIN_NAME_MAX* = cint(71)
+const SC_MAPPED_FILES* = cint(16)
+const SC_MEMLOCK* = cint(17)
+const SC_MEMLOCK_RANGE* = cint(18)
+const SC_MEMORY_PROTECTION* = cint(19)
+const SC_MESSAGE_PASSING* = cint(20)
+const SC_MONOTONIC_CLOCK* = cint(149)
+const SC_MQ_OPEN_MAX* = cint(27)
+const SC_MQ_PRIO_MAX* = cint(28)
+const SC_NGROUPS_MAX* = cint(3)
+const SC_OPEN_MAX* = cint(4)
+const SC_PAGESIZE* = cint(30)
+const SC_PRIORITIZED_IO* = cint(13)
+const SC_PRIORITY_SCHEDULING* = cint(10)
+const SC_RAW_SOCKETS* = cint(236)
+const SC_RE_DUP_MAX* = cint(44)
+const SC_READER_WRITER_LOCKS* = cint(153)
+const SC_REALTIME_SIGNALS* = cint(9)
+const SC_REGEXP* = cint(155)
+const SC_RTSIG_MAX* = cint(31)
+const SC_SAVED_IDS* = cint(8)
+const SC_SEM_NSEMS_MAX* = cint(32)
+const SC_SEM_VALUE_MAX* = cint(33)
+const SC_SEMAPHORES* = cint(21)
+const SC_SHARED_MEMORY_OBJECTS* = cint(22)
+const SC_SHELL* = cint(157)
+const SC_SIGQUEUE_MAX* = cint(34)
+const SC_SPAWN* = cint(159)
+const SC_SPIN_LOCKS* = cint(154)
+const SC_SPORADIC_SERVER* = cint(160)
+const SC_SS_REPL_MAX* = cint(241)
+const SC_STREAM_MAX* = cint(5)
+const SC_SYMLOOP_MAX* = cint(173)
+const SC_SYNCHRONIZED_IO* = cint(14)
+const SC_THREAD_ATTR_STACKADDR* = cint(77)
+const SC_THREAD_ATTR_STACKSIZE* = cint(78)
+const SC_THREAD_CPUTIME* = cint(139)
+const SC_THREAD_DESTRUCTOR_ITERATIONS* = cint(73)
+const SC_THREAD_KEYS_MAX* = cint(74)
+const SC_THREAD_PRIO_INHERIT* = cint(80)
+const SC_THREAD_PRIO_PROTECT* = cint(81)
+const SC_THREAD_PRIORITY_SCHEDULING* = cint(79)
+const SC_THREAD_PROCESS_SHARED* = cint(82)
+const SC_THREAD_SAFE_FUNCTIONS* = cint(68)
+const SC_THREAD_SPORADIC_SERVER* = cint(161)
+const SC_THREAD_STACK_MIN* = cint(75)
+const SC_THREAD_THREADS_MAX* = cint(76)
+const SC_THREADS* = cint(67)
+const SC_TIMEOUTS* = cint(164)
+const SC_TIMER_MAX* = cint(35)
+const SC_TIMERS* = cint(11)
+const SC_TRACE* = cint(181)
+const SC_TRACE_EVENT_FILTER* = cint(182)
+const SC_TRACE_EVENT_NAME_MAX* = cint(242)
+const SC_TRACE_INHERIT* = cint(183)
+const SC_TRACE_LOG* = cint(184)
+const SC_TRACE_NAME_MAX* = cint(243)
+const SC_TRACE_SYS_MAX* = cint(244)
+const SC_TRACE_USER_EVENT_MAX* = cint(245)
+const SC_TTY_NAME_MAX* = cint(72)
+const SC_TYPED_MEMORY_OBJECTS* = cint(165)
+const SC_TZNAME_MAX* = cint(6)
+const SC_V6_ILP32_OFF32* = cint(176)
+const SC_V6_ILP32_OFFBIG* = cint(177)
+const SC_V6_LP64_OFF64* = cint(178)
+const SC_V6_LPBIG_OFFBIG* = cint(179)
+const SC_VERSION* = cint(29)
+const SC_XBS5_ILP32_OFF32* = cint(125)
+const SC_XBS5_ILP32_OFFBIG* = cint(126)
+const SC_XBS5_LP64_OFF64* = cint(127)
+const SC_XBS5_LPBIG_OFFBIG* = cint(128)
+const SC_XOPEN_CRYPT* = cint(92)
+const SC_XOPEN_ENH_I18N* = cint(93)
+const SC_XOPEN_LEGACY* = cint(129)
+const SC_XOPEN_REALTIME* = cint(130)
+const SC_XOPEN_REALTIME_THREADS* = cint(131)
+const SC_XOPEN_SHM* = cint(94)
+const SC_XOPEN_STREAMS* = cint(246)
+const SC_XOPEN_UNIX* = cint(91)
+const SC_XOPEN_VERSION* = cint(89)
+const SC_NPROCESSORS_ONLN* = cint(84)
+const SEEK_SET* = cint(0)
+const SEEK_CUR* = cint(1)
+const SEEK_END* = cint(2)
diff --git a/lib/posix/posix_macos_amd64.nim b/lib/posix/posix_macos_amd64.nim
new file mode 100644
index 000000000..a4b64ed62
--- /dev/null
+++ b/lib/posix/posix_macos_amd64.nim
@@ -0,0 +1,620 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2012 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+const
+  hasSpawnH = true # should exist for every Posix system nowadays
+  hasAioH = false
+
+type
+  DIR* {.importc: "DIR", header: "<dirent.h>",
+          incompleteStruct.} = object
+    ## A type representing a directory stream.
+
+type
+  SocketHandle* = distinct cint # The type used to represent socket descriptors
+
+type
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct clong
+
+  Timespec* {.importc: "struct timespec",
+               header: "<time.h>", final, pure.} = object ## struct timespec
+    tv_sec*: Time  ## Seconds.
+    tv_nsec*: int  ## Nanoseconds.
+
+  Dirent* {.importc: "struct dirent",
+             header: "<dirent.h>", final, pure.} = object ## dirent_t struct
+    when defined(haiku):
+      d_dev*: Dev ## Device (not POSIX)
+      d_pdev*: Dev ## Parent device (only for queries) (not POSIX)
+    d_ino*: Ino  ## File serial number.
+    when defined(dragonfly):
+      # DragonflyBSD doesn't have `d_reclen` field.
+      d_type*: uint8
+    elif defined(linux) or defined(macosx) or defined(freebsd) or
+         defined(netbsd) or defined(openbsd) or defined(genode):
+      d_reclen*: cshort ## Length of this record. (not POSIX)
+      d_type*: int8 ## Type of file; not supported by all filesystem types.
+                    ## (not POSIX)
+      when defined(linux) or defined(openbsd):
+        d_off*: Off  ## Not an offset. Value that `telldir()` would return.
+    elif defined(haiku):
+      d_pino*: Ino ## Parent inode (only for queries) (not POSIX)
+      d_reclen*: cushort ## Length of this record. (not POSIX)
+
+    d_name*: array[0..255, char] ## Name of entry.
+
+  Tflock* {.importc: "struct flock", final, pure,
+            header: "<fcntl.h>".} = object ## flock type
+    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+    l_whence*: cshort ## Flag for starting offset.
+    l_start*: Off     ## Relative offset in bytes.
+    l_len*: Off       ## Size; if 0 then until EOF.
+    l_pid*: Pid      ## Process ID of the process holding the lock;
+                      ## returned with F_GETLK.
+
+  FTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
+    base*: cint
+    level*: cint
+
+  Glob* {.importc: "glob_t", header: "<glob.h>",
+           final, pure.} = object ## glob_t
+    gl_pathc*: int          ## Count of paths matched by pattern.
+    gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
+    gl_offs*: int           ## Slots to reserve at the beginning of gl_pathv.
+
+  Group* {.importc: "struct group", header: "<grp.h>",
+            final, pure.} = object ## struct group
+    gr_name*: cstring     ## The name of the group.
+    gr_gid*: Gid         ## Numerical group ID.
+    gr_mem*: cstringArray ## Pointer to a null-terminated array of character
+                          ## pointers to member names.
+
+  Iconv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} =
+    object ## Identifies the conversion from one codeset to another.
+
+  Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
+            pure.} = object
+    currency_symbol*: cstring
+    decimal_point*: cstring
+    frac_digits*: char
+    grouping*: cstring
+    int_curr_symbol*: cstring
+    int_frac_digits*: char
+    int_n_cs_precedes*: char
+    int_n_sep_by_space*: char
+    int_n_sign_posn*: char
+    int_p_cs_precedes*: char
+    int_p_sep_by_space*: char
+    int_p_sign_posn*: char
+    mon_decimal_point*: cstring
+    mon_grouping*: cstring
+    mon_thousands_sep*: cstring
+    negative_sign*: cstring
+    n_cs_precedes*: char
+    n_sep_by_space*: char
+    n_sign_posn*: char
+    positive_sign*: cstring
+    p_cs_precedes*: char
+    p_sep_by_space*: char
+    p_sign_posn*: char
+    thousands_sep*: cstring
+
+  Passwd* {.importc: "struct passwd", header: "<pwd.h>",
+             final, pure.} = object ## struct passwd
+    pw_name*: cstring   ## User's login name.
+    pw_uid*: Uid        ## Numerical user ID.
+    pw_gid*: Gid        ## Numerical group ID.
+    pw_dir*: cstring    ## Initial working directory.
+    pw_shell*: cstring  ## Program to use as shell.
+
+  Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int
+    ## used for file block counts
+  Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int32
+    ## used for block sizes
+  Clock* {.importc: "clock_t", header: "<sys/types.h>".} = int
+  ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int
+  Dev* {.importc: "dev_t", header: "<sys/types.h>".} = (
+    when defined(freebsd):
+      uint32
+    else:
+      int32)
+  Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int
+  Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int
+  Gid* {.importc: "gid_t", header: "<sys/types.h>".} = uint32
+  Id* {.importc: "id_t", header: "<sys/types.h>".} = int
+  Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
+  Key* {.importc: "key_t", header: "<sys/types.h>".} = int
+  Mode* {.importc: "mode_t", header: "<sys/types.h>".} = (
+    when defined(openbsd) or defined(netbsd):
+      uint32
+    else:
+      uint16
+  )
+  Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = uint16
+  Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
+  Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
+  Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = int
+  Pthread_barrier* {.importc: "pthread_barrier_t",
+                      header: "<sys/types.h>".} = int
+  Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
+                          header: "<sys/types.h>".} = int
+  Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = int
+  Pthread_condattr* {.importc: "pthread_condattr_t",
+                       header: "<sys/types.h>".} = int
+  Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = int
+  Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = int
+  Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
+                        header: "<sys/types.h>".} = int
+  Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = int
+  Pthread_rwlock* {.importc: "pthread_rwlock_t",
+                     header: "<sys/types.h>".} = int
+  Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
+                         header: "<sys/types.h>".} = int
+  Pthread_spinlock* {.importc: "pthread_spinlock_t",
+                       header: "<sys/types.h>".} = int
+  Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = int
+  Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int32
+  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
+  Timer* {.importc: "timer_t", header: "<sys/types.h>".} = int
+  Trace_attr* {.importc: "trace_attr_t", header: "<sys/types.h>".} = int
+  Trace_event_id* {.importc: "trace_event_id_t",
+                     header: "<sys/types.h>".} = int
+  Trace_event_set* {.importc: "trace_event_set_t",
+                      header: "<sys/types.h>".} = int
+  Trace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int
+  Uid* {.importc: "uid_t", header: "<sys/types.h>".} = uint32
+  Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int
+
+  Utsname* {.importc: "struct utsname",
+              header: "<sys/utsname.h>",
+              final, pure.} = object ## struct utsname
+    sysname*,      ## Name of this implementation of the operating system.
+      nodename*,   ## Name of this node within the communications
+                   ## network to which this node is attached, if any.
+      release*,    ## Current release level of this implementation.
+      version*,    ## Current version level of this release.
+      machine*: array[0..255, char] ## Name of the hardware type on which the
+                                     ## system is running.
+
+  Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
+  Ipc_perm* {.importc: "struct ipc_perm",
+               header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
+    uid*: Uid    ## Owner's user ID.
+    gid*: Gid    ## Owner's group ID.
+    cuid*: Uid   ## Creator's user ID.
+    cgid*: Gid   ## Creator's group ID.
+    mode*: Mode  ## Read/write permission.
+
+  Stat* {.importc: "struct stat",
+           header: "<sys/stat.h>", final, pure.} = object ## struct stat
+    st_dev*: Dev          ## Device ID of device containing file.
+    st_ino*: Ino          ## File serial number.
+    st_mode*: Mode        ## Mode of file (see below).
+    st_nlink*: Nlink      ## Number of hard links to the file.
+    st_uid*: Uid          ## User ID of file.
+    st_gid*: Gid          ## Group ID of file.
+    st_rdev*: Dev         ## Device ID (if file is character or block special).
+    st_size*: Off         ## For regular files, the file size in bytes.
+                          ## For symbolic links, the length in bytes of the
+                          ## pathname contained in the symbolic link.
+                          ## For a shared memory object, the length in bytes.
+                          ## For a typed memory object, the length in bytes.
+                          ## For other file types, the use of this field is
+                          ## unspecified.
+    when defined(osx):
+      st_atim* {.importc:"st_atimespec".}: Timespec  ## Time of last access.
+      st_mtim* {.importc:"st_mtimespec".}: Timespec  ## Time of last data modification.
+      st_ctim*  {.importc:"st_ctimespec".}: Timespec  ## Time of last status change.
+    elif StatHasNanoseconds:
+      st_atim*: Timespec  ## Time of last access.
+      st_mtim*: Timespec  ## Time of last data modification.
+      st_ctim*: Timespec  ## Time of last status change.
+    else:
+      st_atime*: Time     ## Time of last access.
+      st_mtime*: Time     ## Time of last data modification.
+      st_ctime*: Time     ## Time of last status change.
+
+    st_blksize*: Blksize  ## A file system-specific preferred I/O block size
+                          ## for this object. In some file system types, this
+                          ## may vary from file to file.
+    st_blocks*: Blkcnt    ## Number of blocks allocated for this object.
+
+
+  Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
+              final, pure.} = object ## struct statvfs
+    f_bsize*: int        ## File system block size.
+    f_frsize*: int       ## Fundamental file system block size.
+    f_blocks*: Fsblkcnt  ## Total number of blocks on file system
+                         ## in units of f_frsize.
+    f_bfree*: Fsblkcnt   ## Total number of free blocks.
+    f_bavail*: Fsblkcnt  ## Number of free blocks available to
+                         ## non-privileged process.
+    f_files*: Fsfilcnt   ## Total number of file serial numbers.
+    f_ffree*: Fsfilcnt   ## Total number of free file serial numbers.
+    f_favail*: Fsfilcnt  ## Number of file serial numbers available to
+                         ## non-privileged process.
+    f_fsid*: int         ## File system ID.
+    f_flag*: int         ## Bit mask of f_flag values.
+    f_namemax*: int      ## Maximum filename length.
+
+  Posix_typed_mem_info* {.importc: "struct posix_typed_mem_info",
+                           header: "<sys/mman.h>", final, pure.} = object
+    posix_tmi_length*: int
+
+  Tm* {.importc: "struct tm", header: "<time.h>",
+         final, pure.} = object ## struct tm
+    tm_sec*: cint   ## Seconds [0,60].
+    tm_min*: cint   ## Minutes [0,59].
+    tm_hour*: cint  ## Hour [0,23].
+    tm_mday*: cint  ## Day of month [1,31].
+    tm_mon*: cint   ## Month of year [0,11].
+    tm_year*: cint  ## Years since 1900.
+    tm_wday*: cint  ## Day of week [0,6] (Sunday =0).
+    tm_yday*: cint  ## Day of year [0,365].
+    tm_isdst*: cint ## Daylight Savings flag.
+  Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
+                 final, pure.} = object ## struct itimerspec
+    it_interval*: Timespec  ## Timer period.
+    it_value*: Timespec     ## Timer expiration.
+
+  Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
+    ## Possibly volatile-qualified integer type of an object that can be
+    ## accessed as an atomic entity, even in the presence of asynchronous
+    ## interrupts.
+  Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
+
+  SigEvent* {.importc: "struct sigevent",
+               header: "<signal.h>", final, pure.} = object ## struct sigevent
+    sigev_notify*: cint           ## Notification type.
+    sigev_signo*: cint            ## Signal number.
+    sigev_value*: SigVal          ## Signal value.
+    sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
+    sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
+
+  SigVal* {.importc: "union sigval",
+             header: "<signal.h>", final, pure.} = object ## struct sigval
+    sival_ptr*: pointer ## pointer signal value;
+                        ## integer signal value not defined!
+  Sigaction* {.importc: "struct sigaction",
+                header: "<signal.h>", final, pure.} = object ## struct sigaction
+    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
+                                            ## function or one of the macros
+                                            ## SIG_IGN or SIG_DFL.
+    sa_mask*: Sigset ## Set of signals to be blocked during execution of
+                      ## the signal handling function.
+    sa_flags*: cint   ## Special flags.
+    sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
+
+  Stack* {.importc: "stack_t",
+            header: "<signal.h>", final, pure.} = object ## stack_t
+    ss_sp*: pointer  ## Stack base or pointer.
+    ss_size*: int    ## Stack size.
+    ss_flags*: cint  ## Flags.
+
+  SigStack* {.importc: "struct sigstack",
+               header: "<signal.h>", final, pure.} = object ## struct sigstack
+    ss_onstack*: cint ## Non-zero when signal stack is in use.
+    ss_sp*: pointer   ## Signal stack pointer.
+
+  SigInfo* {.importc: "siginfo_t",
+              header: "<signal.h>", final, pure.} = object ## siginfo_t
+    si_signo*: cint    ## Signal number.
+    si_code*: cint     ## Signal code.
+    si_errno*: cint    ## If non-zero, an errno value associated with
+                       ## this signal, as defined in <errno.h>.
+    si_pid*: Pid       ## Sending process ID.
+    si_uid*: Uid       ## Real user ID of sending process.
+    si_addr*: pointer  ## Address of faulting instruction.
+    si_status*: cint   ## Exit value or signal.
+    si_band*: int      ## Band event for SIGPOLL.
+    si_value*: SigVal  ## Signal value.
+
+  Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
+  Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
+
+  Sched_param* {.importc: "struct sched_param",
+                  header: "<sched.h>",
+                  final, pure.} = object ## struct sched_param
+    sched_priority*: cint
+    sched_ss_low_priority*: cint     ## Low scheduling priority for
+                                     ## sporadic server.
+    sched_ss_repl_period*: Timespec  ## Replenishment period for
+                                     ## sporadic server.
+    sched_ss_init_budget*: Timespec  ## Initial budget for sporadic server.
+    sched_ss_max_repl*: cint         ## Maximum pending replenishments for
+                                     ## sporadic server.
+
+  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+             final, pure.} = object ## struct timeval
+    tv_sec*: Time ## Seconds.
+    tv_usec*: Suseconds ## Microseconds.
+  TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
+           final, pure.} = object
+  Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
+               final, pure.} = object
+  Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
+               final, pure.} = object ## ucontext_t
+    uc_link*: ptr Ucontext  ## Pointer to the context that is resumed
+                            ## when this context returns.
+    uc_sigmask*: Sigset     ## The set of signals that are blocked when this
+                            ## context is active.
+    uc_stack*: Stack        ## The stack used by this context.
+    uc_mcontext*: Mcontext  ## A machine-specific representation of the saved
+                            ## context.
+
+when hasAioH:
+  type
+    Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
+              final, pure.} = object ## struct aiocb
+      aio_fildes*: cint         ## File descriptor.
+      aio_offset*: Off          ## File offset.
+      aio_buf*: pointer         ## Location of buffer.
+      aio_nbytes*: int          ## Length of transfer.
+      aio_reqprio*: cint        ## Request priority offset.
+      aio_sigevent*: SigEvent   ## Signal number and value.
+      aio_lio_opcode: cint      ## Operation to be performed.
+
+when hasSpawnH:
+  type
+    Tposix_spawnattr* {.importc: "posix_spawnattr_t",
+                        header: "<spawn.h>", final, pure.} = object
+    Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
+                                 header: "<spawn.h>", final, pure.} = object
+
+
+when not defined(macos) and not defined(macosx): # freebsd
+  type
+    Mqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
+    MqAttr* {.importc: "struct mq_attr",
+              header: "<mqueue.h>",
+              final, pure.} = object ## message queue attribute
+      mq_flags*: int   ## Message queue flags.
+      mq_maxmsg*: int  ## Maximum number of messages.
+      mq_msgsize*: int ## Maximum message size.
+      mq_curmsgs*: int ## Number of messages currently queued.
+
+when defined(linux):
+  # from sys/un.h
+  const Sockaddr_un_path_length* = 108
+else:
+  # according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html
+  # this is >=92
+  const Sockaddr_un_path_length* = 92
+
+type
+  SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
+  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8
+
+  SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+              pure, final.} = object ## struct sockaddr
+    sa_family*: TSa_Family         ## Address family.
+    sa_data*: array[0..255, char] ## Socket address (variable-length data).
+
+  Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
+              pure, final.} = object ## struct sockaddr_un
+    sun_family*: TSa_Family         ## Address family.
+    sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path
+
+  Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                       header: "<sys/socket.h>",
+                       pure, final.} = object ## struct sockaddr_storage
+    ss_family*: TSa_Family ## Address family.
+
+  Tif_nameindex* {.importc: "struct if_nameindex", final,
+                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
+    if_index*: cint   ## Numeric index of the interface.
+    if_name*: cstring ## Null-terminated name of the interface.
+
+
+  IOVec* {.importc: "struct iovec", pure, final,
+            header: "<sys/uio.h>".} = object ## struct iovec
+    iov_base*: pointer ## Base address of a memory region for input or output.
+    iov_len*: csize_t    ## The size of the memory pointed to by iov_base.
+
+  Tmsghdr* {.importc: "struct msghdr", pure, final,
+             header: "<sys/socket.h>".} = object  ## struct msghdr
+    msg_name*: pointer  ## Optional address.
+    msg_namelen*: SockLen  ## Size of address.
+    msg_iov*: ptr IOVec    ## Scatter/gather array.
+    msg_iovlen*: cint   ## Members in msg_iov.
+    msg_control*: pointer  ## Ancillary data; see below.
+    msg_controllen*: SockLen ## Ancillary data buffer len.
+    msg_flags*: cint ## Flags on received message.
+
+
+  Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
+              header: "<sys/socket.h>".} = object ## struct cmsghdr
+    cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
+    cmsg_level*: cint   ## Originating protocol.
+    cmsg_type*: cint    ## Protocol-specific type.
+
+  TLinger* {.importc: "struct linger", pure, final,
+             header: "<sys/socket.h>".} = object ## struct linger
+    l_onoff*: cint  ## Indicates whether linger option is enabled.
+    l_linger*: cint ## Linger time, in seconds.
+
+  InPort* = uint16
+  InAddrScalar* = uint32
+
+  InAddrT* {.importc: "in_addr_t", pure, final,
+             header: "<netinet/in.h>".} = uint32
+
+  InAddr* {.importc: "struct in_addr", pure, final,
+             header: "<netinet/in.h>".} = object ## struct in_addr
+    s_addr*: InAddrScalar
+
+  Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
+                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
+    sin_family*: TSa_Family ## AF_INET.
+    sin_port*: InPort      ## Port number.
+    sin_addr*: InAddr      ## IP address.
+
+  In6Addr* {.importc: "struct in6_addr", pure, final,
+              header: "<netinet/in.h>".} = object ## struct in6_addr
+    s6_addr*: array[0..15, char]
+
+  Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
+                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
+    sin6_family*: TSa_Family ## AF_INET6.
+    sin6_port*: InPort      ## Port number.
+    sin6_flowinfo*: uint32    ## IPv6 traffic class and flow information.
+    sin6_addr*: In6Addr     ## IPv6 address.
+    sin6_scope_id*: uint32    ## Set of interfaces for a scope.
+
+  Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
+                header: "<netinet/in.h>".} = object ## struct ipv6_mreq
+    ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
+    ipv6mr_interface*: cint     ## Interface index.
+
+  Hostent* {.importc: "struct hostent", pure, final,
+              header: "<netdb.h>".} = object ## struct hostent
+    h_name*: cstring           ## Official name of the host.
+    h_aliases*: cstringArray   ## A pointer to an array of pointers to
+                               ## alternative host names, terminated by a
+                               ## null pointer.
+    h_addrtype*: cint          ## Address type.
+    h_length*: cint            ## The length, in bytes, of the address.
+    h_addr_list*: cstringArray ## A pointer to an array of pointers to network
+                               ## addresses (in network byte order) for the
+                               ## host, terminated by a null pointer.
+
+  Tnetent* {.importc: "struct netent", pure, final,
+              header: "<netdb.h>".} = object ## struct netent
+    n_name*: cstring         ## Official, fully-qualified (including the
+                             ## domain) name of the host.
+    n_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative network names, terminated by a
+                             ## null pointer.
+    n_addrtype*: cint        ## The address type of the network.
+    n_net*: uint32            ## The network number, in host byte order.
+
+  Protoent* {.importc: "struct protoent", pure, final,
+              header: "<netdb.h>".} = object ## struct protoent
+    p_name*: cstring         ## Official name of the protocol.
+    p_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative protocol names, terminated by
+                             ## a null pointer.
+    p_proto*: cint           ## The protocol number.
+
+  Servent* {.importc: "struct servent", pure, final,
+             header: "<netdb.h>".} = object ## struct servent
+    s_name*: cstring         ## Official name of the service.
+    s_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative service names, terminated by
+                             ## a null pointer.
+    s_port*: cint            ## The port number at which the service
+                             ## resides, in network byte order.
+    s_proto*: cstring        ## The name of the protocol to use when
+                             ## contacting the service.
+
+  AddrInfo* {.importc: "struct addrinfo", pure, final,
+              header: "<netdb.h>".} = object ## struct addrinfo
+    ai_flags*: cint         ## Input flags.
+    ai_family*: cint        ## Address family of socket.
+    ai_socktype*: cint      ## Socket type.
+    ai_protocol*: cint      ## Protocol of socket.
+    ai_addrlen*: SockLen   ## Length of socket address.
+    ai_addr*: ptr SockAddr ## Socket address of socket.
+    ai_canonname*: cstring  ## Canonical name of service location.
+    ai_next*: ptr AddrInfo ## Pointer to next in list.
+
+  TPollfd* {.importc: "struct pollfd", pure, final,
+             header: "<poll.h>".} = object ## struct pollfd
+    fd*: cint        ## The following descriptor being polled.
+    events*: cshort  ## The input event flags (see below).
+    revents*: cshort ## The output event flags (see below).
+
+  Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint
+
+var
+  errno* {.importc, header: "<errno.h>".}: cint ## error variable
+  h_errno* {.importc, header: "<netdb.h>".}: cint
+  daylight* {.importc, header: "<time.h>".}: cint
+  timezone* {.importc, header: "<time.h>".}: int
+
+# Regenerate using detect.nim!
+include posix_other_consts
+
+when defined(linux):
+  var
+    MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
+      ## Populate (prefault) page tables for a mapping.
+else:
+  var
+    MAP_POPULATE*: cint = 0
+
+when defined(linux) or defined(nimdoc):
+  when defined(alpha) or defined(mips) or defined(mipsel) or
+      defined(mips64) or defined(mips64el) or defined(parisc) or
+      defined(sparc) or defined(sparc64) or defined(nimdoc):
+    const SO_REUSEPORT* = cint(0x0200)
+      ## Multiple binding: load balancing on incoming TCP connections
+      ## or UDP packets. (Requires Linux kernel > 3.9)
+  else:
+    const SO_REUSEPORT* = cint(15)
+else:
+  var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint
+
+when defined(linux) or defined(bsd):
+  var SOCK_CLOEXEC* {.importc, header: "<sys/socket.h>".}: cint
+
+when defined(macosx):
+  # We can't use the NOSIGNAL flag in the `send` function, it has no effect
+  # Instead we should use SO_NOSIGPIPE in setsockopt
+  const
+    MSG_NOSIGNAL* = 0'i32
+  var
+    SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
+elif defined(solaris):
+  # Solaris doesn't have MSG_NOSIGNAL
+  const
+    MSG_NOSIGNAL* = 0'i32
+else:
+  var
+    MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
+      ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected.
+
+when defined(haiku):
+  const
+    SIGKILLTHR* = 21 ## BeOS specific: Kill just the thread, not team
+
+when hasSpawnH:
+  when defined(linux):
+    # better be safe than sorry; Linux has this flag, macosx doesn't, don't
+    # know about the other OSes
+
+    # Non-GNU systems like TCC and musl-libc  don't define __USE_GNU, so we
+    # can't get the magic number from spawn.h
+    const POSIX_SPAWN_USEVFORK* = cint(0x40)
+  else:
+    # macosx lacks this, so we define the constant to be 0 to not affect
+    # OR'ing of flags:
+    const POSIX_SPAWN_USEVFORK* = cint(0)
+
+# <sys/wait.h>
+proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Exit code, if WIFEXITED(s)
+proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Termination signal, if WIFSIGNALED(s)
+proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Stop signal, if WIFSTOPPED(s)
+proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited normally.
+proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited due to uncaught signal.
+proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child is currently stopped.
+proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child has been continued.
+
+when defined(nimHasStyleChecks):
+  {.pop.}
diff --git a/lib/posix/posix_nintendoswitch.nim b/lib/posix/posix_nintendoswitch.nim
new file mode 100644
index 000000000..b66563695
--- /dev/null
+++ b/lib/posix/posix_nintendoswitch.nim
@@ -0,0 +1,506 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2018 Joey Yakimowich-Payne
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+# To be included from posix.nim!
+
+const
+  hasSpawnH = true
+  hasAioH = false
+
+type
+  DIR* {.importc: "DIR", header: "<dirent.h>",
+          incompleteStruct.} = object
+
+const SIG_HOLD* = cast[Sighandler](2)
+
+type
+  SocketHandle* = distinct cint # The type used to represent socket descriptors
+
+type
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct clong
+
+  Timespec* {.importc: "struct timespec",
+               header: "<time.h>", final, pure.} = object ## struct timespec
+    tv_sec*: Time  ## Seconds.
+    tv_nsec*: clong  ## Nanoseconds.
+
+  Dirent* {.importc: "struct dirent",
+            header: "<dirent.h>", final, pure.} = object ## dirent_t struct
+    d_ino*: Ino
+    d_type*: int8  # uint8 really!
+    d_name*: array[256, cchar]
+
+  Tflock* {.importc: "struct flock", final, pure,
+            header: "<fcntl.h>".} = object ## flock type
+    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+    l_whence*: cshort ## Flag for starting offset.
+    l_start*: Off     ## Relative offset in bytes.
+    l_len*: Off       ## Size; if 0 then until EOF.
+    l_pid*: Pid      ## Process ID of the process holding the lock;
+                      ## returned with F_GETLK.
+
+  # no struct FTW on linux
+
+  Glob* {.importc: "glob_t", header: "<glob.h>",
+           final, pure.} = object ## glob_t
+    gl_pathc*: cint          ## Count of paths matched by pattern.
+    gl_matchc*: cint          ## Count of paths matching pattern
+    gl_offs*: cint           ## Slots to reserve at the beginning of gl_pathv.
+    gl_flags*: cint
+    gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
+    gl_errfunc*: pointer
+    gl_closedir*: pointer
+    gl_readdir*: pointer
+    gl_opendir*: pointer
+    gl_lstat*: pointer
+    gl_stat*: pointer
+
+  Group* {.importc: "struct group", header: "<grp.h>",
+            final, pure.} = object ## struct group
+    gr_name*: cstring     ## The name of the group.
+    gr_passwd*: cstring
+    gr_gid*: Gid         ## Numerical group ID.
+    gr_mem*: cstringArray ## Pointer to a null-terminated array of character
+                          ## pointers to member names.
+
+  Iconv* {.importc: "iconv_t", header: "<iconv.h>".} = pointer
+     ## Identifies the conversion from one codeset to another.
+
+  Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
+            pure.} = object
+    decimal_point*: cstring
+    thousands_sep*: cstring
+    grouping*: cstring
+    int_curr_symbol*: cstring
+    currency_symbol*: cstring
+    mon_decimal_point*: cstring
+    mon_thousands_sep*: cstring
+    mon_grouping*: cstring
+    positive_sign*: cstring
+    negative_sign*: cstring
+    int_frac_digits*: char
+    frac_digits*: char
+    p_cs_precedes*: char
+    p_sep_by_space*: char
+    n_cs_precedes*: char
+    n_sep_by_space*: char
+    p_sign_posn*: char
+    n_sign_posn*: char
+    int_n_cs_precedes*: char
+    int_n_sep_by_space*: char
+    int_n_sign_posn*: char
+    int_p_cs_precedes*: char
+    int_p_sep_by_space*: char
+    int_p_sign_posn*: char
+
+  Passwd* {.importc: "struct passwd", header: "<pwd.h>",
+             final, pure.} = object ## struct passwd
+    pw_name*: cstring   ## User's login name.
+    pw_passwd*: cstring
+    pw_uid*: Uid        ## Numerical user ID.
+    pw_gid*: Gid        ## Numerical group ID.
+    pw_comment*: cstring
+    pw_gecos*: cstring
+    pw_dir*: cstring    ## Initial working directory.
+    pw_shell*: cstring  ## Program to use as shell.
+
+  Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = clong
+    ## used for file block counts
+  Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = clong
+    ## used for block sizes
+  Clock* {.importc: "clock_t", header: "<sys/types.h>".} = clong
+  ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = cint
+  Dev* {.importc: "dev_t", header: "<sys/types.h>".} = culong
+  Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = culong
+  Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = culong
+  Gid* {.importc: "gid_t", header: "<sys/types.h>".} = cuint
+  Id* {.importc: "id_t", header: "<sys/types.h>".} = cuint
+  Ino* {.importc: "ino_t", header: "<sys/types.h>".} = culong
+  Key* {.importc: "key_t", header: "<sys/types.h>".} = cint
+  Mode* {.importc: "mode_t", header: "<sys/types.h>".} = uint16
+  Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = culong
+  Off* {.importc: "off_t", header: "<sys/types.h>".} = clong
+  Pid* {.importc: "pid_t", header: "<sys/types.h>".} = cint
+  Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>",
+                  pure, final.} = object
+    abi: array[56 div sizeof(clong), clong]
+
+  Pthread_barrier* {.importc: "pthread_barrier_t",
+                      header: "<sys/types.h>", pure, final.} = object
+    abi: array[32 div sizeof(clong), clong]
+  Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
+                          header: "<sys/types.h>", pure, final.} = object
+    abi: array[4 div sizeof(cint), cint]
+
+  Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>",
+                  pure, final.} = object
+    abi: array[48 div sizeof(clonglong), clonglong]
+  Pthread_condattr* {.importc: "pthread_condattr_t",
+                       header: "<sys/types.h>", pure, final.} = object
+    abi: array[4 div sizeof(cint), cint]
+  Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = cuint
+  Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>",
+                   pure, final.} = object
+    abi: array[48 div sizeof(clong), clong]
+  Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
+                        header: "<sys/types.h>", pure, final.} = object
+    abi: array[4 div sizeof(cint), cint]
+  Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = cint
+  Pthread_rwlock* {.importc: "pthread_rwlock_t",
+                     header: "<sys/types.h>", pure, final.} = object
+    abi: array[56 div sizeof(clong), clong]
+  Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
+                         header: "<sys/types.h>".} = object
+    abi: array[8 div sizeof(clong), clong]
+  Pthread_spinlock* {.importc: "pthread_spinlock_t",
+                       header: "<sys/types.h>".} = cint
+  Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = culong
+  Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = clong
+  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
+  Timer* {.importc: "timer_t", header: "<sys/types.h>".} = pointer
+  Uid* {.importc: "uid_t", header: "<sys/types.h>".} = cuint
+  Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = cuint
+
+  Utsname* {.importc: "struct utsname",
+              header: "<sys/utsname.h>",
+              final, pure.} = object ## struct utsname
+    sysname*,      ## Name of this implementation of the operating system.
+      nodename*,   ## Name of this node within the communications
+                   ## network to which this node is attached, if any.
+      release*,    ## Current release level of this implementation.
+      version*,    ## Current version level of this release.
+      machine*,    ## Name of the hardware type on which the
+                   ## system is running.
+      domainname*: array[65, char]
+
+  Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
+    abi: array[32 div sizeof(clong), clong]
+
+  Stat* {.importc: "struct stat",
+           header: "<sys/stat.h>", final, pure.} = object ## struct stat
+    st_dev*: Dev          ## Device ID of device containing file.
+    st_ino*: Ino          ## File serial number.
+    st_mode*: Mode        ## Mode of file (see below).
+    st_nlink*: Nlink      ## Number of hard links to the file.
+    st_uid*: Uid          ## User ID of file.
+    st_gid*: Gid          ## Group ID of file.
+    st_rdev*: Dev         ## Device ID (if file is character or block special).
+    st_size*: Off         ## For regular files, the file size in bytes.
+                           ## For symbolic links, the length in bytes of the
+                           ## pathname contained in the symbolic link.
+                           ## For a shared memory object, the length in bytes.
+                           ## For a typed memory object, the length in bytes.
+                           ## For other file types, the use of this field is
+                           ## unspecified.
+    when StatHasNanoseconds:
+      st_atim*: Timespec  ## Time of last access.
+      pad1: clong
+      st_mtim*: Timespec  ## Time of last data modification.
+      pad2: clong
+      st_ctim*: Timespec  ## Time of last status change.
+      pad3: clong
+    else:
+      st_atime*: Time     ## Time of last access.
+      pad1: clong
+      st_mtime*: Time     ## Time of last data modification.
+      pad2: clong
+      st_ctime*: Time     ## Time of last status change.
+      pad3: clong
+    st_blksize*: Blksize   ## A file system-specific preferred I/O block size
+                           ## for this object. In some file system types, this
+                           ## may vary from file to file.
+    st_blocks*: Blkcnt     ## Number of blocks allocated for this object.
+    reserved: array[2, clong]
+
+
+
+  Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
+              final, pure.} = object ## struct statvfs
+    f_bsize*: culong        ## File system block size.
+    f_frsize*: culong       ## Fundamental file system block size.
+    f_blocks*: Fsblkcnt  ## Total number of blocks on file system
+                         ## in units of f_frsize.
+    f_bfree*: Fsblkcnt   ## Total number of free blocks.
+    f_bavail*: Fsblkcnt  ## Number of free blocks available to
+                         ## non-privileged process.
+    f_files*: Fsfilcnt   ## Total number of file serial numbers.
+    f_ffree*: Fsfilcnt   ## Total number of free file serial numbers.
+    f_favail*: Fsfilcnt  ## Number of file serial numbers available to
+                         ## non-privileged process.
+    f_fsid*: culong         ## File system ID.
+    f_flag*: culong         ## Bit mask of f_flag values.
+    f_namemax*: culong      ## Maximum filename length.
+
+  # No Posix_typed_mem_info
+
+  Tm* {.importc: "struct tm", header: "<time.h>",
+         final, pure.} = object ## struct tm
+    tm_sec*: cint   ## Seconds [0,60].
+    tm_min*: cint   ## Minutes [0,59].
+    tm_hour*: cint  ## Hour [0,23].
+    tm_mday*: cint  ## Day of month [1,31].
+    tm_mon*: cint   ## Month of year [0,11].
+    tm_year*: cint  ## Years since 1900.
+    tm_wday*: cint  ## Day of week [0,6] (Sunday =0).
+    tm_yday*: cint  ## Day of year [0,365].
+    tm_isdst*: cint ## Daylight Savings flag.
+
+  Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
+                 final, pure.} = object ## struct itimerspec
+    it_interval*: Timespec  ## Timer period.
+    it_value*: Timespec     ## Timer expiration.
+
+  Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
+    ## Possibly volatile-qualified integer type of an object that can be
+    ## accessed as an atomic entity, even in the presence of asynchronous
+    ## interrupts.
+  Sigset* {.importc: "sigset_t", header: "<signal.h>", final.} = culong
+
+  SigEvent* {.importc: "struct sigevent",
+               header: "<signal.h>", final, pure.} = object ## struct sigevent
+    sigev_notify*: cint           ## Notification type.
+    sigev_signo*: cint            ## Signal number.
+    sigev_value*: SigVal          ## Signal value.
+
+  SigVal* {.importc: "union sigval",
+             header: "<signal.h>", final, pure.} = object ## struct sigval
+    sival_int*: cint    ## integer signal value
+    sival_ptr*: pointer ## pointer signal value;
+
+  Sigaction* {.importc: "struct sigaction",
+                header: "<signal.h>", final, pure.} = object ## struct sigaction
+    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
+                                            ## function or one of the macros
+                                            ## SIG_IGN or SIG_DFL.
+    sa_mask*: Sigset ## Set of signals to be blocked during execution of
+                      ## the signal handling function.
+    sa_flags*: cint   ## Special flags.
+
+  Stack* {.importc: "stack_t",
+            header: "<signal.h>", final, pure.} = object ## stack_t
+    ss_sp*: pointer  ## Stack base or pointer.
+    ss_flags*: cint  ## Flags.
+    ss_size*: csize_t ## Stack size.
+
+  SigInfo* {.importc: "siginfo_t",
+              header: "<signal.h>", final, pure.} = object ## siginfo_t
+    si_signo*: cint    ## Signal number.
+    si_code*: cint     ## Signal code.
+    si_value*: SigVal  ## Signal value.
+
+  Nl_item* {.importc: "nl_item", header: "<langinfo.h>".} = cint
+
+  Sched_param* {.importc: "struct sched_param",
+                  header: "<sched.h>",
+                  final, pure.} = object ## struct sched_param
+    sched_priority*: cint
+
+  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+             final, pure.} = object ## struct timeval
+    tv_sec*: Time       ## Seconds.
+    tv_usec*: Suseconds ## Microseconds.
+  TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
+           final, pure.} = object
+    abi: array[((64+(sizeof(clong) * 8)-1) div (sizeof(clong) * 8)), clong]
+
+proc si_pid*(info: SigInfo): Pid =
+  ## This might not be correct behavior. si_pid doesn't exist in Switch's
+  ## devkitpro headers
+  raise newException(OSError, "Nintendo switch cannot get si_pid!")
+
+type
+  Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
+            final, pure.} = object ## struct aiocb
+    aio_fildes*: cint         ## File descriptor.
+    aio_lio_opcode*: cint     ## Operation to be performed.
+    aio_reqprio*: cint        ## Request priority offset.
+    aio_buf*: pointer         ## Location of buffer.
+    aio_nbytes*: csize_t      ## Length of transfer.
+    aio_sigevent*: SigEvent   ## Signal number and value.
+    next_prio: pointer
+    abs_prio: cint
+    policy: cint
+    error_Code: cint
+    return_value: clong
+    aio_offset*: Off          ## File offset.
+    reserved: array[32, uint8]
+
+type
+  Tposix_spawnattr* {.importc: "posix_spawnattr_t",
+                      header: "<spawn.h>", final, pure.} = object
+  Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
+                               header: "<spawn.h>", final, pure.} = object
+
+# from sys/un.h
+const Sockaddr_un_path_length* = 108
+
+type
+  SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
+  # cushort really
+  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cshort
+
+  SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+              pure, final.} = object ## struct sockaddr
+    sa_len: uint8
+    sa_family*: TSa_Family         ## Address family.
+    sa_data*: array[14, char] ## Socket address (variable-length data).
+
+  Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                       header: "<sys/socket.h>",
+                       pure, final.} = object ## struct sockaddr_storage
+    ss_len: uint8
+    ss_family*: TSa_Family ## Address family.
+    ss_padding1: array[64 - sizeof(uint8) - sizeof(cshort), char]
+    ss_align: clonglong
+    ss_padding2: array[
+      128 - sizeof(uint8) - sizeof(cshort) -
+      (64 - sizeof(uint8) - sizeof(cshort)) - 64, char]
+
+  Tif_nameindex* {.importc: "struct if_nameindex", final,
+                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
+    if_index*: cuint   ## Numeric index of the interface.
+    if_name*: cstring ## Null-terminated name of the interface.
+
+
+  IOVec* {.importc: "struct iovec", pure, final,
+            header: "<sys/socket.h>".} = object ## struct iovec
+    iov_base*: pointer ## Base address of a memory region for input or output.
+    iov_len*: csize_t    ## The size of the memory pointed to by iov_base.
+
+  Tmsghdr* {.importc: "struct msghdr", pure, final,
+             header: "<sys/socket.h>".} = object  ## struct msghdr
+    msg_name*: pointer  ## Optional address.
+    msg_namelen*: SockLen  ## Size of address.
+    msg_iov*: ptr IOVec    ## Scatter/gather array.
+    msg_iovlen*: csize_t   ## Members in msg_iov.
+    msg_control*: pointer  ## Ancillary data; see below.
+    msg_controllen*: csize_t ## Ancillary data buffer len.
+    msg_flags*: cint ## Flags on received message.
+
+
+  Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
+              header: "<sys/socket.h>".} = object ## struct cmsghdr
+    cmsg_len*: csize_t ## Data byte count, including the cmsghdr.
+    cmsg_level*: cint   ## Originating protocol.
+    cmsg_type*: cint    ## Protocol-specific type.
+
+  TLinger* {.importc: "struct linger", pure, final,
+             header: "<sys/socket.h>".} = object ## struct linger
+    l_onoff*: cint  ## Indicates whether linger option is enabled.
+    l_linger*: cint ## Linger time, in seconds.
+    # data follows...
+
+  InPort* = uint16
+  InAddrScalar* = uint32
+
+  InAddrT* {.importc: "in_addr_t", pure, final,
+             header: "<netinet/in.h>".} = uint32
+
+  InAddr* {.importc: "struct in_addr", pure, final,
+             header: "<netinet/in.h>".} = object ## struct in_addr
+    s_addr*: InAddrScalar
+
+  Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
+                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
+    sin_len*: cushort
+    sin_family*: TSa_Family ## AF_INET.
+    sin_port*: InPort      ## Port number.
+    sin_addr*: InAddr      ## IP address.
+    sin_zero: array[8, uint8]
+
+  In6Addr* {.importc: "struct in6_addr", pure, final,
+              header: "<netinet/in.h>".} = object ## struct in6_addr
+    s6_addr*: array[0..15, char]
+
+  Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
+                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
+    sin6_family*: TSa_Family ## AF_INET6.
+    sin6_port*: InPort      ## Port number.
+    sin6_flowinfo*: uint32    ## IPv6 traffic class and flow information.
+    sin6_addr*: In6Addr     ## IPv6 address.
+    sin6_scope_id*: uint32    ## Set of interfaces for a scope.
+
+  Hostent* {.importc: "struct hostent", pure, final,
+              header: "<netdb.h>".} = object ## struct hostent
+    h_name*: cstring           ## Official name of the host.
+    h_aliases*: cstringArray   ## A pointer to an array of pointers to
+                               ## alternative host names, terminated by a
+                               ## null pointer.
+    h_addrtype*: cint          ## Address type.
+    h_length*: cint            ## The length, in bytes, of the address.
+    h_addr_list*: cstringArray ## A pointer to an array of pointers to network
+                               ## addresses (in network byte order) for the
+                               ## host, terminated by a null pointer.
+
+  Tnetent* {.importc: "struct netent", pure, final,
+              header: "<netdb.h>".} = object ## struct netent
+    n_name*: cstring         ## Official, fully-qualified (including the
+                             ## domain) name of the host.
+    n_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative network names, terminated by a
+                             ## null pointer.
+    n_addrtype*: cint        ## The address type of the network.
+    n_net*: uint32            ## The network number, in host byte order.
+
+  Protoent* {.importc: "struct protoent", pure, final,
+              header: "<netdb.h>".} = object ## struct protoent
+    p_name*: cstring         ## Official name of the protocol.
+    p_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative protocol names, terminated by
+                             ## a null pointer.
+    p_proto*: cint           ## The protocol number.
+
+  Servent* {.importc: "struct servent", pure, final,
+             header: "<netdb.h>".} = object ## struct servent
+    s_name*: cstring         ## Official name of the service.
+    s_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative service names, terminated by
+                             ## a null pointer.
+    s_port*: cint            ## The port number at which the service
+                             ## resides, in network byte order.
+    s_proto*: cstring        ## The name of the protocol to use when
+                             ## contacting the service.
+
+  AddrInfo* {.importc: "struct addrinfo", pure, final,
+              header: "<netdb.h>".} = object ## struct addrinfo
+    ai_flags*: cint         ## Input flags.
+    ai_family*: cint        ## Address family of socket.
+    ai_socktype*: cint      ## Socket type.
+    ai_protocol*: cint      ## Protocol of socket.
+    ai_addrlen*: SockLen   ## Length of socket address.
+    ai_canonname*: cstring  ## Canonical name of service location.
+    ai_addr*: ptr SockAddr ## Socket address of socket.
+    ai_next*: ptr AddrInfo ## Pointer to next in list.
+
+  TPollfd* {.importc: "struct pollfd", pure, final,
+             header: "<poll.h>".} = object ## struct pollfd
+    fd*: cint        ## The following descriptor being polled.
+    events*: cshort  ## The input event flags (see below).
+    revents*: cshort ## The output event flags (see below).
+
+  Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
+
+var
+  errno* {.importc, header: "<errno.h>".}: cint ## error variable
+  h_errno* {.importc, header: "<netdb.h>".}: cint
+  daylight* {.importc: "_daylight", header: "<time.h>".}: cint
+  timezone* {.importc: "_timezone", header: "<time.h>".}: clong
+
+# Regenerate using detect.nim!
+include posix_nintendoswitch_consts
+
+const POSIX_SPAWN_USEVFORK* = cint(0x40)  # needs _GNU_SOURCE!
+
+# <sys/wait.h>
+proc WEXITSTATUS*(s: cint): cint =  (s shr 8) and 0xff
+proc WIFEXITED*(s:cint) : bool = (s and 0xff) == 0
+proc WTERMSIG*(s:cint): cint = s and 0x7f
+proc WSTOPSIG*(s:cint): cint = WEXITSTATUS(s)
+proc WIFSIGNALED*(s:cint) : bool = ((s and 0x7f) > 0) and ((s and 0x7f) < 0x7f)
+proc WIFSTOPPED*(s:cint) : bool = (s and 0xff) == 0x7f
diff --git a/lib/posix/posix_nintendoswitch_consts.nim b/lib/posix/posix_nintendoswitch_consts.nim
new file mode 100644
index 000000000..8cd8824b5
--- /dev/null
+++ b/lib/posix/posix_nintendoswitch_consts.nim
@@ -0,0 +1,587 @@
+# Generated by detect.nim
+
+
+# <aio.h>
+
+# <dlfcn.h>
+
+# <errno.h>
+const E2BIG* = cint(7)
+const EACCES* = cint(13)
+const EADDRINUSE* = cint(112)
+const EADDRNOTAVAIL* = cint(125)
+const EAFNOSUPPORT* = cint(106)
+const EAGAIN* = cint(11)
+const EALREADY* = cint(120)
+const EBADF* = cint(9)
+const EBADMSG* = cint(77)
+const EBUSY* = cint(16)
+const ECANCELED* = cint(140)
+const ECHILD* = cint(10)
+const ECONNABORTED* = cint(113)
+const ECONNREFUSED* = cint(111)
+const ECONNRESET* = cint(104)
+const EDEADLK* = cint(45)
+const EDESTADDRREQ* = cint(121)
+const EDOM* = cint(33)
+const EDQUOT* = cint(132)
+const EEXIST* = cint(17)
+const EFAULT* = cint(14)
+const EFBIG* = cint(27)
+const EHOSTUNREACH* = cint(118)
+const EIDRM* = cint(36)
+const EILSEQ* = cint(138)
+const EINPROGRESS* = cint(119)
+const EINTR* = cint(4)
+const EINVAL* = cint(22)
+const EIO* = cint(5)
+const EISCONN* = cint(127)
+const EISDIR* = cint(21)
+const ELOOP* = cint(92)
+const EMFILE* = cint(24)
+const EMLINK* = cint(31)
+const EMSGSIZE* = cint(122)
+const EMULTIHOP* = cint(74)
+const ENAMETOOLONG* = cint(91)
+const ENETDOWN* = cint(115)
+const ENETRESET* = cint(126)
+const ENETUNREACH* = cint(114)
+const ENFILE* = cint(23)
+const ENOBUFS* = cint(105)
+const ENODATA* = cint(61)
+const ENODEV* = cint(19)
+const ENOENT* = cint(2)
+const ENOEXEC* = cint(8)
+const ENOLCK* = cint(46)
+const ENOLINK* = cint(67)
+const ENOMEM* = cint(12)
+const ENOMSG* = cint(35)
+const ENOPROTOOPT* = cint(109)
+const ENOSPC* = cint(28)
+const ENOSR* = cint(63)
+const ENOSTR* = cint(60)
+const ENOSYS* = cint(88)
+const ENOTCONN* = cint(128)
+const ENOTDIR* = cint(20)
+const ENOTEMPTY* = cint(90)
+const ENOTSOCK* = cint(108)
+const ENOTSUP* = cint(134)
+const ENOTTY* = cint(25)
+const ENXIO* = cint(6)
+const EOPNOTSUPP* = cint(95)
+const EOVERFLOW* = cint(139)
+const EPERM* = cint(1)
+const EPIPE* = cint(32)
+const EPROTO* = cint(71)
+const EPROTONOSUPPORT* = cint(123)
+const EPROTOTYPE* = cint(107)
+const ERANGE* = cint(34)
+const EROFS* = cint(30)
+const ESPIPE* = cint(29)
+const ESRCH* = cint(3)
+const ESTALE* = cint(133)
+const ETIME* = cint(62)
+const ETIMEDOUT* = cint(116)
+const ETXTBSY* = cint(26)
+const EWOULDBLOCK* = cint(11)
+const EXDEV* = cint(18)
+
+# <fcntl.h>
+const F_DUPFD* = cint(0)
+const F_GETFD* = cint(1)
+const F_SETFD* = cint(2)
+const F_GETFL* = cint(3)
+const F_SETFL* = cint(4)
+const F_GETLK* = cint(7)
+const F_SETLK* = cint(8)
+const F_SETLKW* = cint(9)
+const F_GETOWN* = cint(5)
+const F_SETOWN* = cint(6)
+const FD_CLOEXEC* = cint(1)
+const F_RDLCK* = cint(1)
+const F_UNLCK* = cint(3)
+const F_WRLCK* = cint(2)
+const O_CREAT* = cint(512)
+const O_EXCL* = cint(2048)
+const O_NOCTTY* = cint(32768)
+const O_TRUNC* = cint(1024)
+const O_APPEND* = cint(8)
+const O_NONBLOCK* = cint(16384)
+const O_SYNC* = cint(8192)
+const O_ACCMODE* = cint(3)
+const O_RDONLY* = cint(0)
+const O_RDWR* = cint(2)
+const O_WRONLY* = cint(1)
+
+# <fenv.h>
+
+# <fmtmsg.h>
+
+# <fnmatch.h>
+const FNM_NOMATCH* = cint(1)
+const FNM_PATHNAME* = cint(2)
+const FNM_PERIOD* = cint(4)
+const FNM_NOESCAPE* = cint(1)
+
+# <ftw.h>
+
+# <glob.h>
+const GLOB_APPEND* = cint(1)
+const GLOB_DOOFFS* = cint(2)
+const GLOB_ERR* = cint(4)
+const GLOB_MARK* = cint(8)
+const GLOB_NOCHECK* = cint(16)
+const GLOB_NOSORT* = cint(32)
+const GLOB_NOSPACE* = cint(-1)
+
+# <langinfo.h>
+const CODESET* = cint(0)
+const D_T_FMT* = cint(1)
+const D_FMT* = cint(2)
+const T_FMT* = cint(3)
+const T_FMT_AMPM* = cint(4)
+const AM_STR* = cint(5)
+const PM_STR* = cint(6)
+const DAY_1* = cint(7)
+const DAY_2* = cint(8)
+const DAY_3* = cint(9)
+const DAY_4* = cint(10)
+const DAY_5* = cint(11)
+const DAY_6* = cint(12)
+const DAY_7* = cint(13)
+const ABDAY_1* = cint(14)
+const ABDAY_2* = cint(15)
+const ABDAY_3* = cint(16)
+const ABDAY_4* = cint(17)
+const ABDAY_5* = cint(18)
+const ABDAY_6* = cint(19)
+const ABDAY_7* = cint(20)
+const MON_1* = cint(21)
+const MON_2* = cint(22)
+const MON_3* = cint(23)
+const MON_4* = cint(24)
+const MON_5* = cint(25)
+const MON_6* = cint(26)
+const MON_7* = cint(27)
+const MON_8* = cint(28)
+const MON_9* = cint(29)
+const MON_10* = cint(30)
+const MON_11* = cint(31)
+const MON_12* = cint(32)
+const ABMON_1* = cint(33)
+const ABMON_2* = cint(34)
+const ABMON_3* = cint(35)
+const ABMON_4* = cint(36)
+const ABMON_5* = cint(37)
+const ABMON_6* = cint(38)
+const ABMON_7* = cint(39)
+const ABMON_8* = cint(40)
+const ABMON_9* = cint(41)
+const ABMON_10* = cint(42)
+const ABMON_11* = cint(43)
+const ABMON_12* = cint(44)
+const ERA* = cint(45)
+const ERA_D_FMT* = cint(46)
+const ERA_D_T_FMT* = cint(47)
+const ERA_T_FMT* = cint(48)
+const ALT_DIGITS* = cint(49)
+const RADIXCHAR* = cint(50)
+const THOUSEP* = cint(51)
+const YESEXPR* = cint(52)
+const NOEXPR* = cint(53)
+const CRNCYSTR* = cint(56)
+
+# <locale.h>
+const LC_ALL* = cint(0)
+const LC_COLLATE* = cint(1)
+const LC_CTYPE* = cint(2)
+const LC_MESSAGES* = cint(6)
+const LC_MONETARY* = cint(3)
+const LC_NUMERIC* = cint(4)
+const LC_TIME* = cint(5)
+
+# <netdb.h>
+const IPPORT_RESERVED* = cint(1024)
+const HOST_NOT_FOUND* = cint(1)
+const NO_DATA* = cint(4)
+const NO_RECOVERY* = cint(3)
+const TRY_AGAIN* = cint(2)
+const AI_PASSIVE* = cint(1)
+const AI_CANONNAME* = cint(2)
+const AI_NUMERICHOST* = cint(4)
+const AI_NUMERICSERV* = cint(8)
+const AI_V4MAPPED* = cint(2048)
+const AI_ALL* = cint(256)
+const AI_ADDRCONFIG* = cint(1024)
+const NI_NOFQDN* = cint(1)
+const NI_NUMERICHOST* = cint(2)
+const NI_NAMEREQD* = cint(4)
+const NI_NUMERICSERV* = cint(8)
+const NI_NUMERICSCOPE* = cint(32)
+const NI_DGRAM* = cint(16)
+const EAI_AGAIN* = cint(2)
+const EAI_BADFLAGS* = cint(3)
+const EAI_FAIL* = cint(4)
+const EAI_FAMILY* = cint(5)
+const EAI_MEMORY* = cint(6)
+const EAI_NONAME* = cint(8)
+const EAI_SERVICE* = cint(9)
+const EAI_SOCKTYPE* = cint(10)
+const EAI_SYSTEM* = cint(11)
+const EAI_OVERFLOW* = cint(14)
+
+# <net/if.h>
+const IF_NAMESIZE* = cint(16)
+
+# <netinet/in.h>
+const IPPROTO_IP* = cint(0)
+const IPPROTO_IPV6* = cint(41)
+const IPPROTO_ICMP* = cint(1)
+const IPPROTO_ICMPV6* = cint(58)
+const IPPROTO_RAW* = cint(255)
+const IPPROTO_TCP* = cint(6)
+const IPPROTO_UDP* = cint(17)
+const INADDR_ANY* = InAddrScalar(0)
+const INADDR_LOOPBACK* = InAddrScalar(2130706433)
+const INADDR_BROADCAST* = InAddrScalar(4294967295)
+const INET_ADDRSTRLEN* = cint(16)
+const INET6_ADDRSTRLEN* = cint(46)
+const IPV6_JOIN_GROUP* = cint(12)
+const IPV6_LEAVE_GROUP* = cint(13)
+const IPV6_MULTICAST_HOPS* = cint(10)
+const IPV6_MULTICAST_IF* = cint(9)
+const IPV6_MULTICAST_LOOP* = cint(11)
+const IPV6_UNICAST_HOPS* = cint(4)
+const IPV6_V6ONLY* = cint(27)
+
+# <netinet/tcp.h>
+const TCP_NODELAY* = cint(1)
+
+# <nl_types.h>
+
+# <poll.h>
+const POLLIN* = cshort(1)
+const POLLRDNORM* = cshort(64)
+const POLLRDBAND* = cshort(128)
+const POLLPRI* = cshort(2)
+const POLLOUT* = cshort(4)
+const POLLWRNORM* = cshort(4)
+const POLLWRBAND* = cshort(256)
+const POLLERR* = cshort(8)
+const POLLHUP* = cshort(16)
+const POLLNVAL* = cshort(32)
+
+# <pthread.h>
+const PTHREAD_CREATE_DETACHED* = cint(0)
+const PTHREAD_CREATE_JOINABLE* = cint(1)
+const PTHREAD_EXPLICIT_SCHED* = cint(2)
+const PTHREAD_INHERIT_SCHED* = cint(1)
+const PTHREAD_SCOPE_PROCESS* = cint(0)
+const PTHREAD_SCOPE_SYSTEM* = cint(1)
+
+# <sched.h>
+const SCHED_FIFO* = cint(1)
+const SCHED_RR* = cint(2)
+const SCHED_OTHER* = cint(0)
+
+# <semaphore.h>
+
+# <signal.h>
+const SIGEV_NONE* = cint(1)
+const SIGEV_SIGNAL* = cint(2)
+const SIGEV_THREAD* = cint(3)
+const SIGABRT* = cint(6)
+const SIGALRM* = cint(14)
+const SIGBUS* = cint(10)
+const SIGCHLD* = cint(20)
+const SIGCONT* = cint(19)
+const SIGFPE* = cint(8)
+const SIGHUP* = cint(1)
+const SIGILL* = cint(4)
+const SIGINT* = cint(2)
+const SIGKILL* = cint(9)
+const SIGPIPE* = cint(13)
+const SIGQUIT* = cint(3)
+const SIGSEGV* = cint(11)
+const SIGSTOP* = cint(17)
+const SIGTERM* = cint(15)
+const SIGTSTP* = cint(18)
+const SIGTTIN* = cint(21)
+const SIGTTOU* = cint(22)
+const SIGUSR1* = cint(30)
+const SIGUSR2* = cint(31)
+const SIGPOLL* = cint(23)
+const SIGPROF* = cint(27)
+const SIGSYS* = cint(12)
+const SIGTRAP* = cint(5)
+const SIGURG* = cint(16)
+const SIGVTALRM* = cint(26)
+const SIGXCPU* = cint(24)
+const SIGXFSZ* = cint(25)
+const SA_NOCLDSTOP* = cint(1)
+const SIG_BLOCK* = cint(1)
+const SIG_UNBLOCK* = cint(2)
+const SIG_SETMASK* = cint(0)
+const SS_ONSTACK* = cint(1)
+const SS_DISABLE* = cint(2)
+const MINSIGSTKSZ* = cint(2048)
+const SIGSTKSZ* = cint(8192)
+const SIG_DFL* = cast[Sighandler](0)
+const SIG_ERR* = cast[Sighandler](-1)
+const SIG_IGN* = cast[Sighandler](1)
+
+# <sys/ipc.h>
+
+# <sys/mman.h>
+
+# <sys/resource.h>
+
+# <sys/select.h>
+const FD_SETSIZE* = cint(64)
+
+# <sys/socket.h>
+const MSG_CTRUNC* = cint(32)
+const MSG_DONTROUTE* = cint(4)
+const MSG_EOR* = cint(8)
+const MSG_OOB* = cint(1)
+const SCM_RIGHTS* = cint(1)
+const SO_ACCEPTCONN* = cint(2)
+const SO_BROADCAST* = cint(32)
+const SO_DEBUG* = cint(1)
+const SO_DONTROUTE* = cint(16)
+const SO_ERROR* = cint(4103)
+const SO_KEEPALIVE* = cint(8)
+const SO_LINGER* = cint(128)
+const SO_OOBINLINE* = cint(256)
+const SO_RCVBUF* = cint(4098)
+const SO_RCVLOWAT* = cint(4100)
+const SO_RCVTIMEO* = cint(4102)
+const SO_REUSEADDR* = cint(4)
+const SO_SNDBUF* = cint(4097)
+const SO_SNDLOWAT* = cint(4099)
+const SO_SNDTIMEO* = cint(4101)
+const SO_TYPE* = cint(4104)
+const SOCK_DGRAM* = cint(2)
+const SOCK_RAW* = cint(3)
+const SOCK_SEQPACKET* = cint(5)
+const SOCK_STREAM* = cint(1)
+const SOL_SOCKET* = cint(65535)
+const SOMAXCONN* = cint(128)
+const SO_REUSEPORT* = cint(512)
+const MSG_NOSIGNAL* = cint(131072)
+const MSG_PEEK* = cint(2)
+const MSG_TRUNC* = cint(16)
+const MSG_WAITALL* = cint(64)
+const AF_INET* = cint(2)
+const AF_INET6* = cint(28)
+const AF_UNIX* = cint(1)
+const AF_UNSPEC* = cint(0)
+const SHUT_RD* = cint(0)
+const SHUT_RDWR* = cint(2)
+const SHUT_WR* = cint(1)
+
+# <sys/stat.h>
+const S_IFBLK* = cint(24576)
+const S_IFCHR* = cint(8192)
+const S_IFDIR* = cint(16384)
+const S_IFIFO* = cint(4096)
+const S_IFLNK* = cint(40960)
+const S_IFMT* = cint(61440)
+const S_IFREG* = cint(32768)
+const S_IFSOCK* = cint(49152)
+const S_IRGRP* = cint(32)
+const S_IROTH* = cint(4)
+const S_IRUSR* = cint(256)
+const S_IRWXG* = cint(56)
+const S_IRWXO* = cint(7)
+const S_IRWXU* = cint(448)
+const S_ISGID* = cint(1024)
+const S_ISUID* = cint(2048)
+const S_ISVTX* = cint(512)
+const S_IWGRP* = cint(16)
+const S_IWOTH* = cint(2)
+const S_IWUSR* = cint(128)
+const S_IXGRP* = cint(8)
+const S_IXOTH* = cint(1)
+const S_IXUSR* = cint(64)
+
+# <sys/statvfs.h>
+const ST_RDONLY* = cint(1)
+const ST_NOSUID* = cint(2)
+
+# <sys/wait.h>
+const WNOHANG* = cint(1)
+const WUNTRACED* = cint(2)
+
+# <spawn.h>
+const POSIX_SPAWN_RESETIDS* = cint(1)
+const POSIX_SPAWN_SETPGROUP* = cint(2)
+const POSIX_SPAWN_SETSCHEDPARAM* = cint(4)
+const POSIX_SPAWN_SETSCHEDULER* = cint(8)
+const POSIX_SPAWN_SETSIGDEF* = cint(16)
+const POSIX_SPAWN_SETSIGMASK* = cint(32)
+
+# <stdio.h>
+const IOFBF* = cint(0)
+const IONBF* = cint(2)
+
+# <time.h>
+const CLOCKS_PER_SEC* = clong(100)
+const CLOCK_REALTIME* = cint(1)
+const TIMER_ABSTIME* = cint(4)
+const CLOCK_MONOTONIC* = cint(4)
+
+# <unistd.h>
+const F_OK* = cint(0)
+const R_OK* = cint(4)
+const W_OK* = cint(2)
+const X_OK* = cint(1)
+const F_LOCK* = cint(1)
+const F_TEST* = cint(3)
+const F_TLOCK* = cint(2)
+const F_ULOCK* = cint(0)
+const PC_2_SYMLINKS* = cint(13)
+const PC_ALLOC_SIZE_MIN* = cint(15)
+const PC_ASYNC_IO* = cint(9)
+const PC_CHOWN_RESTRICTED* = cint(6)
+const PC_FILESIZEBITS* = cint(12)
+const PC_LINK_MAX* = cint(0)
+const PC_MAX_CANON* = cint(1)
+const PC_MAX_INPUT* = cint(2)
+const PC_NAME_MAX* = cint(3)
+const PC_NO_TRUNC* = cint(7)
+const PC_PATH_MAX* = cint(4)
+const PC_PIPE_BUF* = cint(5)
+const PC_PRIO_IO* = cint(10)
+const PC_REC_INCR_XFER_SIZE* = cint(16)
+const PC_REC_MIN_XFER_SIZE* = cint(18)
+const PC_REC_XFER_ALIGN* = cint(19)
+const PC_SYMLINK_MAX* = cint(14)
+const PC_SYNC_IO* = cint(11)
+const PC_VDISABLE* = cint(8)
+const SC_2_C_BIND* = cint(108)
+const SC_2_C_DEV* = cint(109)
+const SC_2_CHAR_TERM* = cint(107)
+const SC_2_FORT_DEV* = cint(110)
+const SC_2_FORT_RUN* = cint(111)
+const SC_2_LOCALEDEF* = cint(112)
+const SC_2_PBS* = cint(113)
+const SC_2_PBS_ACCOUNTING* = cint(114)
+const SC_2_PBS_CHECKPOINT* = cint(115)
+const SC_2_PBS_LOCATE* = cint(116)
+const SC_2_PBS_MESSAGE* = cint(117)
+const SC_2_PBS_TRACK* = cint(118)
+const SC_2_SW_DEV* = cint(119)
+const SC_2_UPE* = cint(120)
+const SC_2_VERSION* = cint(121)
+const SC_ADVISORY_INFO* = cint(54)
+const SC_AIO_LISTIO_MAX* = cint(34)
+const SC_AIO_MAX* = cint(35)
+const SC_AIO_PRIO_DELTA_MAX* = cint(36)
+const SC_ARG_MAX* = cint(0)
+const SC_ASYNCHRONOUS_IO* = cint(21)
+const SC_ATEXIT_MAX* = cint(55)
+const SC_BARRIERS* = cint(56)
+const SC_BC_BASE_MAX* = cint(57)
+const SC_BC_DIM_MAX* = cint(58)
+const SC_BC_SCALE_MAX* = cint(59)
+const SC_BC_STRING_MAX* = cint(60)
+const SC_CHILD_MAX* = cint(1)
+const SC_CLK_TCK* = cint(2)
+const SC_CLOCK_SELECTION* = cint(61)
+const SC_COLL_WEIGHTS_MAX* = cint(62)
+const SC_CPUTIME* = cint(63)
+const SC_DELAYTIMER_MAX* = cint(37)
+const SC_EXPR_NEST_MAX* = cint(64)
+const SC_FSYNC* = cint(22)
+const SC_GETGR_R_SIZE_MAX* = cint(50)
+const SC_GETPW_R_SIZE_MAX* = cint(51)
+const SC_HOST_NAME_MAX* = cint(65)
+const SC_IOV_MAX* = cint(66)
+const SC_IPV6* = cint(67)
+const SC_JOB_CONTROL* = cint(5)
+const SC_LINE_MAX* = cint(68)
+const SC_LOGIN_NAME_MAX* = cint(52)
+const SC_MAPPED_FILES* = cint(23)
+const SC_MEMLOCK* = cint(24)
+const SC_MEMLOCK_RANGE* = cint(25)
+const SC_MEMORY_PROTECTION* = cint(26)
+const SC_MESSAGE_PASSING* = cint(27)
+const SC_MONOTONIC_CLOCK* = cint(69)
+const SC_MQ_OPEN_MAX* = cint(13)
+const SC_MQ_PRIO_MAX* = cint(14)
+const SC_NGROUPS_MAX* = cint(3)
+const SC_OPEN_MAX* = cint(4)
+const SC_PAGE_SIZE* = cint(8)
+const SC_PRIORITIZED_IO* = cint(28)
+const SC_PRIORITY_SCHEDULING* = cint(101)
+const SC_RAW_SOCKETS* = cint(70)
+const SC_RE_DUP_MAX* = cint(73)
+const SC_READER_WRITER_LOCKS* = cint(71)
+const SC_REALTIME_SIGNALS* = cint(29)
+const SC_REGEXP* = cint(72)
+const SC_RTSIG_MAX* = cint(15)
+const SC_SAVED_IDS* = cint(6)
+const SC_SEM_NSEMS_MAX* = cint(16)
+const SC_SEM_VALUE_MAX* = cint(17)
+const SC_SEMAPHORES* = cint(30)
+const SC_SHARED_MEMORY_OBJECTS* = cint(31)
+const SC_SHELL* = cint(74)
+const SC_SIGQUEUE_MAX* = cint(18)
+const SC_SPAWN* = cint(75)
+const SC_SPIN_LOCKS* = cint(76)
+const SC_SPORADIC_SERVER* = cint(77)
+const SC_SS_REPL_MAX* = cint(78)
+const SC_STREAM_MAX* = cint(100)
+const SC_SYMLOOP_MAX* = cint(79)
+const SC_SYNCHRONIZED_IO* = cint(32)
+const SC_THREAD_ATTR_STACKADDR* = cint(43)
+const SC_THREAD_ATTR_STACKSIZE* = cint(44)
+const SC_THREAD_CPUTIME* = cint(80)
+const SC_THREAD_DESTRUCTOR_ITERATIONS* = cint(53)
+const SC_THREAD_KEYS_MAX* = cint(38)
+const SC_THREAD_PRIO_INHERIT* = cint(46)
+const SC_THREAD_PRIO_PROTECT* = cint(47)
+const SC_THREAD_PRIORITY_SCHEDULING* = cint(45)
+const SC_THREAD_PROCESS_SHARED* = cint(48)
+const SC_THREAD_SAFE_FUNCTIONS* = cint(49)
+const SC_THREAD_SPORADIC_SERVER* = cint(81)
+const SC_THREAD_STACK_MIN* = cint(39)
+const SC_THREAD_THREADS_MAX* = cint(40)
+const SC_THREADS* = cint(42)
+const SC_TIMEOUTS* = cint(82)
+const SC_TIMER_MAX* = cint(19)
+const SC_TIMERS* = cint(33)
+const SC_TRACE* = cint(83)
+const SC_TRACE_EVENT_FILTER* = cint(84)
+const SC_TRACE_EVENT_NAME_MAX* = cint(85)
+const SC_TRACE_INHERIT* = cint(86)
+const SC_TRACE_LOG* = cint(87)
+const SC_TRACE_NAME_MAX* = cint(88)
+const SC_TRACE_SYS_MAX* = cint(89)
+const SC_TRACE_USER_EVENT_MAX* = cint(90)
+const SC_TTY_NAME_MAX* = cint(41)
+const SC_TYPED_MEMORY_OBJECTS* = cint(91)
+const SC_TZNAME_MAX* = cint(20)
+const SC_V6_ILP32_OFF32* = cint(92)
+const SC_V6_ILP32_OFFBIG* = cint(93)
+const SC_V6_LP64_OFF64* = cint(94)
+const SC_V6_LPBIG_OFFBIG* = cint(95)
+const SC_VERSION* = cint(7)
+const SC_XBS5_ILP32_OFF32* = cint(92)
+const SC_XBS5_ILP32_OFFBIG* = cint(93)
+const SC_XBS5_LP64_OFF64* = cint(94)
+const SC_XBS5_LPBIG_OFFBIG* = cint(95)
+const SC_XOPEN_CRYPT* = cint(96)
+const SC_XOPEN_ENH_I18N* = cint(97)
+const SC_XOPEN_LEGACY* = cint(98)
+const SC_XOPEN_REALTIME* = cint(99)
+const SC_XOPEN_REALTIME_THREADS* = cint(102)
+const SC_XOPEN_SHM* = cint(103)
+const SC_XOPEN_STREAMS* = cint(104)
+const SC_XOPEN_UNIX* = cint(105)
+const SC_XOPEN_VERSION* = cint(106)
+const SC_NPROCESSORS_ONLN* = cint(10)
+const SEEK_SET* = cint(0)
+const SEEK_CUR* = cint(1)
+const SEEK_END* = cint(2)
diff --git a/lib/posix/posix_openbsd_amd64.nim b/lib/posix/posix_openbsd_amd64.nim
new file mode 100644
index 000000000..184cd89c0
--- /dev/null
+++ b/lib/posix/posix_openbsd_amd64.nim
@@ -0,0 +1,565 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2012 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+const
+  hasSpawnH = true # should exist for every Posix system nowadays
+  hasAioH = false
+
+type
+  DIR* {.importc: "DIR", header: "<dirent.h>",
+          incompleteStruct.} = object
+    ## A type representing a directory stream.
+
+type
+  SocketHandle* = distinct cint # The type used to represent socket descriptors
+
+type
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct clonglong
+
+  Timespec* {.importc: "struct timespec",
+               header: "<time.h>", final, pure.} = object ## struct timespec
+    tv_sec*: Time  ## Seconds.
+    tv_nsec*: int  ## Nanoseconds.
+
+  Dirent* {.importc: "struct dirent",
+             header: "<dirent.h>", final, pure.} = object ## dirent_t struct
+    when defined(haiku):
+      d_dev*: Dev ## Device (not POSIX)
+      d_pdev*: Dev ## Parent device (only for queries) (not POSIX)
+    d_ino*: Ino  ## File serial number.
+    when defined(dragonfly):
+      # DragonflyBSD doesn't have `d_reclen` field.
+      d_type*: uint8
+    elif defined(linux) or defined(macosx) or defined(freebsd) or
+         defined(netbsd) or defined(openbsd) or defined(genode):
+      d_reclen*: cshort ## Length of this record. (not POSIX)
+      d_type*: int8 ## Type of file; not supported by all filesystem types.
+                    ## (not POSIX)
+      when defined(linux) or defined(openbsd):
+        d_off*: Off  ## Not an offset. Value that `telldir()` would return.
+    elif defined(haiku):
+      d_pino*: Ino ## Parent inode (only for queries) (not POSIX)
+      d_reclen*: cushort ## Length of this record. (not POSIX)
+
+    d_name*: array[0..255, char] ## Name of entry.
+
+  Tflock* {.importc: "struct flock", final, pure,
+            header: "<fcntl.h>".} = object ## flock type
+    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+    l_whence*: cshort ## Flag for starting offset.
+    l_start*: Off     ## Relative offset in bytes.
+    l_len*: Off       ## Size; if 0 then until EOF.
+    l_pid*: Pid      ## Process ID of the process holding the lock;
+                      ## returned with F_GETLK.
+
+  FTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
+    base*: cint
+    level*: cint
+
+  Glob* {.importc: "glob_t", header: "<glob.h>",
+           final, pure.} = object ## glob_t
+    gl_pathc*: int          ## Count of paths matched by pattern.
+    gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
+    gl_offs*: int           ## Slots to reserve at the beginning of gl_pathv.
+
+  Group* {.importc: "struct group", header: "<grp.h>",
+            final, pure.} = object ## struct group
+    gr_name*: cstring     ## The name of the group.
+    gr_gid*: Gid         ## Numerical group ID.
+    gr_mem*: cstringArray ## Pointer to a null-terminated array of character
+                          ## pointers to member names.
+
+  Iconv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} =
+    object ## Identifies the conversion from one codeset to another.
+
+  Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
+            pure.} = object
+    currency_symbol*: cstring
+    decimal_point*: cstring
+    frac_digits*: char
+    grouping*: cstring
+    int_curr_symbol*: cstring
+    int_frac_digits*: char
+    int_n_cs_precedes*: char
+    int_n_sep_by_space*: char
+    int_n_sign_posn*: char
+    int_p_cs_precedes*: char
+    int_p_sep_by_space*: char
+    int_p_sign_posn*: char
+    mon_decimal_point*: cstring
+    mon_grouping*: cstring
+    mon_thousands_sep*: cstring
+    negative_sign*: cstring
+    n_cs_precedes*: char
+    n_sep_by_space*: char
+    n_sign_posn*: char
+    positive_sign*: cstring
+    p_cs_precedes*: char
+    p_sep_by_space*: char
+    p_sign_posn*: char
+    thousands_sep*: cstring
+
+  Mqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
+  MqAttr* {.importc: "struct mq_attr",
+             header: "<mqueue.h>",
+             final, pure.} = object ## message queue attribute
+    mq_flags*: int   ## Message queue flags.
+    mq_maxmsg*: int  ## Maximum number of messages.
+    mq_msgsize*: int ## Maximum message size.
+    mq_curmsgs*: int ## Number of messages currently queued.
+
+  Passwd* {.importc: "struct passwd", header: "<pwd.h>",
+             final, pure.} = object ## struct passwd
+    pw_name*: cstring   ## User's login name.
+    pw_uid*: Uid        ## Numerical user ID.
+    pw_gid*: Gid        ## Numerical group ID.
+    pw_dir*: cstring    ## Initial working directory.
+    pw_shell*: cstring  ## Program to use as shell.
+
+  Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int
+    ## used for file block counts
+  Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int32
+    ## used for block sizes
+  Clock* {.importc: "clock_t", header: "<sys/types.h>".} = int
+  ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int
+  Dev* {.importc: "dev_t", header: "<sys/types.h>".} = (
+    when defined(freebsd):
+      uint32
+    else:
+      int32)
+  Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int
+  Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int
+  Gid* {.importc: "gid_t", header: "<sys/types.h>".} = uint32
+  Id* {.importc: "id_t", header: "<sys/types.h>".} = int
+  Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
+  Key* {.importc: "key_t", header: "<sys/types.h>".} = int
+  Mode* {.importc: "mode_t", header: "<sys/types.h>".} = uint32
+  Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = uint32
+  Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
+  Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
+  Pthread_attr* {.importc: "pthread_attr_t", header: "<pthread.h>".} = int
+  Pthread_barrier* {.importc: "pthread_barrier_t",
+                      header: "<pthread.h>".} = int
+  Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
+                          header: "<pthread.h>".} = int
+  Pthread_cond* {.importc: "pthread_cond_t", header: "<pthread.h>".} = int
+  Pthread_condattr* {.importc: "pthread_condattr_t",
+                       header: "<pthread.h>".} = int
+  Pthread_key* {.importc: "pthread_key_t", header: "<pthread.h>".} = int
+  Pthread_mutex* {.importc: "pthread_mutex_t", header: "<pthread.h>".} = int
+  Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
+                        header: "<pthread.h>".} = int
+  Pthread_once* {.importc: "pthread_once_t", header: "<pthread.h>".} = int
+  Pthread_rwlock* {.importc: "pthread_rwlock_t",
+                     header: "<pthread.h>".} = int
+  Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
+                         header: "<pthread.h>".} = int
+  Pthread_spinlock* {.importc: "pthread_spinlock_t",
+                       header: "<pthread.h>".} = int
+  Pthread* {.importc: "pthread_t", header: "<pthread.h>".} = int
+  Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int32
+  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
+  Timer* {.importc: "timer_t", header: "<sys/types.h>".} = int
+  Trace_attr* {.importc: "trace_attr_t", header: "<sys/types.h>".} = int
+  Trace_event_id* {.importc: "trace_event_id_t",
+                     header: "<sys/types.h>".} = int
+  Trace_event_set* {.importc: "trace_event_set_t",
+                      header: "<sys/types.h>".} = int
+  Trace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int
+  Uid* {.importc: "uid_t", header: "<sys/types.h>".} = uint32
+  Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int
+
+  Utsname* {.importc: "struct utsname",
+              header: "<sys/utsname.h>",
+              final, pure.} = object ## struct utsname
+    sysname*,      ## Name of this implementation of the operating system.
+      nodename*,   ## Name of this node within the communications
+                   ## network to which this node is attached, if any.
+      release*,    ## Current release level of this implementation.
+      version*,    ## Current version level of this release.
+      machine*: array[0..255, char] ## Name of the hardware type on which the
+                                     ## system is running.
+
+  Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
+  Ipc_perm* {.importc: "struct ipc_perm",
+               header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
+    uid*: Uid    ## Owner's user ID.
+    gid*: Gid    ## Owner's group ID.
+    cuid*: Uid   ## Creator's user ID.
+    cgid*: Gid   ## Creator's group ID.
+    mode*: Mode  ## Read/write permission.
+
+  Stat* {.importc: "struct stat",
+           header: "<sys/stat.h>", final, pure.} = object ## struct stat
+    st_dev*: Dev          ## Device ID of device containing file.
+    st_ino*: Ino          ## File serial number.
+    st_mode*: Mode        ## Mode of file (see below).
+    st_nlink*: Nlink      ## Number of hard links to the file.
+    st_uid*: Uid          ## User ID of file.
+    st_gid*: Gid          ## Group ID of file.
+    st_rdev*: Dev         ## Device ID (if file is character or block special).
+    st_size*: Off         ## For regular files, the file size in bytes.
+                          ## For symbolic links, the length in bytes of the
+                          ## pathname contained in the symbolic link.
+                          ## For a shared memory object, the length in bytes.
+                          ## For a typed memory object, the length in bytes.
+                          ## For other file types, the use of this field is
+                          ## unspecified.
+    when StatHasNanoseconds:
+      st_atim*: Timespec  ## Time of last access.
+      st_mtim*: Timespec  ## Time of last data modification.
+      st_ctim*: Timespec  ## Time of last status change.
+    else:
+      st_atime*: Time     ## Time of last access.
+      st_mtime*: Time     ## Time of last data modification.
+      st_ctime*: Time     ## Time of last status change.
+    st_blksize*: Blksize  ## A file system-specific preferred I/O block size
+                          ## for this object. In some file system types, this
+                          ## may vary from file to file.
+    st_blocks*: Blkcnt    ## Number of blocks allocated for this object.
+
+
+  Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
+              final, pure.} = object ## struct statvfs
+    f_bsize*: int        ## File system block size.
+    f_frsize*: int       ## Fundamental file system block size.
+    f_blocks*: Fsblkcnt  ## Total number of blocks on file system
+                         ## in units of f_frsize.
+    f_bfree*: Fsblkcnt   ## Total number of free blocks.
+    f_bavail*: Fsblkcnt  ## Number of free blocks available to
+                         ## non-privileged process.
+    f_files*: Fsfilcnt   ## Total number of file serial numbers.
+    f_ffree*: Fsfilcnt   ## Total number of free file serial numbers.
+    f_favail*: Fsfilcnt  ## Number of file serial numbers available to
+                         ## non-privileged process.
+    f_fsid*: int         ## File system ID.
+    f_flag*: int         ## Bit mask of f_flag values.
+    f_namemax*: int      ## Maximum filename length.
+
+  Posix_typed_mem_info* {.importc: "struct posix_typed_mem_info",
+                           header: "<sys/mman.h>", final, pure.} = object
+    posix_tmi_length*: int
+
+  Tm* {.importc: "struct tm", header: "<time.h>",
+         final, pure.} = object ## struct tm
+    tm_sec*: cint   ## Seconds [0,60].
+    tm_min*: cint   ## Minutes [0,59].
+    tm_hour*: cint  ## Hour [0,23].
+    tm_mday*: cint  ## Day of month [1,31].
+    tm_mon*: cint   ## Month of year [0,11].
+    tm_year*: cint  ## Years since 1900.
+    tm_wday*: cint  ## Day of week [0,6] (Sunday =0).
+    tm_yday*: cint  ## Day of year [0,365].
+    tm_isdst*: cint ## Daylight Savings flag.
+  Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
+                 final, pure.} = object ## struct itimerspec
+    it_interval*: Timespec  ## Timer period.
+    it_value*: Timespec     ## Timer expiration.
+
+  Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
+    ## Possibly volatile-qualified integer type of an object that can be
+    ## accessed as an atomic entity, even in the presence of asynchronous
+    ## interrupts.
+  Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
+
+  SigEvent* {.importc: "struct sigevent",
+               header: "<signal.h>", final, pure.} = object ## struct sigevent
+    sigev_notify*: cint           ## Notification type.
+    sigev_signo*: cint            ## Signal number.
+    sigev_value*: SigVal          ## Signal value.
+    sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
+    sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
+
+  SigVal* {.importc: "union sigval",
+             header: "<signal.h>", final, pure.} = object ## struct sigval
+    sival_ptr*: pointer ## pointer signal value;
+                        ## integer signal value not defined!
+  Sigaction* {.importc: "struct sigaction",
+                header: "<signal.h>", final, pure.} = object ## struct sigaction
+    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
+                                            ## function or one of the macros
+                                            ## SIG_IGN or SIG_DFL.
+    sa_mask*: Sigset ## Set of signals to be blocked during execution of
+                      ## the signal handling function.
+    sa_flags*: cint   ## Special flags.
+    sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
+
+  Stack* {.importc: "stack_t",
+            header: "<signal.h>", final, pure.} = object ## stack_t
+    ss_sp*: pointer  ## Stack base or pointer.
+    ss_size*: int    ## Stack size.
+    ss_flags*: cint  ## Flags.
+
+  SigStack* {.importc: "struct sigstack",
+               header: "<signal.h>", final, pure.} = object ## struct sigstack
+    ss_onstack*: cint ## Non-zero when signal stack is in use.
+    ss_sp*: pointer   ## Signal stack pointer.
+
+  SigInfo* {.importc: "siginfo_t",
+              header: "<signal.h>", final, pure.} = object ## siginfo_t
+    si_signo*: cint    ## Signal number.
+    si_code*: cint     ## Signal code.
+    si_errno*: cint    ## If non-zero, an errno value associated with
+                       ## this signal, as defined in <errno.h>.
+    si_pid*: Pid       ## Sending process ID.
+    si_uid*: Uid       ## Real user ID of sending process.
+    si_addr*: pointer  ## Address of faulting instruction.
+    si_status*: cint   ## Exit value or signal.
+    si_band*: int      ## Band event for SIGPOLL.
+    si_value*: SigVal  ## Signal value.
+
+  Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
+  Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
+
+  Sched_param* {.importc: "struct sched_param",
+                  header: "<sched.h>",
+                  final, pure.} = object ## struct sched_param
+    sched_priority*: cint
+    sched_ss_low_priority*: cint     ## Low scheduling priority for
+                                     ## sporadic server.
+    sched_ss_repl_period*: Timespec  ## Replenishment period for
+                                     ## sporadic server.
+    sched_ss_init_budget*: Timespec  ## Initial budget for sporadic server.
+    sched_ss_max_repl*: cint         ## Maximum pending replenishments for
+                                     ## sporadic server.
+
+  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+             final, pure.} = object ## struct timeval
+    tv_sec*: Time ## Seconds.
+    tv_usec*: Suseconds ## Microseconds.
+  TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
+           final, pure.} = object
+  # the following aren't actually defined, but they're here to keep things happy for now
+  Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
+               final, pure.} = object
+  Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
+               final, pure.} = object ## ucontext_t
+    uc_link*: ptr Ucontext  ## Pointer to the context that is resumed
+                            ## when this context returns.
+    uc_sigmask*: Sigset     ## The set of signals that are blocked when this
+                            ## context is active.
+    uc_stack*: Stack        ## The stack used by this context.
+    uc_mcontext*: Mcontext  ## A machine-specific representation of the saved
+                            ## context.
+
+when hasAioH:
+  type
+    Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
+              final, pure.} = object ## struct aiocb
+      aio_fildes*: cint         ## File descriptor.
+      aio_offset*: Off          ## File offset.
+      aio_buf*: pointer         ## Location of buffer.
+      aio_nbytes*: int          ## Length of transfer.
+      aio_reqprio*: cint        ## Request priority offset.
+      aio_sigevent*: SigEvent   ## Signal number and value.
+      aio_lio_opcode: cint      ## Operation to be performed.
+
+when hasSpawnH:
+  type
+    Tposix_spawnattr* {.importc: "posix_spawnattr_t",
+                        header: "<spawn.h>", final, pure.} = object
+    Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
+                                 header: "<spawn.h>", final, pure.} = object
+
+# according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html
+# this is >=92
+const Sockaddr_un_path_length* = 92
+
+type
+  SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
+  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8
+
+  SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+              pure, final.} = object ## struct sockaddr
+    sa_family*: TSa_Family         ## Address family.
+    sa_data*: array[0..255, char] ## Socket address (variable-length data).
+
+  Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
+              pure, final.} = object ## struct sockaddr_un
+    sun_family*: TSa_Family         ## Address family.
+    sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path
+
+  Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                       header: "<sys/socket.h>",
+                       pure, final.} = object ## struct sockaddr_storage
+    ss_family*: TSa_Family ## Address family.
+
+  Tif_nameindex* {.importc: "struct if_nameindex", final,
+                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
+    if_index*: cint   ## Numeric index of the interface.
+    if_name*: cstring ## Null-terminated name of the interface.
+
+
+  IOVec* {.importc: "struct iovec", pure, final,
+            header: "<sys/uio.h>".} = object ## struct iovec
+    iov_base*: pointer ## Base address of a memory region for input or output.
+    iov_len*: csize_t    ## The size of the memory pointed to by iov_base.
+
+  Tmsghdr* {.importc: "struct msghdr", pure, final,
+             header: "<sys/socket.h>".} = object  ## struct msghdr
+    msg_name*: pointer  ## Optional address.
+    msg_namelen*: SockLen  ## Size of address.
+    msg_iov*: ptr IOVec    ## Scatter/gather array.
+    msg_iovlen*: cint   ## Members in msg_iov.
+    msg_control*: pointer  ## Ancillary data; see below.
+    msg_controllen*: SockLen ## Ancillary data buffer len.
+    msg_flags*: cint ## Flags on received message.
+
+
+  Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
+              header: "<sys/socket.h>".} = object ## struct cmsghdr
+    cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
+    cmsg_level*: cint   ## Originating protocol.
+    cmsg_type*: cint    ## Protocol-specific type.
+
+  TLinger* {.importc: "struct linger", pure, final,
+             header: "<sys/socket.h>".} = object ## struct linger
+    l_onoff*: cint  ## Indicates whether linger option is enabled.
+    l_linger*: cint ## Linger time, in seconds.
+
+  InPort* = uint16
+  InAddrScalar* = uint32
+
+  InAddrT* {.importc: "in_addr_t", pure, final,
+             header: "<netinet/in.h>".} = uint32
+
+  InAddr* {.importc: "struct in_addr", pure, final,
+             header: "<netinet/in.h>".} = object ## struct in_addr
+    s_addr*: InAddrScalar
+
+  Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
+                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
+    sin_family*: TSa_Family ## AF_INET.
+    sin_port*: InPort      ## Port number.
+    sin_addr*: InAddr      ## IP address.
+
+  In6Addr* {.importc: "struct in6_addr", pure, final,
+              header: "<netinet/in.h>".} = object ## struct in6_addr
+    s6_addr*: array[0..15, char]
+
+  Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
+                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
+    sin6_family*: TSa_Family ## AF_INET6.
+    sin6_port*: InPort      ## Port number.
+    sin6_flowinfo*: uint32    ## IPv6 traffic class and flow information.
+    sin6_addr*: In6Addr     ## IPv6 address.
+    sin6_scope_id*: uint32    ## Set of interfaces for a scope.
+
+  Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
+                header: "<netinet/in.h>".} = object ## struct ipv6_mreq
+    ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
+    ipv6mr_interface*: cint     ## Interface index.
+
+  Hostent* {.importc: "struct hostent", pure, final,
+              header: "<netdb.h>".} = object ## struct hostent
+    h_name*: cstring           ## Official name of the host.
+    h_aliases*: cstringArray   ## A pointer to an array of pointers to
+                               ## alternative host names, terminated by a
+                               ## null pointer.
+    h_addrtype*: cint          ## Address type.
+    h_length*: cint            ## The length, in bytes, of the address.
+    h_addr_list*: cstringArray ## A pointer to an array of pointers to network
+                               ## addresses (in network byte order) for the
+                               ## host, terminated by a null pointer.
+
+  Tnetent* {.importc: "struct netent", pure, final,
+              header: "<netdb.h>".} = object ## struct netent
+    n_name*: cstring         ## Official, fully-qualified (including the
+                             ## domain) name of the host.
+    n_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative network names, terminated by a
+                             ## null pointer.
+    n_addrtype*: cint        ## The address type of the network.
+    n_net*: uint32            ## The network number, in host byte order.
+
+  Protoent* {.importc: "struct protoent", pure, final,
+              header: "<netdb.h>".} = object ## struct protoent
+    p_name*: cstring         ## Official name of the protocol.
+    p_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative protocol names, terminated by
+                             ## a null pointer.
+    p_proto*: cint           ## The protocol number.
+
+  Servent* {.importc: "struct servent", pure, final,
+             header: "<netdb.h>".} = object ## struct servent
+    s_name*: cstring         ## Official name of the service.
+    s_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative service names, terminated by
+                             ## a null pointer.
+    s_port*: cint            ## The port number at which the service
+                             ## resides, in network byte order.
+    s_proto*: cstring        ## The name of the protocol to use when
+                             ## contacting the service.
+
+  AddrInfo* {.importc: "struct addrinfo", pure, final,
+              header: "<netdb.h>".} = object ## struct addrinfo
+    ai_flags*: cint         ## Input flags.
+    ai_family*: cint        ## Address family of socket.
+    ai_socktype*: cint      ## Socket type.
+    ai_protocol*: cint      ## Protocol of socket.
+    ai_addrlen*: SockLen   ## Length of socket address.
+    ai_addr*: ptr SockAddr ## Socket address of socket.
+    ai_canonname*: cstring  ## Canonical name of service location.
+    ai_next*: ptr AddrInfo ## Pointer to next in list.
+
+  TPollfd* {.importc: "struct pollfd", pure, final,
+             header: "<poll.h>".} = object ## struct pollfd
+    fd*: cint        ## The following descriptor being polled.
+    events*: cshort  ## The input event flags (see below).
+    revents*: cshort ## The output event flags (see below).
+
+  Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint
+
+var
+  errno* {.importc, header: "<errno.h>".}: cint ## error variable
+  h_errno* {.importc, header: "<netdb.h>".}: cint
+  daylight* {.importc, header: "<time.h>".}: cint
+  timezone* {.importc, header: "<time.h>".}: int
+
+# Regenerate using detect.nim!
+include posix_other_consts
+
+var
+  MAP_POPULATE*: cint = 0
+
+when defined(nimdoc):
+  const SO_REUSEPORT* = cint(0x0200)
+else:
+  var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint
+
+var SOCK_CLOEXEC* {.importc, header: "<sys/socket.h>".}: cint
+
+var MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
+
+when hasSpawnH:
+    # openbsd lacks this, so we define the constant to be 0 to not affect
+    # OR'ing of flags:
+    const POSIX_SPAWN_USEVFORK* = cint(0)
+
+# <sys/wait.h>
+proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Exit code, if WIFEXITED(s)
+proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Termination signal, if WIFSIGNALED(s)
+proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Stop signal, if WIFSTOPPED(s)
+proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited normally.
+proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited due to uncaught signal.
+proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child is currently stopped.
+proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child has been continued.
+
+when defined(nimHasStyleChecks):
+  {.pop.}
diff --git a/lib/posix/posix_other.nim b/lib/posix/posix_other.nim
new file mode 100644
index 000000000..ea8731405
--- /dev/null
+++ b/lib/posix/posix_other.nim
@@ -0,0 +1,706 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2012 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+when defined(freertos) or defined(zephyr):
+  const
+    hasSpawnH = false # should exist for every Posix system nowadays
+    hasAioH = false
+else:
+  const
+    hasSpawnH = true # should exist for every Posix system nowadays
+    hasAioH = defined(linux)
+
+when defined(linux) and not defined(android):
+  # On Linux:
+  # timer_{create,delete,settime,gettime},
+  # clock_{getcpuclockid, getres, gettime, nanosleep, settime} lives in librt
+  {.passl: "-lrt".}
+when defined(solaris):
+  # On Solaris hstrerror lives in libresolv
+  {.passl: "-lresolv".}
+
+type
+  DIR* {.importc: "DIR", header: "<dirent.h>",
+          incompleteStruct.} = object
+    ## A type representing a directory stream.
+
+type
+  SocketHandle* = distinct cint # The type used to represent socket descriptors
+
+type
+  Time* {.importc: "time_t", header: "<time.h>".} = distinct (
+    when defined(nimUse64BitCTime):
+      int64
+    else:
+      clong
+  )
+
+  Timespec* {.importc: "struct timespec",
+               header: "<time.h>", final, pure.} = object ## struct timespec
+    tv_sec*: Time  ## Seconds.
+    tv_nsec*: int  ## Nanoseconds.
+
+  Dirent* {.importc: "struct dirent",
+             header: "<dirent.h>", final, pure.} = object ## dirent_t struct
+    when defined(haiku):
+      d_dev*: Dev ## Device (not POSIX)
+      d_pdev*: Dev ## Parent device (only for queries) (not POSIX)
+    d_ino*: Ino  ## File serial number.
+    when defined(dragonfly):
+      # DragonflyBSD doesn't have `d_reclen` field.
+      d_type*: uint8
+    elif defined(linux) or defined(macosx) or defined(freebsd) or
+         defined(netbsd) or defined(openbsd) or defined(genode):
+      d_reclen*: cshort ## Length of this record. (not POSIX)
+      d_type*: int8 ## Type of file; not supported by all filesystem types.
+                    ## (not POSIX)
+      when defined(linux) or defined(openbsd):
+        d_off*: Off  ## Not an offset. Value that `telldir()` would return.
+    elif defined(haiku):
+      d_pino*: Ino ## Parent inode (only for queries) (not POSIX)
+      d_reclen*: cushort ## Length of this record. (not POSIX)
+
+    d_name*: array[0..255, char] ## Name of entry.
+
+  Tflock* {.importc: "struct flock", final, pure,
+            header: "<fcntl.h>".} = object ## flock type
+    l_type*: cshort   ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+    l_whence*: cshort ## Flag for starting offset.
+    l_start*: Off     ## Relative offset in bytes.
+    l_len*: Off       ## Size; if 0 then until EOF.
+    l_pid*: Pid      ## Process ID of the process holding the lock;
+                      ## returned with F_GETLK.
+
+  FTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object
+    base*: cint
+    level*: cint
+
+  Glob* {.importc: "glob_t", header: "<glob.h>",
+           final, pure.} = object ## glob_t
+    gl_pathc*: int          ## Count of paths matched by pattern.
+    gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
+    gl_offs*: int           ## Slots to reserve at the beginning of gl_pathv.
+
+  Group* {.importc: "struct group", header: "<grp.h>",
+            final, pure.} = object ## struct group
+    gr_name*: cstring     ## The name of the group.
+    gr_gid*: Gid         ## Numerical group ID.
+    gr_mem*: cstringArray ## Pointer to a null-terminated array of character
+                          ## pointers to member names.
+
+  Iconv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} =
+    object ## Identifies the conversion from one codeset to another.
+
+  Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
+            pure.} = object
+    currency_symbol*: cstring
+    decimal_point*: cstring
+    frac_digits*: char
+    grouping*: cstring
+    int_curr_symbol*: cstring
+    int_frac_digits*: char
+    int_n_cs_precedes*: char
+    int_n_sep_by_space*: char
+    int_n_sign_posn*: char
+    int_p_cs_precedes*: char
+    int_p_sep_by_space*: char
+    int_p_sign_posn*: char
+    mon_decimal_point*: cstring
+    mon_grouping*: cstring
+    mon_thousands_sep*: cstring
+    negative_sign*: cstring
+    n_cs_precedes*: char
+    n_sep_by_space*: char
+    n_sign_posn*: char
+    positive_sign*: cstring
+    p_cs_precedes*: char
+    p_sep_by_space*: char
+    p_sign_posn*: char
+    thousands_sep*: cstring
+
+  Mqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object
+  MqAttr* {.importc: "struct mq_attr",
+             header: "<mqueue.h>",
+             final, pure.} = object ## message queue attribute
+    mq_flags*: int   ## Message queue flags.
+    mq_maxmsg*: int  ## Maximum number of messages.
+    mq_msgsize*: int ## Maximum message size.
+    mq_curmsgs*: int ## Number of messages currently queued.
+
+  Passwd* {.importc: "struct passwd", header: "<pwd.h>",
+             final, pure.} = object ## struct passwd
+    pw_name*: cstring   ## User's login name.
+    pw_uid*: Uid        ## Numerical user ID.
+    pw_gid*: Gid        ## Numerical group ID.
+    pw_dir*: cstring    ## Initial working directory.
+    pw_shell*: cstring  ## Program to use as shell.
+
+  Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int
+    ## used for file block counts
+  Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int
+    ## used for block sizes
+  Clock* {.importc: "clock_t", header: "<sys/types.h>".} = int
+  ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int
+  Dev* {.importc: "dev_t", header: "<sys/types.h>".} = int
+  Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int
+  Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int
+  Gid* {.importc: "gid_t", header: "<sys/types.h>".} = int
+  Id* {.importc: "id_t", header: "<sys/types.h>".} = int
+  Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
+  Key* {.importc: "key_t", header: "<sys/types.h>".} = int
+  Mode* {.importc: "mode_t", header: "<sys/types.h>".} = (
+    when defined(android) or defined(macos) or defined(macosx) or
+        (defined(bsd) and not defined(openbsd) and not defined(netbsd)):
+      uint16
+    else:
+      uint32
+  )
+  Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int
+  Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
+  Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
+  Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = int
+  Pthread_barrier* {.importc: "pthread_barrier_t",
+                      header: "<sys/types.h>".} = int
+  Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
+                          header: "<sys/types.h>".} = int
+  Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = int
+  Pthread_condattr* {.importc: "pthread_condattr_t",
+                       header: "<sys/types.h>".} = int
+  Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = int
+  Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = int
+  Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
+                        header: "<sys/types.h>".} = int
+  Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = int
+  Pthread_rwlock* {.importc: "pthread_rwlock_t",
+                     header: "<sys/types.h>".} = int
+  Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
+                         header: "<sys/types.h>".} = int
+  Pthread_spinlock* {.importc: "pthread_spinlock_t",
+                       header: "<sys/types.h>".} = int
+  Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = int
+  Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int
+  #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
+  Timer* {.importc: "timer_t", header: "<sys/types.h>".} = int
+  Trace_attr* {.importc: "trace_attr_t", header: "<sys/types.h>".} = int
+  Trace_event_id* {.importc: "trace_event_id_t",
+                     header: "<sys/types.h>".} = int
+  Trace_event_set* {.importc: "trace_event_set_t",
+                      header: "<sys/types.h>".} = int
+  Trace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int
+  Uid* {.importc: "uid_t", header: "<sys/types.h>".} = int
+  Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int
+
+  Utsname* {.importc: "struct utsname",
+              header: "<sys/utsname.h>",
+              final, pure.} = object ## struct utsname
+    sysname*,      ## Name of this implementation of the operating system.
+      nodename*,   ## Name of this node within the communications
+                   ## network to which this node is attached, if any.
+      release*,    ## Current release level of this implementation.
+      version*,    ## Current version level of this release.
+      machine*: array[0..255, char] ## Name of the hardware type on which the
+                                     ## system is running.
+
+  Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
+  Ipc_perm* {.importc: "struct ipc_perm",
+               header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
+    uid*: Uid    ## Owner's user ID.
+    gid*: Gid    ## Owner's group ID.
+    cuid*: Uid   ## Creator's user ID.
+    cgid*: Gid   ## Creator's group ID.
+    mode*: Mode  ## Read/write permission.
+
+  Stat* {.importc: "struct stat",
+           header: "<sys/stat.h>", final, pure.} = object ## struct stat
+    st_dev*: Dev          ## Device ID of device containing file.
+    st_ino*: Ino          ## File serial number.
+    st_mode*: Mode        ## Mode of file (see below).
+    st_nlink*: Nlink      ## Number of hard links to the file.
+    st_uid*: Uid          ## User ID of file.
+    st_gid*: Gid          ## Group ID of file.
+    st_rdev*: Dev         ## Device ID (if file is character or block special).
+    st_size*: Off         ## For regular files, the file size in bytes.
+                          ## For symbolic links, the length in bytes of the
+                          ## pathname contained in the symbolic link.
+                          ## For a shared memory object, the length in bytes.
+                          ## For a typed memory object, the length in bytes.
+                          ## For other file types, the use of this field is
+                          ## unspecified.
+    when StatHasNanoseconds:
+      st_atim*: Timespec  ## Time of last access.
+      st_mtim*: Timespec  ## Time of last data modification.
+      st_ctim*: Timespec  ## Time of last status change.
+    else:
+      st_atime*: Time     ## Time of last access.
+      st_mtime*: Time     ## Time of last data modification.
+      st_ctime*: Time     ## Time of last status change.
+    st_blksize*: Blksize  ## A file system-specific preferred I/O block size
+                          ## for this object. In some file system types, this
+                          ## may vary from file to file.
+    st_blocks*: Blkcnt    ## Number of blocks allocated for this object.
+
+
+  Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
+              final, pure.} = object ## struct statvfs
+    f_bsize*: int        ## File system block size.
+    f_frsize*: int       ## Fundamental file system block size.
+    f_blocks*: Fsblkcnt  ## Total number of blocks on file system
+                         ## in units of f_frsize.
+    f_bfree*: Fsblkcnt   ## Total number of free blocks.
+    f_bavail*: Fsblkcnt  ## Number of free blocks available to
+                         ## non-privileged process.
+    f_files*: Fsfilcnt   ## Total number of file serial numbers.
+    f_ffree*: Fsfilcnt   ## Total number of free file serial numbers.
+    f_favail*: Fsfilcnt  ## Number of file serial numbers available to
+                         ## non-privileged process.
+    f_fsid*: int         ## File system ID.
+    f_flag*: int         ## Bit mask of f_flag values.
+    f_namemax*: int      ## Maximum filename length.
+
+  Posix_typed_mem_info* {.importc: "struct posix_typed_mem_info",
+                           header: "<sys/mman.h>", final, pure.} = object
+    posix_tmi_length*: int
+
+  Tm* {.importc: "struct tm", header: "<time.h>",
+         final, pure.} = object ## struct tm
+    tm_sec*: cint   ## Seconds [0,60].
+    tm_min*: cint   ## Minutes [0,59].
+    tm_hour*: cint  ## Hour [0,23].
+    tm_mday*: cint  ## Day of month [1,31].
+    tm_mon*: cint   ## Month of year [0,11].
+    tm_year*: cint  ## Years since 1900.
+    tm_wday*: cint  ## Day of week [0,6] (Sunday =0).
+    tm_yday*: cint  ## Day of year [0,365].
+    tm_isdst*: cint ## Daylight Savings flag.
+  Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
+                 final, pure.} = object ## struct itimerspec
+    it_interval*: Timespec  ## Timer period.
+    it_value*: Timespec     ## Timer expiration.
+
+  Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
+    ## Possibly volatile-qualified integer type of an object that can be
+    ## accessed as an atomic entity, even in the presence of asynchronous
+    ## interrupts.
+  Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
+
+  SigEvent* {.importc: "struct sigevent",
+               header: "<signal.h>", final, pure.} = object ## struct sigevent
+    sigev_notify*: cint           ## Notification type.
+    sigev_signo*: cint            ## Signal number.
+    sigev_value*: SigVal          ## Signal value.
+    sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
+    sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
+
+  SigVal* {.importc: "union sigval",
+             header: "<signal.h>", final, pure.} = object ## struct sigval
+    sival_ptr*: pointer ## pointer signal value;
+                        ## integer signal value not defined!
+  Sigaction* {.importc: "struct sigaction",
+                header: "<signal.h>", final, pure.} = object ## struct sigaction
+    sa_handler*: proc (x: cint) {.noconv.}  ## Pointer to a signal-catching
+                                            ## function or one of the macros
+                                            ## SIG_IGN or SIG_DFL.
+    sa_mask*: Sigset ## Set of signals to be blocked during execution of
+                      ## the signal handling function.
+    sa_flags*: cint   ## Special flags.
+    sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}
+
+  Stack* {.importc: "stack_t",
+            header: "<signal.h>", final, pure.} = object ## stack_t
+    ss_sp*: pointer  ## Stack base or pointer.
+    ss_size*: int    ## Stack size.
+    ss_flags*: cint  ## Flags.
+
+  SigStack* {.importc: "struct sigstack",
+               header: "<signal.h>", final, pure.} = object ## struct sigstack
+    ss_onstack*: cint ## Non-zero when signal stack is in use.
+    ss_sp*: pointer   ## Signal stack pointer.
+
+  SigInfo* {.importc: "siginfo_t",
+              header: "<signal.h>", final, pure.} = object ## siginfo_t
+    si_signo*: cint    ## Signal number.
+    si_code*: cint     ## Signal code.
+    si_errno*: cint    ## If non-zero, an errno value associated with
+                       ## this signal, as defined in <errno.h>.
+    si_pid*: Pid       ## Sending process ID.
+    si_uid*: Uid       ## Real user ID of sending process.
+    si_addr*: pointer  ## Address of faulting instruction.
+    si_status*: cint   ## Exit value or signal.
+    si_band*: int      ## Band event for SIGPOLL.
+    si_value*: SigVal  ## Signal value.
+
+  Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
+  Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint
+
+  Sched_param* {.importc: "struct sched_param",
+                  header: "<sched.h>",
+                  final, pure.} = object ## struct sched_param
+    sched_priority*: cint
+    sched_ss_low_priority*: cint     ## Low scheduling priority for
+                                     ## sporadic server.
+    sched_ss_repl_period*: Timespec  ## Replenishment period for
+                                     ## sporadic server.
+    sched_ss_init_budget*: Timespec  ## Initial budget for sporadic server.
+    sched_ss_max_repl*: cint         ## Maximum pending replenishments for
+                                     ## sporadic server.
+
+  Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
+             final, pure.} = object ## struct timeval
+    tv_sec*: Time ## Seconds.
+    tv_usec*: Suseconds ## Microseconds.
+  TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
+           final, pure.} = object
+  Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
+               final, pure.} = object
+  Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
+               final, pure.} = object ## ucontext_t
+    uc_link*: ptr Ucontext  ## Pointer to the context that is resumed
+                            ## when this context returns.
+    uc_sigmask*: Sigset     ## The set of signals that are blocked when this
+                            ## context is active.
+    uc_stack*: Stack        ## The stack used by this context.
+    uc_mcontext*: Mcontext  ## A machine-specific representation of the saved
+                            ## context.
+
+when hasAioH:
+  type
+    Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
+              final, pure.} = object ## struct aiocb
+      aio_fildes*: cint         ## File descriptor.
+      aio_offset*: Off          ## File offset.
+      aio_buf*: pointer         ## Location of buffer.
+      aio_nbytes*: int          ## Length of transfer.
+      aio_reqprio*: cint        ## Request priority offset.
+      aio_sigevent*: SigEvent   ## Signal number and value.
+      aio_lio_opcode: cint      ## Operation to be performed.
+
+when hasSpawnH:
+  type
+    Tposix_spawnattr* {.importc: "posix_spawnattr_t",
+                        header: "<spawn.h>", final, pure.} = object
+    Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
+                                 header: "<spawn.h>", final, pure.} = object
+
+when defined(linux):
+  const Sockaddr_max_length* = 255
+  # from sys/un.h
+  const Sockaddr_un_path_length* = 108
+elif defined(zephyr):
+  when defined(net_ipv6):
+    const Sockaddr_max_length* = 24
+  elif defined(net_raw):
+    const Sockaddr_max_length* = 20
+  elif defined(net_ipv4):
+    const Sockaddr_max_length* = 8
+  else:
+    const Sockaddr_max_length* = 255 # just for compilation purposes
+
+  const Sockaddr_un_path_length* = Sockaddr_max_length
+  # Zephyr is heavily customizable so it's easy to get to a state  
+  # where Nim & Zephyr IPv6 settings are out of sync, causing painful runtime failures. 
+  when defined(net_ipv4) or defined(net_ipv6) or defined(net_raw):
+    {.emit: ["NIM_STATIC_ASSERT(NET_SOCKADDR_MAX_SIZE == ",
+        Sockaddr_max_length,
+        ",\"NET_SOCKADDR_MAX_SIZE and Sockaddr_max_length size mismatch!",
+        " Check that Nim and Zephyr IPv4/IPv6 settings match.",
+        " Try adding -d:net_ipv6 to enable IPv6 for Nim on Zephyr.\" );"].}
+elif defined(freertos) or defined(lwip):
+  const Sockaddr_max_length* = 14
+  const Sockaddr_un_path_length* = 108
+else:
+  const Sockaddr_max_length* = 255
+  # according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html
+  # this is >=92
+  const Sockaddr_un_path_length* = 92
+
+type
+  SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
+  TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cushort
+
+when defined(lwip):
+  type
+    SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+                pure, final.} = object ## struct sockaddr
+      sa_len*: uint8         ## Address family.
+      sa_family*: TSa_Family         ## Address family.
+      sa_data*: array[0..Sockaddr_max_length-sizeof(uint8)-sizeof(TSa_Family), char] ## Socket address (variable-length data).
+
+    Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                        header: "<sys/socket.h>",
+                        pure, final.} = object ## struct sockaddr_storage
+      s2_len*: uint8 ## Address family.
+      ss_family*: TSa_Family ## Address family.
+      s2_data1*: array[2, char] ## Address family.
+      s2_data2*: array[3, uint32] ## Address family.
+      when defined(lwip6) or defined(net_ipv6):
+        s2_data3*: array[3, uint32] ## Address family.
+elif defined(zephyr):
+  type
+    SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+                pure, final.} = object ## struct sockaddr
+      sa_family*: TSa_Family         ## Address family.
+      data*: array[0..Sockaddr_max_length-sizeof(TSa_Family), char] ## Socket address (variable-length data).
+
+    Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                        header: "<sys/socket.h>",
+                        pure, final.} = object ## struct sockaddr_storage
+      ss_family*: TSa_Family ## Address family.
+      data*: array[0..Sockaddr_max_length-sizeof(TSa_Family), char] ## Socket address (variable-length data).
+  {.emit: ["NIM_STATIC_ASSERT(sizeof(struct sockaddr) == ", sizeof(Sockaddr), ",\"struct size mismatch\" );"].}
+  {.emit: ["NIM_STATIC_ASSERT(sizeof(struct sockaddr_storage) == ", sizeof(Sockaddr_storage), ",\"struct size mismatch\" );"].}
+else:
+  type
+    SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
+                pure, final.} = object ## struct sockaddr
+      sa_family*: TSa_Family         ## Address family.
+      sa_data*: array[0..Sockaddr_max_length-sizeof(TSa_Family), char] ## Socket address (variable-length data).
+
+    Sockaddr_storage* {.importc: "struct sockaddr_storage",
+                        header: "<sys/socket.h>",
+                        pure, final.} = object ## struct sockaddr_storage
+      ss_family*: TSa_Family ## Address family.
+
+type
+  Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
+              pure, final.} = object ## struct sockaddr_un
+    sun_family*: TSa_Family         ## Address family.
+    sun_path*: array[0..Sockaddr_un_path_length-sizeof(TSa_Family), char] ## Socket path
+
+
+type
+  Tif_nameindex* {.importc: "struct if_nameindex", final,
+                   pure, header: "<net/if.h>".} = object ## struct if_nameindex
+    if_index*: cint   ## Numeric index of the interface.
+    if_name*: cstring ## Null-terminated name of the interface.
+
+
+  IOVec* {.importc: "struct iovec", pure, final,
+            header: "<sys/uio.h>".} = object ## struct iovec
+    iov_base*: pointer ## Base address of a memory region for input or output.
+    iov_len*: csize_t    ## The size of the memory pointed to by iov_base.
+
+  Tmsghdr* {.importc: "struct msghdr", pure, final,
+             header: "<sys/socket.h>".} = object  ## struct msghdr
+    msg_name*: pointer  ## Optional address.
+    msg_namelen*: SockLen  ## Size of address.
+    msg_iov*: ptr IOVec    ## Scatter/gather array.
+    msg_iovlen*: cint   ## Members in msg_iov.
+    msg_control*: pointer  ## Ancillary data; see below.
+    msg_controllen*: SockLen ## Ancillary data buffer len.
+    msg_flags*: cint ## Flags on received message.
+
+
+  Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
+              header: "<sys/socket.h>".} = object ## struct cmsghdr
+    cmsg_len*: SockLen ## Data byte count, including the cmsghdr.
+    cmsg_level*: cint   ## Originating protocol.
+    cmsg_type*: cint    ## Protocol-specific type.
+
+  TLinger* {.importc: "struct linger", pure, final,
+             header: "<sys/socket.h>".} = object ## struct linger
+    l_onoff*: cint  ## Indicates whether linger option is enabled.
+    l_linger*: cint ## Linger time, in seconds.
+
+  InPort* = uint16
+  InAddrScalar* = uint32
+
+  InAddrT* {.importc: "in_addr_t", pure, final,
+             header: "<netinet/in.h>".} = uint32
+
+  InAddr* {.importc: "struct in_addr", pure, final,
+             header: "<netinet/in.h>".} = object ## struct in_addr
+    s_addr*: InAddrScalar
+
+  # TODO: Fixme for FreeRTOS/LwIP, these are incorrect
+  Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
+                  header: "<netinet/in.h>".} = object ## struct sockaddr_in
+    sin_family*: TSa_Family ## AF_INET.
+    sin_port*: InPort      ## Port number.
+    sin_addr*: InAddr      ## IP address.
+
+  In6Addr* {.importc: "struct in6_addr", pure, final,
+              header: "<netinet/in.h>".} = object ## struct in6_addr
+    s6_addr*: array[0..15, char]
+
+  Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
+                   header: "<netinet/in.h>".} = object ## struct sockaddr_in6
+    sin6_family*: TSa_Family ## AF_INET6.
+    sin6_port*: InPort      ## Port number.
+    sin6_flowinfo*: int32    ## IPv6 traffic class and flow information.
+    sin6_addr*: In6Addr     ## IPv6 address.
+    sin6_scope_id*: int32    ## Set of interfaces for a scope.
+
+  Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
+                header: "<netinet/in.h>".} = object ## struct ipv6_mreq
+    ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
+    ipv6mr_interface*: cint     ## Interface index.
+
+  Hostent* {.importc: "struct hostent", pure, final,
+              header: "<netdb.h>".} = object ## struct hostent
+    h_name*: cstring           ## Official name of the host.
+    h_aliases*: cstringArray   ## A pointer to an array of pointers to
+                               ## alternative host names, terminated by a
+                               ## null pointer.
+    h_addrtype*: cint          ## Address type.
+    h_length*: cint            ## The length, in bytes, of the address.
+    h_addr_list*: cstringArray ## A pointer to an array of pointers to network
+                               ## addresses (in network byte order) for the
+                               ## host, terminated by a null pointer.
+
+  Tnetent* {.importc: "struct netent", pure, final,
+              header: "<netdb.h>".} = object ## struct netent
+    n_name*: cstring         ## Official, fully-qualified (including the
+                             ## domain) name of the host.
+    n_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative network names, terminated by a
+                             ## null pointer.
+    n_addrtype*: cint        ## The address type of the network.
+    n_net*: int32            ## The network number, in host byte order.
+
+  Protoent* {.importc: "struct protoent", pure, final,
+              header: "<netdb.h>".} = object ## struct protoent
+    p_name*: cstring         ## Official name of the protocol.
+    p_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative protocol names, terminated by
+                             ## a null pointer.
+    p_proto*: cint           ## The protocol number.
+
+  Servent* {.importc: "struct servent", pure, final,
+             header: "<netdb.h>".} = object ## struct servent
+    s_name*: cstring         ## Official name of the service.
+    s_aliases*: cstringArray ## A pointer to an array of pointers to
+                             ## alternative service names, terminated by
+                             ## a null pointer.
+    s_port*: cint            ## The port number at which the service
+                             ## resides, in network byte order.
+    s_proto*: cstring        ## The name of the protocol to use when
+                             ## contacting the service.
+
+  AddrInfo* {.importc: "struct addrinfo", pure, final,
+              header: "<netdb.h>".} = object ## struct addrinfo
+    ai_flags*: cint         ## Input flags.
+    ai_family*: cint        ## Address family of socket.
+    ai_socktype*: cint      ## Socket type.
+    ai_protocol*: cint      ## Protocol of socket.
+    ai_addrlen*: SockLen   ## Length of socket address.
+    ai_addr*: ptr SockAddr ## Socket address of socket.
+    ai_canonname*: cstring  ## Canonical name of service location.
+    ai_next*: ptr AddrInfo ## Pointer to next in list.
+
+when not defined(lwip):
+  type
+    TPollfd* {.importc: "struct pollfd", pure, final,
+              header: "<poll.h>".} = object ## struct pollfd
+      fd*: cint        ## The following descriptor being polled.
+      events*: cshort  ## The input event flags (see below).
+      revents*: cshort ## The output event flags (see below).
+
+  when defined(zephyr):
+    type
+      Tnfds* = distinct cint
+  else:
+    type
+      Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint
+
+var
+  errno* {.importc, header: "<errno.h>".}: cint ## error variable
+  h_errno* {.importc, header: "<netdb.h>".}: cint
+  daylight* {.importc, header: "<time.h>".}: cint
+  timezone* {.importc, header: "<time.h>".}: int
+
+# Regenerate using detect.nim!
+when defined(lwip):
+  include posix_freertos_consts
+else:
+  include posix_other_consts
+
+when defined(linux):
+  var
+    MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
+      ## Populate (prefault) page tables for a mapping.
+else:
+  var
+    MAP_POPULATE*: cint = 0
+
+when defined(linux) or defined(nimdoc):
+  when defined(alpha) or defined(mips) or defined(mipsel) or
+      defined(mips64) or defined(mips64el) or defined(parisc) or
+      defined(sparc) or defined(sparc64) or defined(nimdoc):
+    const SO_REUSEPORT* = cint(0x0200)
+      ## Multiple binding: load balancing on incoming TCP connections
+      ## or UDP packets. (Requires Linux kernel > 3.9)
+  else:
+    const SO_REUSEPORT* = cint(15)
+elif defined(nuttx):
+  # Not supported, use SO_REUSEADDR to avoid compilation errors.
+  var SO_REUSEPORT* {.importc: "SO_REUSEADDR", header: "<sys/socket.h>".}: cint
+else:
+  var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint
+
+when defined(linux) or defined(bsd) or defined(nuttx):
+  var SOCK_CLOEXEC* {.importc, header: "<sys/socket.h>".}: cint
+
+when defined(macosx):
+  # We can't use the NOSIGNAL flag in the `send` function, it has no effect
+  # Instead we should use SO_NOSIGPIPE in setsockopt
+  const
+    MSG_NOSIGNAL* = 0'i32
+  var
+    SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint
+elif defined(solaris):
+  # Solaris doesn't have MSG_NOSIGNAL
+  const
+    MSG_NOSIGNAL* = 0'i32
+elif defined(zephyr) or defined(freertos) or defined(lwip):
+  # LwIP/FreeRTOS doesn't have MSG_NOSIGNAL
+  const
+    MSG_NOSIGNAL* = 0x20'i32
+else:
+  var
+    MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint
+      ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected.
+
+when defined(haiku):
+  const
+    SIGKILLTHR* = 21 ## BeOS specific: Kill just the thread, not team
+
+when hasSpawnH:
+  when defined(linux):
+    # better be safe than sorry; Linux has this flag, macosx and NuttX don't,
+    # don't know about the other OSes
+
+    # Non-GNU systems like TCC and musl-libc don't define __USE_GNU, so we
+    # can't get the magic number from spawn.h
+    const POSIX_SPAWN_USEVFORK* = cint(0x40)
+  else:
+    # macosx and NuttX lack this, so we define the constant to be 0 to not affect
+    # OR'ing of flags:
+    const POSIX_SPAWN_USEVFORK* = cint(0)
+
+# <sys/wait.h>
+proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Exit code, if WIFEXITED(s)
+proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Termination signal, if WIFSIGNALED(s)
+proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".}
+  ## Stop signal, if WIFSTOPPED(s)
+proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited normally.
+proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child exited due to uncaught signal.
+proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child is currently stopped.
+proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".}
+  ## True if child has been continued.
+
+when defined(nimHasStyleChecks):
+  {.pop.}
diff --git a/lib/posix/posix_other_consts.nim b/lib/posix/posix_other_consts.nim
new file mode 100644
index 000000000..d346b4150
--- /dev/null
+++ b/lib/posix/posix_other_consts.nim
@@ -0,0 +1,757 @@
+# Generated by detect.nim
+
+# <aio.h>
+var AIO_ALLDONE* {.importc: "AIO_ALLDONE", header: "<aio.h>".}: cint
+var AIO_CANCELED* {.importc: "AIO_CANCELED", header: "<aio.h>".}: cint
+var AIO_NOTCANCELED* {.importc: "AIO_NOTCANCELED", header: "<aio.h>".}: cint
+var LIO_NOP* {.importc: "LIO_NOP", header: "<aio.h>".}: cint
+var LIO_NOWAIT* {.importc: "LIO_NOWAIT", header: "<aio.h>".}: cint
+var LIO_READ* {.importc: "LIO_READ", header: "<aio.h>".}: cint
+var LIO_WAIT* {.importc: "LIO_WAIT", header: "<aio.h>".}: cint
+var LIO_WRITE* {.importc: "LIO_WRITE", header: "<aio.h>".}: cint
+
+# <dlfcn.h>
+var RTLD_LAZY* {.importc: "RTLD_LAZY", header: "<dlfcn.h>".}: cint
+var RTLD_NOW* {.importc: "RTLD_NOW", header: "<dlfcn.h>".}: cint
+var RTLD_GLOBAL* {.importc: "RTLD_GLOBAL", header: "<dlfcn.h>".}: cint
+var RTLD_LOCAL* {.importc: "RTLD_LOCAL", header: "<dlfcn.h>".}: cint
+
+# <errno.h>
+var E2BIG* {.importc: "E2BIG", header: "<errno.h>".}: cint
+var EACCES* {.importc: "EACCES", header: "<errno.h>".}: cint
+var EADDRINUSE* {.importc: "EADDRINUSE", header: "<errno.h>".}: cint
+var EADDRNOTAVAIL* {.importc: "EADDRNOTAVAIL", header: "<errno.h>".}: cint
+var EAFNOSUPPORT* {.importc: "EAFNOSUPPORT", header: "<errno.h>".}: cint
+var EAGAIN* {.importc: "EAGAIN", header: "<errno.h>".}: cint
+var EALREADY* {.importc: "EALREADY", header: "<errno.h>".}: cint
+var EBADF* {.importc: "EBADF", header: "<errno.h>".}: cint
+var EBADMSG* {.importc: "EBADMSG", header: "<errno.h>".}: cint
+var EBUSY* {.importc: "EBUSY", header: "<errno.h>".}: cint
+var ECANCELED* {.importc: "ECANCELED", header: "<errno.h>".}: cint
+var ECHILD* {.importc: "ECHILD", header: "<errno.h>".}: cint
+var ECONNABORTED* {.importc: "ECONNABORTED", header: "<errno.h>".}: cint
+var ECONNREFUSED* {.importc: "ECONNREFUSED", header: "<errno.h>".}: cint
+var ECONNRESET* {.importc: "ECONNRESET", header: "<errno.h>".}: cint
+var EDEADLK* {.importc: "EDEADLK", header: "<errno.h>".}: cint
+var EDESTADDRREQ* {.importc: "EDESTADDRREQ", header: "<errno.h>".}: cint
+var EDOM* {.importc: "EDOM", header: "<errno.h>".}: cint
+var EDQUOT* {.importc: "EDQUOT", header: "<errno.h>".}: cint
+var EEXIST* {.importc: "EEXIST", header: "<errno.h>".}: cint
+var EFAULT* {.importc: "EFAULT", header: "<errno.h>".}: cint
+var EFBIG* {.importc: "EFBIG", header: "<errno.h>".}: cint
+var EHOSTUNREACH* {.importc: "EHOSTUNREACH", header: "<errno.h>".}: cint
+var EIDRM* {.importc: "EIDRM", header: "<errno.h>".}: cint
+var EILSEQ* {.importc: "EILSEQ", header: "<errno.h>".}: cint
+var EINPROGRESS* {.importc: "EINPROGRESS", header: "<errno.h>".}: cint
+var EINTR* {.importc: "EINTR", header: "<errno.h>".}: cint
+var EINVAL* {.importc: "EINVAL", header: "<errno.h>".}: cint
+var EIO* {.importc: "EIO", header: "<errno.h>".}: cint
+var EISCONN* {.importc: "EISCONN", header: "<errno.h>".}: cint
+var EISDIR* {.importc: "EISDIR", header: "<errno.h>".}: cint
+var ELOOP* {.importc: "ELOOP", header: "<errno.h>".}: cint
+var EMFILE* {.importc: "EMFILE", header: "<errno.h>".}: cint
+var EMLINK* {.importc: "EMLINK", header: "<errno.h>".}: cint
+var EMSGSIZE* {.importc: "EMSGSIZE", header: "<errno.h>".}: cint
+var EMULTIHOP* {.importc: "EMULTIHOP", header: "<errno.h>".}: cint
+var ENAMETOOLONG* {.importc: "ENAMETOOLONG", header: "<errno.h>".}: cint
+var ENETDOWN* {.importc: "ENETDOWN", header: "<errno.h>".}: cint
+var ENETRESET* {.importc: "ENETRESET", header: "<errno.h>".}: cint
+var ENETUNREACH* {.importc: "ENETUNREACH", header: "<errno.h>".}: cint
+var ENFILE* {.importc: "ENFILE", header: "<errno.h>".}: cint
+var ENOBUFS* {.importc: "ENOBUFS", header: "<errno.h>".}: cint
+var ENODATA* {.importc: "ENODATA", header: "<errno.h>".}: cint
+var ENODEV* {.importc: "ENODEV", header: "<errno.h>".}: cint
+var ENOENT* {.importc: "ENOENT", header: "<errno.h>".}: cint
+var ENOEXEC* {.importc: "ENOEXEC", header: "<errno.h>".}: cint
+var ENOLCK* {.importc: "ENOLCK", header: "<errno.h>".}: cint
+var ENOLINK* {.importc: "ENOLINK", header: "<errno.h>".}: cint
+var ENOMEM* {.importc: "ENOMEM", header: "<errno.h>".}: cint
+var ENOMSG* {.importc: "ENOMSG", header: "<errno.h>".}: cint
+var ENOPROTOOPT* {.importc: "ENOPROTOOPT", header: "<errno.h>".}: cint
+var ENOSPC* {.importc: "ENOSPC", header: "<errno.h>".}: cint
+var ENOSR* {.importc: "ENOSR", header: "<errno.h>".}: cint
+var ENOSTR* {.importc: "ENOSTR", header: "<errno.h>".}: cint
+var ENOSYS* {.importc: "ENOSYS", header: "<errno.h>".}: cint
+var ENOTCONN* {.importc: "ENOTCONN", header: "<errno.h>".}: cint
+var ENOTDIR* {.importc: "ENOTDIR", header: "<errno.h>".}: cint
+var ENOTEMPTY* {.importc: "ENOTEMPTY", header: "<errno.h>".}: cint
+var ENOTSOCK* {.importc: "ENOTSOCK", header: "<errno.h>".}: cint
+var ENOTSUP* {.importc: "ENOTSUP", header: "<errno.h>".}: cint
+var ENOTTY* {.importc: "ENOTTY", header: "<errno.h>".}: cint
+var ENXIO* {.importc: "ENXIO", header: "<errno.h>".}: cint
+var EOPNOTSUPP* {.importc: "EOPNOTSUPP", header: "<errno.h>".}: cint
+var EOVERFLOW* {.importc: "EOVERFLOW", header: "<errno.h>".}: cint
+var EPERM* {.importc: "EPERM", header: "<errno.h>".}: cint
+var EPIPE* {.importc: "EPIPE", header: "<errno.h>".}: cint
+var EPROTO* {.importc: "EPROTO", header: "<errno.h>".}: cint
+var EPROTONOSUPPORT* {.importc: "EPROTONOSUPPORT", header: "<errno.h>".}: cint
+var EPROTOTYPE* {.importc: "EPROTOTYPE", header: "<errno.h>".}: cint
+var ERANGE* {.importc: "ERANGE", header: "<errno.h>".}: cint
+var EROFS* {.importc: "EROFS", header: "<errno.h>".}: cint
+var ESPIPE* {.importc: "ESPIPE", header: "<errno.h>".}: cint
+var ESRCH* {.importc: "ESRCH", header: "<errno.h>".}: cint
+var ESTALE* {.importc: "ESTALE", header: "<errno.h>".}: cint
+var ETIME* {.importc: "ETIME", header: "<errno.h>".}: cint
+var ETIMEDOUT* {.importc: "ETIMEDOUT", header: "<errno.h>".}: cint
+var ETXTBSY* {.importc: "ETXTBSY", header: "<errno.h>".}: cint
+var EWOULDBLOCK* {.importc: "EWOULDBLOCK", header: "<errno.h>".}: cint
+var EXDEV* {.importc: "EXDEV", header: "<errno.h>".}: cint
+
+# <fcntl.h>
+var F_DUPFD* {.importc: "F_DUPFD", header: "<fcntl.h>".}: cint
+when defined(nuttx):
+  var F_DUPFD_CLOEXEC* {.importc: "F_DUPFD_CLOEXEC", header: "<fcntl.h>".}: cint
+else:
+  var F_DUPFD_CLOEXEC* {.importc: "F_DUPFD", header: "<fcntl.h>".}: cint
+var F_GETFD* {.importc: "F_GETFD", header: "<fcntl.h>".}: cint
+var F_SETFD* {.importc: "F_SETFD", header: "<fcntl.h>".}: cint
+var F_GETFL* {.importc: "F_GETFL", header: "<fcntl.h>".}: cint
+var F_SETFL* {.importc: "F_SETFL", header: "<fcntl.h>".}: cint
+var F_GETLK* {.importc: "F_GETLK", header: "<fcntl.h>".}: cint
+var F_SETLK* {.importc: "F_SETLK", header: "<fcntl.h>".}: cint
+var F_SETLKW* {.importc: "F_SETLKW", header: "<fcntl.h>".}: cint
+var F_GETOWN* {.importc: "F_GETOWN", header: "<fcntl.h>".}: cint
+var F_SETOWN* {.importc: "F_SETOWN", header: "<fcntl.h>".}: cint
+var FD_CLOEXEC* {.importc: "FD_CLOEXEC", header: "<fcntl.h>".}: cint
+var F_RDLCK* {.importc: "F_RDLCK", header: "<fcntl.h>".}: cint
+var F_UNLCK* {.importc: "F_UNLCK", header: "<fcntl.h>".}: cint
+var F_WRLCK* {.importc: "F_WRLCK", header: "<fcntl.h>".}: cint
+var O_CREAT* {.importc: "O_CREAT", header: "<fcntl.h>".}: cint
+var O_EXCL* {.importc: "O_EXCL", header: "<fcntl.h>".}: cint
+var O_NOCTTY* {.importc: "O_NOCTTY", header: "<fcntl.h>".}: cint
+var O_TRUNC* {.importc: "O_TRUNC", header: "<fcntl.h>".}: cint
+var O_APPEND* {.importc: "O_APPEND", header: "<fcntl.h>".}: cint
+var O_DSYNC* {.importc: "O_DSYNC", header: "<fcntl.h>".}: cint
+var O_NONBLOCK* {.importc: "O_NONBLOCK", header: "<fcntl.h>".}: cint
+var O_RSYNC* {.importc: "O_RSYNC", header: "<fcntl.h>".}: cint
+var O_SYNC* {.importc: "O_SYNC", header: "<fcntl.h>".}: cint
+var O_ACCMODE* {.importc: "O_ACCMODE", header: "<fcntl.h>".}: cint
+var O_RDONLY* {.importc: "O_RDONLY", header: "<fcntl.h>".}: cint
+var O_RDWR* {.importc: "O_RDWR", header: "<fcntl.h>".}: cint
+var O_WRONLY* {.importc: "O_WRONLY", header: "<fcntl.h>".}: cint
+var O_CLOEXEC* {.importc: "O_CLOEXEC", header: "<fcntl.h>".}: cint
+when defined(nuttx):
+  var O_DIRECT* {.importc: "O_DIRECT", header: "<fcntl.h>".}: cint
+  var O_PATH* {.importc: "O_PATH", header: "<fcntl.h>".}: cint
+  var O_NOATIME* {.importc: "O_NOATIME", header: "<fcntl.h>".}: cint
+  var O_TMPFILE* {.importc: "O_TMPFILE", header: "<fcntl.h>".}: cint
+var POSIX_FADV_NORMAL* {.importc: "POSIX_FADV_NORMAL", header: "<fcntl.h>".}: cint
+var POSIX_FADV_SEQUENTIAL* {.importc: "POSIX_FADV_SEQUENTIAL", header: "<fcntl.h>".}: cint
+var POSIX_FADV_RANDOM* {.importc: "POSIX_FADV_RANDOM", header: "<fcntl.h>".}: cint
+var POSIX_FADV_WILLNEED* {.importc: "POSIX_FADV_WILLNEED", header: "<fcntl.h>".}: cint
+var POSIX_FADV_DONTNEED* {.importc: "POSIX_FADV_DONTNEED", header: "<fcntl.h>".}: cint
+var POSIX_FADV_NOREUSE* {.importc: "POSIX_FADV_NOREUSE", header: "<fcntl.h>".}: cint
+
+# <fenv.h>
+var FE_DIVBYZERO* {.importc: "FE_DIVBYZERO", header: "<fenv.h>".}: cint
+var FE_INEXACT* {.importc: "FE_INEXACT", header: "<fenv.h>".}: cint
+var FE_INVALID* {.importc: "FE_INVALID", header: "<fenv.h>".}: cint
+var FE_OVERFLOW* {.importc: "FE_OVERFLOW", header: "<fenv.h>".}: cint
+var FE_UNDERFLOW* {.importc: "FE_UNDERFLOW", header: "<fenv.h>".}: cint
+var FE_ALL_EXCEPT* {.importc: "FE_ALL_EXCEPT", header: "<fenv.h>".}: cint
+var FE_DOWNWARD* {.importc: "FE_DOWNWARD", header: "<fenv.h>".}: cint
+var FE_TONEAREST* {.importc: "FE_TONEAREST", header: "<fenv.h>".}: cint
+var FE_TOWARDZERO* {.importc: "FE_TOWARDZERO", header: "<fenv.h>".}: cint
+var FE_UPWARD* {.importc: "FE_UPWARD", header: "<fenv.h>".}: cint
+var FE_DFL_ENV* {.importc: "FE_DFL_ENV", header: "<fenv.h>".}: cint
+
+# <fmtmsg.h>
+var MM_HARD* {.importc: "MM_HARD", header: "<fmtmsg.h>".}: cint
+var MM_SOFT* {.importc: "MM_SOFT", header: "<fmtmsg.h>".}: cint
+var MM_FIRM* {.importc: "MM_FIRM", header: "<fmtmsg.h>".}: cint
+var MM_APPL* {.importc: "MM_APPL", header: "<fmtmsg.h>".}: cint
+var MM_UTIL* {.importc: "MM_UTIL", header: "<fmtmsg.h>".}: cint
+var MM_OPSYS* {.importc: "MM_OPSYS", header: "<fmtmsg.h>".}: cint
+var MM_RECOVER* {.importc: "MM_RECOVER", header: "<fmtmsg.h>".}: cint
+var MM_NRECOV* {.importc: "MM_NRECOV", header: "<fmtmsg.h>".}: cint
+var MM_HALT* {.importc: "MM_HALT", header: "<fmtmsg.h>".}: cint
+var MM_ERROR* {.importc: "MM_ERROR", header: "<fmtmsg.h>".}: cint
+var MM_WARNING* {.importc: "MM_WARNING", header: "<fmtmsg.h>".}: cint
+var MM_INFO* {.importc: "MM_INFO", header: "<fmtmsg.h>".}: cint
+var MM_NOSEV* {.importc: "MM_NOSEV", header: "<fmtmsg.h>".}: cint
+var MM_PRINT* {.importc: "MM_PRINT", header: "<fmtmsg.h>".}: cint
+var MM_CONSOLE* {.importc: "MM_CONSOLE", header: "<fmtmsg.h>".}: cint
+var MM_OK* {.importc: "MM_OK", header: "<fmtmsg.h>".}: cint
+var MM_NOTOK* {.importc: "MM_NOTOK", header: "<fmtmsg.h>".}: cint
+var MM_NOMSG* {.importc: "MM_NOMSG", header: "<fmtmsg.h>".}: cint
+var MM_NOCON* {.importc: "MM_NOCON", header: "<fmtmsg.h>".}: cint
+
+# <fnmatch.h>
+var FNM_NOMATCH* {.importc: "FNM_NOMATCH", header: "<fnmatch.h>".}: cint
+var FNM_PATHNAME* {.importc: "FNM_PATHNAME", header: "<fnmatch.h>".}: cint
+var FNM_PERIOD* {.importc: "FNM_PERIOD", header: "<fnmatch.h>".}: cint
+var FNM_NOESCAPE* {.importc: "FNM_NOESCAPE", header: "<fnmatch.h>".}: cint
+var FNM_NOSYS* {.importc: "FNM_NOSYS", header: "<fnmatch.h>".}: cint
+
+# <ftw.h>
+var FTW_F* {.importc: "FTW_F", header: "<ftw.h>".}: cint
+var FTW_D* {.importc: "FTW_D", header: "<ftw.h>".}: cint
+var FTW_DNR* {.importc: "FTW_DNR", header: "<ftw.h>".}: cint
+var FTW_DP* {.importc: "FTW_DP", header: "<ftw.h>".}: cint
+var FTW_NS* {.importc: "FTW_NS", header: "<ftw.h>".}: cint
+var FTW_SL* {.importc: "FTW_SL", header: "<ftw.h>".}: cint
+var FTW_SLN* {.importc: "FTW_SLN", header: "<ftw.h>".}: cint
+var FTW_PHYS* {.importc: "FTW_PHYS", header: "<ftw.h>".}: cint
+var FTW_MOUNT* {.importc: "FTW_MOUNT", header: "<ftw.h>".}: cint
+var FTW_DEPTH* {.importc: "FTW_DEPTH", header: "<ftw.h>".}: cint
+var FTW_CHDIR* {.importc: "FTW_CHDIR", header: "<ftw.h>".}: cint
+
+# <glob.h>
+var GLOB_APPEND* {.importc: "GLOB_APPEND", header: "<glob.h>".}: cint
+var GLOB_DOOFFS* {.importc: "GLOB_DOOFFS", header: "<glob.h>".}: cint
+var GLOB_ERR* {.importc: "GLOB_ERR", header: "<glob.h>".}: cint
+var GLOB_MARK* {.importc: "GLOB_MARK", header: "<glob.h>".}: cint
+var GLOB_NOCHECK* {.importc: "GLOB_NOCHECK", header: "<glob.h>".}: cint
+var GLOB_NOESCAPE* {.importc: "GLOB_NOESCAPE", header: "<glob.h>".}: cint
+var GLOB_NOSORT* {.importc: "GLOB_NOSORT", header: "<glob.h>".}: cint
+var GLOB_ABORTED* {.importc: "GLOB_ABORTED", header: "<glob.h>".}: cint
+var GLOB_NOMATCH* {.importc: "GLOB_NOMATCH", header: "<glob.h>".}: cint
+var GLOB_NOSPACE* {.importc: "GLOB_NOSPACE", header: "<glob.h>".}: cint
+var GLOB_NOSYS* {.importc: "GLOB_NOSYS", header: "<glob.h>".}: cint
+
+# <langinfo.h>
+var CODESET* {.importc: "CODESET", header: "<langinfo.h>".}: cint
+var D_T_FMT* {.importc: "D_T_FMT", header: "<langinfo.h>".}: cint
+var D_FMT* {.importc: "D_FMT", header: "<langinfo.h>".}: cint
+var T_FMT* {.importc: "T_FMT", header: "<langinfo.h>".}: cint
+var T_FMT_AMPM* {.importc: "T_FMT_AMPM", header: "<langinfo.h>".}: cint
+var AM_STR* {.importc: "AM_STR", header: "<langinfo.h>".}: cint
+var PM_STR* {.importc: "PM_STR", header: "<langinfo.h>".}: cint
+var DAY_1* {.importc: "DAY_1", header: "<langinfo.h>".}: cint
+var DAY_2* {.importc: "DAY_2", header: "<langinfo.h>".}: cint
+var DAY_3* {.importc: "DAY_3", header: "<langinfo.h>".}: cint
+var DAY_4* {.importc: "DAY_4", header: "<langinfo.h>".}: cint
+var DAY_5* {.importc: "DAY_5", header: "<langinfo.h>".}: cint
+var DAY_6* {.importc: "DAY_6", header: "<langinfo.h>".}: cint
+var DAY_7* {.importc: "DAY_7", header: "<langinfo.h>".}: cint
+var ABDAY_1* {.importc: "ABDAY_1", header: "<langinfo.h>".}: cint
+var ABDAY_2* {.importc: "ABDAY_2", header: "<langinfo.h>".}: cint
+var ABDAY_3* {.importc: "ABDAY_3", header: "<langinfo.h>".}: cint
+var ABDAY_4* {.importc: "ABDAY_4", header: "<langinfo.h>".}: cint
+var ABDAY_5* {.importc: "ABDAY_5", header: "<langinfo.h>".}: cint
+var ABDAY_6* {.importc: "ABDAY_6", header: "<langinfo.h>".}: cint
+var ABDAY_7* {.importc: "ABDAY_7", header: "<langinfo.h>".}: cint
+var MON_1* {.importc: "MON_1", header: "<langinfo.h>".}: cint
+var MON_2* {.importc: "MON_2", header: "<langinfo.h>".}: cint
+var MON_3* {.importc: "MON_3", header: "<langinfo.h>".}: cint
+var MON_4* {.importc: "MON_4", header: "<langinfo.h>".}: cint
+var MON_5* {.importc: "MON_5", header: "<langinfo.h>".}: cint
+var MON_6* {.importc: "MON_6", header: "<langinfo.h>".}: cint
+var MON_7* {.importc: "MON_7", header: "<langinfo.h>".}: cint
+var MON_8* {.importc: "MON_8", header: "<langinfo.h>".}: cint
+var MON_9* {.importc: "MON_9", header: "<langinfo.h>".}: cint
+var MON_10* {.importc: "MON_10", header: "<langinfo.h>".}: cint
+var MON_11* {.importc: "MON_11", header: "<langinfo.h>".}: cint
+var MON_12* {.importc: "MON_12", header: "<langinfo.h>".}: cint
+var ABMON_1* {.importc: "ABMON_1", header: "<langinfo.h>".}: cint
+var ABMON_2* {.importc: "ABMON_2", header: "<langinfo.h>".}: cint
+var ABMON_3* {.importc: "ABMON_3", header: "<langinfo.h>".}: cint
+var ABMON_4* {.importc: "ABMON_4", header: "<langinfo.h>".}: cint
+var ABMON_5* {.importc: "ABMON_5", header: "<langinfo.h>".}: cint
+var ABMON_6* {.importc: "ABMON_6", header: "<langinfo.h>".}: cint
+var ABMON_7* {.importc: "ABMON_7", header: "<langinfo.h>".}: cint
+var ABMON_8* {.importc: "ABMON_8", header: "<langinfo.h>".}: cint
+var ABMON_9* {.importc: "ABMON_9", header: "<langinfo.h>".}: cint
+var ABMON_10* {.importc: "ABMON_10", header: "<langinfo.h>".}: cint
+var ABMON_11* {.importc: "ABMON_11", header: "<langinfo.h>".}: cint
+var ABMON_12* {.importc: "ABMON_12", header: "<langinfo.h>".}: cint
+var ERA* {.importc: "ERA", header: "<langinfo.h>".}: cint
+var ERA_D_FMT* {.importc: "ERA_D_FMT", header: "<langinfo.h>".}: cint
+var ERA_D_T_FMT* {.importc: "ERA_D_T_FMT", header: "<langinfo.h>".}: cint
+var ERA_T_FMT* {.importc: "ERA_T_FMT", header: "<langinfo.h>".}: cint
+var ALT_DIGITS* {.importc: "ALT_DIGITS", header: "<langinfo.h>".}: cint
+var RADIXCHAR* {.importc: "RADIXCHAR", header: "<langinfo.h>".}: cint
+var THOUSEP* {.importc: "THOUSEP", header: "<langinfo.h>".}: cint
+var YESEXPR* {.importc: "YESEXPR", header: "<langinfo.h>".}: cint
+var NOEXPR* {.importc: "NOEXPR", header: "<langinfo.h>".}: cint
+var CRNCYSTR* {.importc: "CRNCYSTR", header: "<langinfo.h>".}: cint
+
+# <locale.h>
+var LC_ALL* {.importc: "LC_ALL", header: "<locale.h>".}: cint
+var LC_COLLATE* {.importc: "LC_COLLATE", header: "<locale.h>".}: cint
+var LC_CTYPE* {.importc: "LC_CTYPE", header: "<locale.h>".}: cint
+var LC_MESSAGES* {.importc: "LC_MESSAGES", header: "<locale.h>".}: cint
+var LC_MONETARY* {.importc: "LC_MONETARY", header: "<locale.h>".}: cint
+var LC_NUMERIC* {.importc: "LC_NUMERIC", header: "<locale.h>".}: cint
+var LC_TIME* {.importc: "LC_TIME", header: "<locale.h>".}: cint
+
+# <netdb.h>
+var IPPORT_RESERVED* {.importc: "IPPORT_RESERVED", header: "<netdb.h>".}: cint
+var HOST_NOT_FOUND* {.importc: "HOST_NOT_FOUND", header: "<netdb.h>".}: cint
+var NO_DATA* {.importc: "NO_DATA", header: "<netdb.h>".}: cint
+var NO_RECOVERY* {.importc: "NO_RECOVERY", header: "<netdb.h>".}: cint
+var TRY_AGAIN* {.importc: "TRY_AGAIN", header: "<netdb.h>".}: cint
+var AI_PASSIVE* {.importc: "AI_PASSIVE", header: "<netdb.h>".}: cint
+var AI_CANONNAME* {.importc: "AI_CANONNAME", header: "<netdb.h>".}: cint
+var AI_NUMERICHOST* {.importc: "AI_NUMERICHOST", header: "<netdb.h>".}: cint
+var AI_NUMERICSERV* {.importc: "AI_NUMERICSERV", header: "<netdb.h>".}: cint
+var AI_V4MAPPED* {.importc: "AI_V4MAPPED", header: "<netdb.h>".}: cint
+var AI_ALL* {.importc: "AI_ALL", header: "<netdb.h>".}: cint
+var AI_ADDRCONFIG* {.importc: "AI_ADDRCONFIG", header: "<netdb.h>".}: cint
+var NI_NOFQDN* {.importc: "NI_NOFQDN", header: "<netdb.h>".}: cint
+var NI_NUMERICHOST* {.importc: "NI_NUMERICHOST", header: "<netdb.h>".}: cint
+var NI_NAMEREQD* {.importc: "NI_NAMEREQD", header: "<netdb.h>".}: cint
+var NI_NUMERICSERV* {.importc: "NI_NUMERICSERV", header: "<netdb.h>".}: cint
+var NI_NUMERICSCOPE* {.importc: "NI_NUMERICSCOPE", header: "<netdb.h>".}: cint
+var NI_DGRAM* {.importc: "NI_DGRAM", header: "<netdb.h>".}: cint
+var EAI_AGAIN* {.importc: "EAI_AGAIN", header: "<netdb.h>".}: cint
+var EAI_BADFLAGS* {.importc: "EAI_BADFLAGS", header: "<netdb.h>".}: cint
+var EAI_FAIL* {.importc: "EAI_FAIL", header: "<netdb.h>".}: cint
+var EAI_FAMILY* {.importc: "EAI_FAMILY", header: "<netdb.h>".}: cint
+var EAI_MEMORY* {.importc: "EAI_MEMORY", header: "<netdb.h>".}: cint
+var EAI_NONAME* {.importc: "EAI_NONAME", header: "<netdb.h>".}: cint
+var EAI_SERVICE* {.importc: "EAI_SERVICE", header: "<netdb.h>".}: cint
+var EAI_SOCKTYPE* {.importc: "EAI_SOCKTYPE", header: "<netdb.h>".}: cint
+var EAI_SYSTEM* {.importc: "EAI_SYSTEM", header: "<netdb.h>".}: cint
+var EAI_OVERFLOW* {.importc: "EAI_OVERFLOW", header: "<netdb.h>".}: cint
+
+# <net/if.h>
+var IF_NAMESIZE* {.importc: "IF_NAMESIZE", header: "<net/if.h>".}: cint
+
+# <netinet/in.h>
+var IPPROTO_IP* {.importc: "IPPROTO_IP", header: "<netinet/in.h>".}: cint
+var IPPROTO_IPV6* {.importc: "IPPROTO_IPV6", header: "<netinet/in.h>".}: cint
+var IPPROTO_ICMP* {.importc: "IPPROTO_ICMP", header: "<netinet/in.h>".}: cint
+var IPPROTO_ICMPV6* {.importc: "IPPROTO_ICMPV6", header: "<netinet/in.h>".}: cint
+var IPPROTO_RAW* {.importc: "IPPROTO_RAW", header: "<netinet/in.h>".}: cint
+var IPPROTO_TCP* {.importc: "IPPROTO_TCP", header: "<netinet/in.h>".}: cint
+var IPPROTO_UDP* {.importc: "IPPROTO_UDP", header: "<netinet/in.h>".}: cint
+var INADDR_ANY* {.importc: "INADDR_ANY", header: "<netinet/in.h>".}: InAddrScalar
+var INADDR_LOOPBACK* {.importc: "INADDR_LOOPBACK", header: "<netinet/in.h>".}: InAddrScalar
+var INADDR_BROADCAST* {.importc: "INADDR_BROADCAST", header: "<netinet/in.h>".}: InAddrScalar
+var INET_ADDRSTRLEN* {.importc: "INET_ADDRSTRLEN", header: "<netinet/in.h>".}: cint
+var INET6_ADDRSTRLEN* {.importc: "INET6_ADDRSTRLEN", header: "<netinet/in.h>".}: cint
+var IPV6_JOIN_GROUP* {.importc: "IPV6_JOIN_GROUP", header: "<netinet/in.h>".}: cint
+var IPV6_LEAVE_GROUP* {.importc: "IPV6_LEAVE_GROUP", header: "<netinet/in.h>".}: cint
+var IPV6_MULTICAST_HOPS* {.importc: "IPV6_MULTICAST_HOPS", header: "<netinet/in.h>".}: cint
+var IPV6_MULTICAST_IF* {.importc: "IPV6_MULTICAST_IF", header: "<netinet/in.h>".}: cint
+var IPV6_MULTICAST_LOOP* {.importc: "IPV6_MULTICAST_LOOP", header: "<netinet/in.h>".}: cint
+var IPV6_UNICAST_HOPS* {.importc: "IPV6_UNICAST_HOPS", header: "<netinet/in.h>".}: cint
+var IPV6_V6ONLY* {.importc: "IPV6_V6ONLY", header: "<netinet/in.h>".}: cint
+
+# <netinet/tcp.h>
+var TCP_NODELAY* {.importc: "TCP_NODELAY", header: "<netinet/tcp.h>".}: cint
+
+# <nl_types.h>
+var NL_SETD* {.importc: "NL_SETD", header: "<nl_types.h>".}: cint
+var NL_CAT_LOCALE* {.importc: "NL_CAT_LOCALE", header: "<nl_types.h>".}: cint
+
+# <poll.h>
+var POLLIN* {.importc: "POLLIN", header: "<poll.h>".}: cshort
+var POLLRDNORM* {.importc: "POLLRDNORM", header: "<poll.h>".}: cshort
+var POLLRDBAND* {.importc: "POLLRDBAND", header: "<poll.h>".}: cshort
+var POLLPRI* {.importc: "POLLPRI", header: "<poll.h>".}: cshort
+var POLLOUT* {.importc: "POLLOUT", header: "<poll.h>".}: cshort
+var POLLWRNORM* {.importc: "POLLWRNORM", header: "<poll.h>".}: cshort
+var POLLWRBAND* {.importc: "POLLWRBAND", header: "<poll.h>".}: cshort
+var POLLERR* {.importc: "POLLERR", header: "<poll.h>".}: cshort
+var POLLHUP* {.importc: "POLLHUP", header: "<poll.h>".}: cshort
+var POLLNVAL* {.importc: "POLLNVAL", header: "<poll.h>".}: cshort
+
+# <pthread.h>
+var PTHREAD_BARRIER_SERIAL_THREAD* {.importc: "PTHREAD_BARRIER_SERIAL_THREAD", header: "<pthread.h>".}: cint
+var PTHREAD_CANCEL_ASYNCHRONOUS* {.importc: "PTHREAD_CANCEL_ASYNCHRONOUS", header: "<pthread.h>".}: cint
+var PTHREAD_CANCEL_ENABLE* {.importc: "PTHREAD_CANCEL_ENABLE", header: "<pthread.h>".}: cint
+var PTHREAD_CANCEL_DEFERRED* {.importc: "PTHREAD_CANCEL_DEFERRED", header: "<pthread.h>".}: cint
+var PTHREAD_CANCEL_DISABLE* {.importc: "PTHREAD_CANCEL_DISABLE", header: "<pthread.h>".}: cint
+var PTHREAD_CREATE_DETACHED* {.importc: "PTHREAD_CREATE_DETACHED", header: "<pthread.h>".}: cint
+var PTHREAD_CREATE_JOINABLE* {.importc: "PTHREAD_CREATE_JOINABLE", header: "<pthread.h>".}: cint
+var PTHREAD_EXPLICIT_SCHED* {.importc: "PTHREAD_EXPLICIT_SCHED", header: "<pthread.h>".}: cint
+var PTHREAD_INHERIT_SCHED* {.importc: "PTHREAD_INHERIT_SCHED", header: "<pthread.h>".}: cint
+var PTHREAD_MUTEX_DEFAULT* {.importc: "PTHREAD_MUTEX_DEFAULT", header: "<pthread.h>".}: cint
+var PTHREAD_MUTEX_ERRORCHECK* {.importc: "PTHREAD_MUTEX_ERRORCHECK", header: "<pthread.h>".}: cint
+var PTHREAD_MUTEX_NORMAL* {.importc: "PTHREAD_MUTEX_NORMAL", header: "<pthread.h>".}: cint
+var PTHREAD_MUTEX_RECURSIVE* {.importc: "PTHREAD_MUTEX_RECURSIVE", header: "<pthread.h>".}: cint
+var PTHREAD_PRIO_INHERIT* {.importc: "PTHREAD_PRIO_INHERIT", header: "<pthread.h>".}: cint
+var PTHREAD_PRIO_NONE* {.importc: "PTHREAD_PRIO_NONE", header: "<pthread.h>".}: cint
+var PTHREAD_PRIO_PROTECT* {.importc: "PTHREAD_PRIO_PROTECT", header: "<pthread.h>".}: cint
+var PTHREAD_PROCESS_SHARED* {.importc: "PTHREAD_PROCESS_SHARED", header: "<pthread.h>".}: cint
+var PTHREAD_PROCESS_PRIVATE* {.importc: "PTHREAD_PROCESS_PRIVATE", header: "<pthread.h>".}: cint
+var PTHREAD_SCOPE_PROCESS* {.importc: "PTHREAD_SCOPE_PROCESS", header: "<pthread.h>".}: cint
+var PTHREAD_SCOPE_SYSTEM* {.importc: "PTHREAD_SCOPE_SYSTEM", header: "<pthread.h>".}: cint
+
+# <sched.h>
+var SCHED_FIFO* {.importc: "SCHED_FIFO", header: "<sched.h>".}: cint
+var SCHED_RR* {.importc: "SCHED_RR", header: "<sched.h>".}: cint
+var SCHED_SPORADIC* {.importc: "SCHED_SPORADIC", header: "<sched.h>".}: cint
+var SCHED_OTHER* {.importc: "SCHED_OTHER", header: "<sched.h>".}: cint
+
+# <semaphore.h>
+var SEM_FAILED* {.importc: "SEM_FAILED", header: "<semaphore.h>".}: pointer
+
+# <signal.h>
+var SIGEV_NONE* {.importc: "SIGEV_NONE", header: "<signal.h>".}: cint
+var SIGEV_SIGNAL* {.importc: "SIGEV_SIGNAL", header: "<signal.h>".}: cint
+var SIGEV_THREAD* {.importc: "SIGEV_THREAD", header: "<signal.h>".}: cint
+var SIGABRT* {.importc: "SIGABRT", header: "<signal.h>".}: cint
+var SIGALRM* {.importc: "SIGALRM", header: "<signal.h>".}: cint
+var SIGBUS* {.importc: "SIGBUS", header: "<signal.h>".}: cint
+var SIGCHLD* {.importc: "SIGCHLD", header: "<signal.h>".}: cint
+var SIGCONT* {.importc: "SIGCONT", header: "<signal.h>".}: cint
+var SIGFPE* {.importc: "SIGFPE", header: "<signal.h>".}: cint
+var SIGHUP* {.importc: "SIGHUP", header: "<signal.h>".}: cint
+var SIGILL* {.importc: "SIGILL", header: "<signal.h>".}: cint
+var SIGINT* {.importc: "SIGINT", header: "<signal.h>".}: cint
+var SIGKILL* {.importc: "SIGKILL", header: "<signal.h>".}: cint
+var SIGPIPE* {.importc: "SIGPIPE", header: "<signal.h>".}: cint
+var SIGQUIT* {.importc: "SIGQUIT", header: "<signal.h>".}: cint
+var SIGSEGV* {.importc: "SIGSEGV", header: "<signal.h>".}: cint
+var SIGSTOP* {.importc: "SIGSTOP", header: "<signal.h>".}: cint
+var SIGTERM* {.importc: "SIGTERM", header: "<signal.h>".}: cint
+var SIGTSTP* {.importc: "SIGTSTP", header: "<signal.h>".}: cint
+var SIGTTIN* {.importc: "SIGTTIN", header: "<signal.h>".}: cint
+var SIGTTOU* {.importc: "SIGTTOU", header: "<signal.h>".}: cint
+var SIGUSR1* {.importc: "SIGUSR1", header: "<signal.h>".}: cint
+var SIGUSR2* {.importc: "SIGUSR2", header: "<signal.h>".}: cint
+var SIGPOLL* {.importc: "SIGPOLL", header: "<signal.h>".}: cint
+var SIGPROF* {.importc: "SIGPROF", header: "<signal.h>".}: cint
+var SIGSYS* {.importc: "SIGSYS", header: "<signal.h>".}: cint
+var SIGTRAP* {.importc: "SIGTRAP", header: "<signal.h>".}: cint
+var SIGURG* {.importc: "SIGURG", header: "<signal.h>".}: cint
+var SIGVTALRM* {.importc: "SIGVTALRM", header: "<signal.h>".}: cint
+var SIGXCPU* {.importc: "SIGXCPU", header: "<signal.h>".}: cint
+var SIGXFSZ* {.importc: "SIGXFSZ", header: "<signal.h>".}: cint
+var SA_NOCLDSTOP* {.importc: "SA_NOCLDSTOP", header: "<signal.h>".}: cint
+var SIG_BLOCK* {.importc: "SIG_BLOCK", header: "<signal.h>".}: cint
+var SIG_UNBLOCK* {.importc: "SIG_UNBLOCK", header: "<signal.h>".}: cint
+var SIG_SETMASK* {.importc: "SIG_SETMASK", header: "<signal.h>".}: cint
+var SA_ONSTACK* {.importc: "SA_ONSTACK", header: "<signal.h>".}: cint
+var SA_RESETHAND* {.importc: "SA_RESETHAND", header: "<signal.h>".}: cint
+var SA_RESTART* {.importc: "SA_RESTART", header: "<signal.h>".}: cint
+var SA_SIGINFO* {.importc: "SA_SIGINFO", header: "<signal.h>".}: cint
+var SA_NOCLDWAIT* {.importc: "SA_NOCLDWAIT", header: "<signal.h>".}: cint
+var SA_NODEFER* {.importc: "SA_NODEFER", header: "<signal.h>".}: cint
+var SS_ONSTACK* {.importc: "SS_ONSTACK", header: "<signal.h>".}: cint
+var SS_DISABLE* {.importc: "SS_DISABLE", header: "<signal.h>".}: cint
+var MINSIGSTKSZ* {.importc: "MINSIGSTKSZ", header: "<signal.h>".}: cint
+var SIGSTKSZ* {.importc: "SIGSTKSZ", header: "<signal.h>".}: cint
+var SIG_HOLD* {.importc: "SIG_HOLD", header: "<signal.h>".}: Sighandler
+var SIG_DFL* {.importc: "SIG_DFL", header: "<signal.h>".}: Sighandler
+var SIG_ERR* {.importc: "SIG_ERR", header: "<signal.h>".}: Sighandler
+var SIG_IGN* {.importc: "SIG_IGN", header: "<signal.h>".}: Sighandler
+
+# <sys/ipc.h>
+var IPC_CREAT* {.importc: "IPC_CREAT", header: "<sys/ipc.h>".}: cint
+var IPC_EXCL* {.importc: "IPC_EXCL", header: "<sys/ipc.h>".}: cint
+var IPC_NOWAIT* {.importc: "IPC_NOWAIT", header: "<sys/ipc.h>".}: cint
+var IPC_PRIVATE* {.importc: "IPC_PRIVATE", header: "<sys/ipc.h>".}: cint
+var IPC_RMID* {.importc: "IPC_RMID", header: "<sys/ipc.h>".}: cint
+var IPC_SET* {.importc: "IPC_SET", header: "<sys/ipc.h>".}: cint
+var IPC_STAT* {.importc: "IPC_STAT", header: "<sys/ipc.h>".}: cint
+
+# <sys/mman.h>
+var PROT_READ* {.importc: "PROT_READ", header: "<sys/mman.h>".}: cint
+var PROT_WRITE* {.importc: "PROT_WRITE", header: "<sys/mman.h>".}: cint
+var PROT_EXEC* {.importc: "PROT_EXEC", header: "<sys/mman.h>".}: cint
+var PROT_NONE* {.importc: "PROT_NONE", header: "<sys/mman.h>".}: cint
+var MAP_ANONYMOUS* {.importc: "MAP_ANONYMOUS", header: "<sys/mman.h>".}: cint
+var MAP_FIXED_NOREPLACE* {.importc: "MAP_FIXED_NOREPLACE", header: "<sys/mman.h>".}: cint
+var MAP_NORESERVE* {.importc: "MAP_NORESERVE", header: "<sys/mman.h>".}: cint
+var MAP_SHARED* {.importc: "MAP_SHARED", header: "<sys/mman.h>".}: cint
+var MAP_PRIVATE* {.importc: "MAP_PRIVATE", header: "<sys/mman.h>".}: cint
+var MAP_FIXED* {.importc: "MAP_FIXED", header: "<sys/mman.h>".}: cint
+var MS_ASYNC* {.importc: "MS_ASYNC", header: "<sys/mman.h>".}: cint
+var MS_SYNC* {.importc: "MS_SYNC", header: "<sys/mman.h>".}: cint
+var MS_INVALIDATE* {.importc: "MS_INVALIDATE", header: "<sys/mman.h>".}: cint
+var MCL_CURRENT* {.importc: "MCL_CURRENT", header: "<sys/mman.h>".}: cint
+var MCL_FUTURE* {.importc: "MCL_FUTURE", header: "<sys/mman.h>".}: cint
+var MAP_FAILED* {.importc: "MAP_FAILED", header: "<sys/mman.h>".}: pointer
+var POSIX_MADV_NORMAL* {.importc: "POSIX_MADV_NORMAL", header: "<sys/mman.h>".}: cint
+var POSIX_MADV_SEQUENTIAL* {.importc: "POSIX_MADV_SEQUENTIAL", header: "<sys/mman.h>".}: cint
+var POSIX_MADV_RANDOM* {.importc: "POSIX_MADV_RANDOM", header: "<sys/mman.h>".}: cint
+var POSIX_MADV_WILLNEED* {.importc: "POSIX_MADV_WILLNEED", header: "<sys/mman.h>".}: cint
+var POSIX_MADV_DONTNEED* {.importc: "POSIX_MADV_DONTNEED", header: "<sys/mman.h>".}: cint
+var POSIX_TYPED_MEM_ALLOCATE* {.importc: "POSIX_TYPED_MEM_ALLOCATE", header: "<sys/mman.h>".}: cint
+var POSIX_TYPED_MEM_ALLOCATE_CONTIG* {.importc: "POSIX_TYPED_MEM_ALLOCATE_CONTIG", header: "<sys/mman.h>".}: cint
+var POSIX_TYPED_MEM_MAP_ALLOCATABLE* {.importc: "POSIX_TYPED_MEM_MAP_ALLOCATABLE", header: "<sys/mman.h>".}: cint
+
+# <sys/resource.h>
+var RLIMIT_NOFILE* {.importc: "RLIMIT_NOFILE", header: "<sys/resource.h>".}: cint
+var RLIMIT_STACK* {.importc: "RLIMIT_STACK", header: "<sys/resource.h>".}: cint
+
+# <sys/select.h>
+var FD_SETSIZE* {.importc: "FD_SETSIZE", header: "<sys/select.h>".}: cint
+when defined(zephyr):
+  # Zephyr specific hardcoded value
+  var FD_MAX* {.importc: "CONFIG_POSIX_MAX_FDS ", header: "<sys/select.h>".}: cint
+
+# <sys/socket.h>
+var MSG_CTRUNC* {.importc: "MSG_CTRUNC", header: "<sys/socket.h>".}: cint
+var MSG_DONTROUTE* {.importc: "MSG_DONTROUTE", header: "<sys/socket.h>".}: cint
+var MSG_EOR* {.importc: "MSG_EOR", header: "<sys/socket.h>".}: cint
+var MSG_OOB* {.importc: "MSG_OOB", header: "<sys/socket.h>".}: cint
+var SCM_RIGHTS* {.importc: "SCM_RIGHTS", header: "<sys/socket.h>".}: cint
+var SO_ACCEPTCONN* {.importc: "SO_ACCEPTCONN", header: "<sys/socket.h>".}: cint
+var SO_BINDTODEVICE* {.importc: "SO_BINDTODEVICE", header: "<sys/socket.h>".}: cint
+var SO_BROADCAST* {.importc: "SO_BROADCAST", header: "<sys/socket.h>".}: cint
+var SO_DEBUG* {.importc: "SO_DEBUG", header: "<sys/socket.h>".}: cint
+var SO_DONTROUTE* {.importc: "SO_DONTROUTE", header: "<sys/socket.h>".}: cint
+var SO_ERROR* {.importc: "SO_ERROR", header: "<sys/socket.h>".}: cint
+var SO_KEEPALIVE* {.importc: "SO_KEEPALIVE", header: "<sys/socket.h>".}: cint
+var SO_LINGER* {.importc: "SO_LINGER", header: "<sys/socket.h>".}: cint
+var SO_OOBINLINE* {.importc: "SO_OOBINLINE", header: "<sys/socket.h>".}: cint
+var SO_RCVBUF* {.importc: "SO_RCVBUF", header: "<sys/socket.h>".}: cint
+var SO_RCVLOWAT* {.importc: "SO_RCVLOWAT", header: "<sys/socket.h>".}: cint
+var SO_RCVTIMEO* {.importc: "SO_RCVTIMEO", header: "<sys/socket.h>".}: cint
+var SO_REUSEADDR* {.importc: "SO_REUSEADDR", header: "<sys/socket.h>".}: cint
+var SO_SNDBUF* {.importc: "SO_SNDBUF", header: "<sys/socket.h>".}: cint
+var SO_SNDLOWAT* {.importc: "SO_SNDLOWAT", header: "<sys/socket.h>".}: cint
+var SO_SNDTIMEO* {.importc: "SO_SNDTIMEO", header: "<sys/socket.h>".}: cint
+var SO_TYPE* {.importc: "SO_TYPE", header: "<sys/socket.h>".}: cint
+var SOCK_DGRAM* {.importc: "SOCK_DGRAM", header: "<sys/socket.h>".}: cint
+var SOCK_RAW* {.importc: "SOCK_RAW", header: "<sys/socket.h>".}: cint
+when defined(zephyr):
+  const SOCK_SEQPACKET* = cint(5)
+  var SOMAXCONN* {.importc: "CONFIG_NET_SOCKETS_POLL_MAX", header: "<sys/socket.h>".}: cint
+else:
+  var SOCK_SEQPACKET* {.importc: "SOCK_SEQPACKET", header: "<sys/socket.h>".}: cint
+  var SOMAXCONN* {.importc: "SOMAXCONN", header: "<sys/socket.h>".}: cint
+
+var SOCK_STREAM* {.importc: "SOCK_STREAM", header: "<sys/socket.h>".}: cint
+var SOL_SOCKET* {.importc: "SOL_SOCKET", header: "<sys/socket.h>".}: cint
+var MSG_PEEK* {.importc: "MSG_PEEK", header: "<sys/socket.h>".}: cint
+var MSG_TRUNC* {.importc: "MSG_TRUNC", header: "<sys/socket.h>".}: cint
+var MSG_WAITALL* {.importc: "MSG_WAITALL", header: "<sys/socket.h>".}: cint
+var AF_INET* {.importc: "AF_INET", header: "<sys/socket.h>".}: cint
+var AF_INET6* {.importc: "AF_INET6", header: "<sys/socket.h>".}: cint
+var AF_UNIX* {.importc: "AF_UNIX", header: "<sys/socket.h>".}: cint
+var AF_UNSPEC* {.importc: "AF_UNSPEC", header: "<sys/socket.h>".}: cint
+var SHUT_RD* {.importc: "SHUT_RD", header: "<sys/socket.h>".}: cint
+var SHUT_RDWR* {.importc: "SHUT_RDWR", header: "<sys/socket.h>".}: cint
+var SHUT_WR* {.importc: "SHUT_WR", header: "<sys/socket.h>".}: cint
+
+# <sys/stat.h>
+var S_IFBLK* {.importc: "S_IFBLK", header: "<sys/stat.h>".}: cint
+var S_IFCHR* {.importc: "S_IFCHR", header: "<sys/stat.h>".}: cint
+var S_IFDIR* {.importc: "S_IFDIR", header: "<sys/stat.h>".}: cint
+var S_IFIFO* {.importc: "S_IFIFO", header: "<sys/stat.h>".}: cint
+var S_IFLNK* {.importc: "S_IFLNK", header: "<sys/stat.h>".}: cint
+var S_IFMT* {.importc: "S_IFMT", header: "<sys/stat.h>".}: cint
+var S_IFREG* {.importc: "S_IFREG", header: "<sys/stat.h>".}: cint
+var S_IFSOCK* {.importc: "S_IFSOCK", header: "<sys/stat.h>".}: cint
+var S_IRGRP* {.importc: "S_IRGRP", header: "<sys/stat.h>".}: cint
+var S_IROTH* {.importc: "S_IROTH", header: "<sys/stat.h>".}: cint
+var S_IRUSR* {.importc: "S_IRUSR", header: "<sys/stat.h>".}: cint
+var S_IRWXG* {.importc: "S_IRWXG", header: "<sys/stat.h>".}: cint
+var S_IRWXO* {.importc: "S_IRWXO", header: "<sys/stat.h>".}: cint
+var S_IRWXU* {.importc: "S_IRWXU", header: "<sys/stat.h>".}: cint
+var S_ISGID* {.importc: "S_ISGID", header: "<sys/stat.h>".}: cint
+var S_ISUID* {.importc: "S_ISUID", header: "<sys/stat.h>".}: cint
+var S_ISVTX* {.importc: "S_ISVTX", header: "<sys/stat.h>".}: cint
+var S_IWGRP* {.importc: "S_IWGRP", header: "<sys/stat.h>".}: cint
+var S_IWOTH* {.importc: "S_IWOTH", header: "<sys/stat.h>".}: cint
+var S_IWUSR* {.importc: "S_IWUSR", header: "<sys/stat.h>".}: cint
+var S_IXGRP* {.importc: "S_IXGRP", header: "<sys/stat.h>".}: cint
+var S_IXOTH* {.importc: "S_IXOTH", header: "<sys/stat.h>".}: cint
+var S_IXUSR* {.importc: "S_IXUSR", header: "<sys/stat.h>".}: cint
+
+# <sys/statvfs.h>
+var ST_RDONLY* {.importc: "ST_RDONLY", header: "<sys/statvfs.h>".}: cint
+var ST_NOSUID* {.importc: "ST_NOSUID", header: "<sys/statvfs.h>".}: cint
+
+# <sys/wait.h>
+var WNOHANG* {.importc: "WNOHANG", header: "<sys/wait.h>".}: cint
+var WUNTRACED* {.importc: "WUNTRACED", header: "<sys/wait.h>".}: cint
+var WEXITED* {.importc: "WEXITED", header: "<sys/wait.h>".}: cint
+var WSTOPPED* {.importc: "WSTOPPED", header: "<sys/wait.h>".}: cint
+var WCONTINUED* {.importc: "WCONTINUED", header: "<sys/wait.h>".}: cint
+var WNOWAIT* {.importc: "WNOWAIT", header: "<sys/wait.h>".}: cint
+var P_ALL* {.importc: "P_ALL", header: "<sys/wait.h>".}: cint
+var P_PID* {.importc: "P_PID", header: "<sys/wait.h>".}: cint
+var P_PGID* {.importc: "P_PGID", header: "<sys/wait.h>".}: cint
+
+# <spawn.h>
+var POSIX_SPAWN_RESETIDS* {.importc: "POSIX_SPAWN_RESETIDS", header: "<spawn.h>".}: cint
+var POSIX_SPAWN_SETPGROUP* {.importc: "POSIX_SPAWN_SETPGROUP", header: "<spawn.h>".}: cint
+var POSIX_SPAWN_SETSCHEDPARAM* {.importc: "POSIX_SPAWN_SETSCHEDPARAM", header: "<spawn.h>".}: cint
+var POSIX_SPAWN_SETSCHEDULER* {.importc: "POSIX_SPAWN_SETSCHEDULER", header: "<spawn.h>".}: cint
+var POSIX_SPAWN_SETSIGDEF* {.importc: "POSIX_SPAWN_SETSIGDEF", header: "<spawn.h>".}: cint
+var POSIX_SPAWN_SETSIGMASK* {.importc: "POSIX_SPAWN_SETSIGMASK", header: "<spawn.h>".}: cint
+
+# <stdio.h>
+var IOFBF* {.importc: "_IOFBF", header: "<stdio.h>".}: cint
+var IONBF* {.importc: "_IONBF", header: "<stdio.h>".}: cint
+
+# <time.h>
+var CLOCKS_PER_SEC* {.importc: "CLOCKS_PER_SEC", header: "<time.h>".}: clong
+var CLOCK_PROCESS_CPUTIME_ID* {.importc: "CLOCK_PROCESS_CPUTIME_ID", header: "<time.h>".}: cint
+var CLOCK_THREAD_CPUTIME_ID* {.importc: "CLOCK_THREAD_CPUTIME_ID", header: "<time.h>".}: cint
+var CLOCK_REALTIME* {.importc: "CLOCK_REALTIME", header: "<time.h>".}: cint
+var TIMER_ABSTIME* {.importc: "TIMER_ABSTIME", header: "<time.h>".}: cint
+var CLOCK_MONOTONIC* {.importc: "CLOCK_MONOTONIC", header: "<time.h>".}: cint
+
+# <unistd.h>
+var POSIX_ASYNC_IO* {.importc: "_POSIX_ASYNC_IO", header: "<unistd.h>".}: cint
+var POSIX_PRIO_IO* {.importc: "_POSIX_PRIO_IO", header: "<unistd.h>".}: cint
+var POSIX_SYNC_IO* {.importc: "_POSIX_SYNC_IO", header: "<unistd.h>".}: cint
+var F_OK* {.importc: "F_OK", header: "<unistd.h>".}: cint
+var R_OK* {.importc: "R_OK", header: "<unistd.h>".}: cint
+var W_OK* {.importc: "W_OK", header: "<unistd.h>".}: cint
+var X_OK* {.importc: "X_OK", header: "<unistd.h>".}: cint
+var CS_PATH* {.importc: "_CS_PATH", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_ILP32_OFF32_CFLAGS* {.importc: "_CS_POSIX_V6_ILP32_OFF32_CFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_ILP32_OFF32_LDFLAGS* {.importc: "_CS_POSIX_V6_ILP32_OFF32_LDFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_ILP32_OFF32_LIBS* {.importc: "_CS_POSIX_V6_ILP32_OFF32_LIBS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_ILP32_OFFBIG_CFLAGS* {.importc: "_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS* {.importc: "_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_ILP32_OFFBIG_LIBS* {.importc: "_CS_POSIX_V6_ILP32_OFFBIG_LIBS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_LP64_OFF64_CFLAGS* {.importc: "_CS_POSIX_V6_LP64_OFF64_CFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_LP64_OFF64_LDFLAGS* {.importc: "_CS_POSIX_V6_LP64_OFF64_LDFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_LP64_OFF64_LIBS* {.importc: "_CS_POSIX_V6_LP64_OFF64_LIBS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS* {.importc: "_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS* {.importc: "_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_LPBIG_OFFBIG_LIBS* {.importc: "_CS_POSIX_V6_LPBIG_OFFBIG_LIBS", header: "<unistd.h>".}: cint
+var CS_POSIX_V6_WIDTH_RESTRICTED_ENVS* {.importc: "_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS", header: "<unistd.h>".}: cint
+var F_LOCK* {.importc: "F_LOCK", header: "<unistd.h>".}: cint
+var F_TEST* {.importc: "F_TEST", header: "<unistd.h>".}: cint
+var F_TLOCK* {.importc: "F_TLOCK", header: "<unistd.h>".}: cint
+var F_ULOCK* {.importc: "F_ULOCK", header: "<unistd.h>".}: cint
+var PC_2_SYMLINKS* {.importc: "_PC_2_SYMLINKS", header: "<unistd.h>".}: cint
+var PC_ALLOC_SIZE_MIN* {.importc: "_PC_ALLOC_SIZE_MIN", header: "<unistd.h>".}: cint
+var PC_ASYNC_IO* {.importc: "_PC_ASYNC_IO", header: "<unistd.h>".}: cint
+var PC_CHOWN_RESTRICTED* {.importc: "_PC_CHOWN_RESTRICTED", header: "<unistd.h>".}: cint
+var PC_FILESIZEBITS* {.importc: "_PC_FILESIZEBITS", header: "<unistd.h>".}: cint
+var PC_LINK_MAX* {.importc: "_PC_LINK_MAX", header: "<unistd.h>".}: cint
+var PC_MAX_CANON* {.importc: "_PC_MAX_CANON", header: "<unistd.h>".}: cint
+var PC_MAX_INPUT* {.importc: "_PC_MAX_INPUT", header: "<unistd.h>".}: cint
+var PC_NAME_MAX* {.importc: "_PC_NAME_MAX", header: "<unistd.h>".}: cint
+var PC_NO_TRUNC* {.importc: "_PC_NO_TRUNC", header: "<unistd.h>".}: cint
+var PC_PATH_MAX* {.importc: "_PC_PATH_MAX", header: "<unistd.h>".}: cint
+var PC_PIPE_BUF* {.importc: "_PC_PIPE_BUF", header: "<unistd.h>".}: cint
+var PC_PRIO_IO* {.importc: "_PC_PRIO_IO", header: "<unistd.h>".}: cint
+var PC_REC_INCR_XFER_SIZE* {.importc: "_PC_REC_INCR_XFER_SIZE", header: "<unistd.h>".}: cint
+var PC_REC_MIN_XFER_SIZE* {.importc: "_PC_REC_MIN_XFER_SIZE", header: "<unistd.h>".}: cint
+var PC_REC_XFER_ALIGN* {.importc: "_PC_REC_XFER_ALIGN", header: "<unistd.h>".}: cint
+var PC_SYMLINK_MAX* {.importc: "_PC_SYMLINK_MAX", header: "<unistd.h>".}: cint
+var PC_SYNC_IO* {.importc: "_PC_SYNC_IO", header: "<unistd.h>".}: cint
+var PC_VDISABLE* {.importc: "_PC_VDISABLE", header: "<unistd.h>".}: cint
+var SC_2_C_BIND* {.importc: "_SC_2_C_BIND", header: "<unistd.h>".}: cint
+var SC_2_C_DEV* {.importc: "_SC_2_C_DEV", header: "<unistd.h>".}: cint
+var SC_2_CHAR_TERM* {.importc: "_SC_2_CHAR_TERM", header: "<unistd.h>".}: cint
+var SC_2_FORT_DEV* {.importc: "_SC_2_FORT_DEV", header: "<unistd.h>".}: cint
+var SC_2_FORT_RUN* {.importc: "_SC_2_FORT_RUN", header: "<unistd.h>".}: cint
+var SC_2_LOCALEDEF* {.importc: "_SC_2_LOCALEDEF", header: "<unistd.h>".}: cint
+var SC_2_PBS* {.importc: "_SC_2_PBS", header: "<unistd.h>".}: cint
+var SC_2_PBS_ACCOUNTING* {.importc: "_SC_2_PBS_ACCOUNTING", header: "<unistd.h>".}: cint
+var SC_2_PBS_CHECKPOINT* {.importc: "_SC_2_PBS_CHECKPOINT", header: "<unistd.h>".}: cint
+var SC_2_PBS_LOCATE* {.importc: "_SC_2_PBS_LOCATE", header: "<unistd.h>".}: cint
+var SC_2_PBS_MESSAGE* {.importc: "_SC_2_PBS_MESSAGE", header: "<unistd.h>".}: cint
+var SC_2_PBS_TRACK* {.importc: "_SC_2_PBS_TRACK", header: "<unistd.h>".}: cint
+var SC_2_SW_DEV* {.importc: "_SC_2_SW_DEV", header: "<unistd.h>".}: cint
+var SC_2_UPE* {.importc: "_SC_2_UPE", header: "<unistd.h>".}: cint
+var SC_2_VERSION* {.importc: "_SC_2_VERSION", header: "<unistd.h>".}: cint
+var SC_ADVISORY_INFO* {.importc: "_SC_ADVISORY_INFO", header: "<unistd.h>".}: cint
+var SC_AIO_LISTIO_MAX* {.importc: "_SC_AIO_LISTIO_MAX", header: "<unistd.h>".}: cint
+var SC_AIO_MAX* {.importc: "_SC_AIO_MAX", header: "<unistd.h>".}: cint
+var SC_AIO_PRIO_DELTA_MAX* {.importc: "_SC_AIO_PRIO_DELTA_MAX", header: "<unistd.h>".}: cint
+var SC_ARG_MAX* {.importc: "_SC_ARG_MAX", header: "<unistd.h>".}: cint
+var SC_ASYNCHRONOUS_IO* {.importc: "_SC_ASYNCHRONOUS_IO", header: "<unistd.h>".}: cint
+var SC_ATEXIT_MAX* {.importc: "_SC_ATEXIT_MAX", header: "<unistd.h>".}: cint
+var SC_BARRIERS* {.importc: "_SC_BARRIERS", header: "<unistd.h>".}: cint
+var SC_BC_BASE_MAX* {.importc: "_SC_BC_BASE_MAX", header: "<unistd.h>".}: cint
+var SC_BC_DIM_MAX* {.importc: "_SC_BC_DIM_MAX", header: "<unistd.h>".}: cint
+var SC_BC_SCALE_MAX* {.importc: "_SC_BC_SCALE_MAX", header: "<unistd.h>".}: cint
+var SC_BC_STRING_MAX* {.importc: "_SC_BC_STRING_MAX", header: "<unistd.h>".}: cint
+var SC_CHILD_MAX* {.importc: "_SC_CHILD_MAX", header: "<unistd.h>".}: cint
+var SC_CLK_TCK* {.importc: "_SC_CLK_TCK", header: "<unistd.h>".}: cint
+var SC_CLOCK_SELECTION* {.importc: "_SC_CLOCK_SELECTION", header: "<unistd.h>".}: cint
+var SC_COLL_WEIGHTS_MAX* {.importc: "_SC_COLL_WEIGHTS_MAX", header: "<unistd.h>".}: cint
+var SC_CPUTIME* {.importc: "_SC_CPUTIME", header: "<unistd.h>".}: cint
+var SC_DELAYTIMER_MAX* {.importc: "_SC_DELAYTIMER_MAX", header: "<unistd.h>".}: cint
+var SC_EXPR_NEST_MAX* {.importc: "_SC_EXPR_NEST_MAX", header: "<unistd.h>".}: cint
+var SC_FSYNC* {.importc: "_SC_FSYNC", header: "<unistd.h>".}: cint
+var SC_GETGR_R_SIZE_MAX* {.importc: "_SC_GETGR_R_SIZE_MAX", header: "<unistd.h>".}: cint
+var SC_GETPW_R_SIZE_MAX* {.importc: "_SC_GETPW_R_SIZE_MAX", header: "<unistd.h>".}: cint
+var SC_HOST_NAME_MAX* {.importc: "_SC_HOST_NAME_MAX", header: "<unistd.h>".}: cint
+var SC_IOV_MAX* {.importc: "_SC_IOV_MAX", header: "<unistd.h>".}: cint
+var SC_IPV6* {.importc: "_SC_IPV6", header: "<unistd.h>".}: cint
+var SC_JOB_CONTROL* {.importc: "_SC_JOB_CONTROL", header: "<unistd.h>".}: cint
+var SC_LINE_MAX* {.importc: "_SC_LINE_MAX", header: "<unistd.h>".}: cint
+var SC_LOGIN_NAME_MAX* {.importc: "_SC_LOGIN_NAME_MAX", header: "<unistd.h>".}: cint
+var SC_MAPPED_FILES* {.importc: "_SC_MAPPED_FILES", header: "<unistd.h>".}: cint
+var SC_MEMLOCK* {.importc: "_SC_MEMLOCK", header: "<unistd.h>".}: cint
+var SC_MEMLOCK_RANGE* {.importc: "_SC_MEMLOCK_RANGE", header: "<unistd.h>".}: cint
+var SC_MEMORY_PROTECTION* {.importc: "_SC_MEMORY_PROTECTION", header: "<unistd.h>".}: cint
+var SC_MESSAGE_PASSING* {.importc: "_SC_MESSAGE_PASSING", header: "<unistd.h>".}: cint
+var SC_MONOTONIC_CLOCK* {.importc: "_SC_MONOTONIC_CLOCK", header: "<unistd.h>".}: cint
+var SC_MQ_OPEN_MAX* {.importc: "_SC_MQ_OPEN_MAX", header: "<unistd.h>".}: cint
+var SC_MQ_PRIO_MAX* {.importc: "_SC_MQ_PRIO_MAX", header: "<unistd.h>".}: cint
+var SC_NGROUPS_MAX* {.importc: "_SC_NGROUPS_MAX", header: "<unistd.h>".}: cint
+var SC_OPEN_MAX* {.importc: "_SC_OPEN_MAX", header: "<unistd.h>".}: cint
+var SC_PAGESIZE* {.importc: "_SC_PAGESIZE", header: "<unistd.h>".}: cint
+var SC_PRIORITIZED_IO* {.importc: "_SC_PRIORITIZED_IO", header: "<unistd.h>".}: cint
+var SC_PRIORITY_SCHEDULING* {.importc: "_SC_PRIORITY_SCHEDULING", header: "<unistd.h>".}: cint
+var SC_RAW_SOCKETS* {.importc: "_SC_RAW_SOCKETS", header: "<unistd.h>".}: cint
+var SC_RE_DUP_MAX* {.importc: "_SC_RE_DUP_MAX", header: "<unistd.h>".}: cint
+var SC_READER_WRITER_LOCKS* {.importc: "_SC_READER_WRITER_LOCKS", header: "<unistd.h>".}: cint
+var SC_REALTIME_SIGNALS* {.importc: "_SC_REALTIME_SIGNALS", header: "<unistd.h>".}: cint
+var SC_REGEXP* {.importc: "_SC_REGEXP", header: "<unistd.h>".}: cint
+var SC_RTSIG_MAX* {.importc: "_SC_RTSIG_MAX", header: "<unistd.h>".}: cint
+var SC_SAVED_IDS* {.importc: "_SC_SAVED_IDS", header: "<unistd.h>".}: cint
+var SC_SEM_NSEMS_MAX* {.importc: "_SC_SEM_NSEMS_MAX", header: "<unistd.h>".}: cint
+var SC_SEM_VALUE_MAX* {.importc: "_SC_SEM_VALUE_MAX", header: "<unistd.h>".}: cint
+var SC_SEMAPHORES* {.importc: "_SC_SEMAPHORES", header: "<unistd.h>".}: cint
+var SC_SHARED_MEMORY_OBJECTS* {.importc: "_SC_SHARED_MEMORY_OBJECTS", header: "<unistd.h>".}: cint
+var SC_SHELL* {.importc: "_SC_SHELL", header: "<unistd.h>".}: cint
+var SC_SIGQUEUE_MAX* {.importc: "_SC_SIGQUEUE_MAX", header: "<unistd.h>".}: cint
+var SC_SPAWN* {.importc: "_SC_SPAWN", header: "<unistd.h>".}: cint
+var SC_SPIN_LOCKS* {.importc: "_SC_SPIN_LOCKS", header: "<unistd.h>".}: cint
+var SC_SPORADIC_SERVER* {.importc: "_SC_SPORADIC_SERVER", header: "<unistd.h>".}: cint
+var SC_SS_REPL_MAX* {.importc: "_SC_SS_REPL_MAX", header: "<unistd.h>".}: cint
+var SC_STREAM_MAX* {.importc: "_SC_STREAM_MAX", header: "<unistd.h>".}: cint
+var SC_SYMLOOP_MAX* {.importc: "_SC_SYMLOOP_MAX", header: "<unistd.h>".}: cint
+var SC_SYNCHRONIZED_IO* {.importc: "_SC_SYNCHRONIZED_IO", header: "<unistd.h>".}: cint
+var SC_THREAD_ATTR_STACKADDR* {.importc: "_SC_THREAD_ATTR_STACKADDR", header: "<unistd.h>".}: cint
+var SC_THREAD_ATTR_STACKSIZE* {.importc: "_SC_THREAD_ATTR_STACKSIZE", header: "<unistd.h>".}: cint
+var SC_THREAD_CPUTIME* {.importc: "_SC_THREAD_CPUTIME", header: "<unistd.h>".}: cint
+var SC_THREAD_DESTRUCTOR_ITERATIONS* {.importc: "_SC_THREAD_DESTRUCTOR_ITERATIONS", header: "<unistd.h>".}: cint
+var SC_THREAD_KEYS_MAX* {.importc: "_SC_THREAD_KEYS_MAX", header: "<unistd.h>".}: cint
+var SC_THREAD_PRIO_INHERIT* {.importc: "_SC_THREAD_PRIO_INHERIT", header: "<unistd.h>".}: cint
+var SC_THREAD_PRIO_PROTECT* {.importc: "_SC_THREAD_PRIO_PROTECT", header: "<unistd.h>".}: cint
+var SC_THREAD_PRIORITY_SCHEDULING* {.importc: "_SC_THREAD_PRIORITY_SCHEDULING", header: "<unistd.h>".}: cint
+var SC_THREAD_PROCESS_SHARED* {.importc: "_SC_THREAD_PROCESS_SHARED", header: "<unistd.h>".}: cint
+var SC_THREAD_SAFE_FUNCTIONS* {.importc: "_SC_THREAD_SAFE_FUNCTIONS", header: "<unistd.h>".}: cint
+var SC_THREAD_SPORADIC_SERVER* {.importc: "_SC_THREAD_SPORADIC_SERVER", header: "<unistd.h>".}: cint
+var SC_THREAD_STACK_MIN* {.importc: "_SC_THREAD_STACK_MIN", header: "<unistd.h>".}: cint
+var SC_THREAD_THREADS_MAX* {.importc: "_SC_THREAD_THREADS_MAX", header: "<unistd.h>".}: cint
+var SC_THREADS* {.importc: "_SC_THREADS", header: "<unistd.h>".}: cint
+var SC_TIMEOUTS* {.importc: "_SC_TIMEOUTS", header: "<unistd.h>".}: cint
+var SC_TIMER_MAX* {.importc: "_SC_TIMER_MAX", header: "<unistd.h>".}: cint
+var SC_TIMERS* {.importc: "_SC_TIMERS", header: "<unistd.h>".}: cint
+var SC_TRACE* {.importc: "_SC_TRACE", header: "<unistd.h>".}: cint
+var SC_TRACE_EVENT_FILTER* {.importc: "_SC_TRACE_EVENT_FILTER", header: "<unistd.h>".}: cint
+var SC_TRACE_EVENT_NAME_MAX* {.importc: "_SC_TRACE_EVENT_NAME_MAX", header: "<unistd.h>".}: cint
+var SC_TRACE_INHERIT* {.importc: "_SC_TRACE_INHERIT", header: "<unistd.h>".}: cint
+var SC_TRACE_LOG* {.importc: "_SC_TRACE_LOG", header: "<unistd.h>".}: cint
+var SC_TRACE_NAME_MAX* {.importc: "_SC_TRACE_NAME_MAX", header: "<unistd.h>".}: cint
+var SC_TRACE_SYS_MAX* {.importc: "_SC_TRACE_SYS_MAX", header: "<unistd.h>".}: cint
+var SC_TRACE_USER_EVENT_MAX* {.importc: "_SC_TRACE_USER_EVENT_MAX", header: "<unistd.h>".}: cint
+var SC_TTY_NAME_MAX* {.importc: "_SC_TTY_NAME_MAX", header: "<unistd.h>".}: cint
+var SC_TYPED_MEMORY_OBJECTS* {.importc: "_SC_TYPED_MEMORY_OBJECTS", header: "<unistd.h>".}: cint
+var SC_TZNAME_MAX* {.importc: "_SC_TZNAME_MAX", header: "<unistd.h>".}: cint
+var SC_V6_ILP32_OFF32* {.importc: "_SC_V6_ILP32_OFF32", header: "<unistd.h>".}: cint
+var SC_V6_ILP32_OFFBIG* {.importc: "_SC_V6_ILP32_OFFBIG", header: "<unistd.h>".}: cint
+var SC_V6_LP64_OFF64* {.importc: "_SC_V6_LP64_OFF64", header: "<unistd.h>".}: cint
+var SC_V6_LPBIG_OFFBIG* {.importc: "_SC_V6_LPBIG_OFFBIG", header: "<unistd.h>".}: cint
+var SC_VERSION* {.importc: "_SC_VERSION", header: "<unistd.h>".}: cint
+var SC_XBS5_ILP32_OFF32* {.importc: "_SC_XBS5_ILP32_OFF32", header: "<unistd.h>".}: cint
+var SC_XBS5_ILP32_OFFBIG* {.importc: "_SC_XBS5_ILP32_OFFBIG", header: "<unistd.h>".}: cint
+var SC_XBS5_LP64_OFF64* {.importc: "_SC_XBS5_LP64_OFF64", header: "<unistd.h>".}: cint
+var SC_XBS5_LPBIG_OFFBIG* {.importc: "_SC_XBS5_LPBIG_OFFBIG", header: "<unistd.h>".}: cint
+var SC_XOPEN_CRYPT* {.importc: "_SC_XOPEN_CRYPT", header: "<unistd.h>".}: cint
+var SC_XOPEN_ENH_I18N* {.importc: "_SC_XOPEN_ENH_I18N", header: "<unistd.h>".}: cint
+var SC_XOPEN_LEGACY* {.importc: "_SC_XOPEN_LEGACY", header: "<unistd.h>".}: cint
+var SC_XOPEN_REALTIME* {.importc: "_SC_XOPEN_REALTIME", header: "<unistd.h>".}: cint
+var SC_XOPEN_REALTIME_THREADS* {.importc: "_SC_XOPEN_REALTIME_THREADS", header: "<unistd.h>".}: cint
+var SC_XOPEN_SHM* {.importc: "_SC_XOPEN_SHM", header: "<unistd.h>".}: cint
+var SC_XOPEN_STREAMS* {.importc: "_SC_XOPEN_STREAMS", header: "<unistd.h>".}: cint
+var SC_XOPEN_UNIX* {.importc: "_SC_XOPEN_UNIX", header: "<unistd.h>".}: cint
+var SC_XOPEN_VERSION* {.importc: "_SC_XOPEN_VERSION", header: "<unistd.h>".}: cint
+var SC_NPROCESSORS_ONLN* {.importc: "_SC_NPROCESSORS_ONLN", header: "<unistd.h>".}: cint
+var SEEK_SET* {.importc: "SEEK_SET", header: "<unistd.h>".}: cint
+var SEEK_CUR* {.importc: "SEEK_CUR", header: "<unistd.h>".}: cint
+var SEEK_END* {.importc: "SEEK_END", header: "<unistd.h>".}: cint
+
+# <nuttx/config.h>
+when defined(nuttx):
+  var NEPOLL_MAX* {.importc: "CONFIG_FS_NEPOLL_DESCRIPTORS", header: "<nuttx/config.h>".}: cint
diff --git a/lib/posix/posix_utils.nim b/lib/posix/posix_utils.nim
new file mode 100644
index 000000000..0c668246f
--- /dev/null
+++ b/lib/posix/posix_utils.nim
@@ -0,0 +1,133 @@
+#
+#            Nim's Runtime Library
+#    (c) Copyright 2019 Federico Ceratto and other Nim contributors
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## A set of helpers for the POSIX module.
+## Raw interfaces are in the other ``posix*.nim`` files.
+
+# Where possible, contribute OS-independent procs in `os <os.html>`_ instead.
+
+import std/[posix, parsecfg, os]
+import std/private/since
+
+when defined(nimPreviewSlimSystem):
+  import std/syncio
+
+type Uname* = object
+  sysname*, nodename*, release*, version*, machine*: string
+
+template charArrayToString(input: typed): string =
+  $cast[cstring](addr input)
+
+proc uname*(): Uname =
+  ## Provides system information in a `Uname` struct with sysname, nodename,
+  ## release, version and machine attributes.
+
+  when defined(posix):
+    runnableExamples:
+      echo uname().nodename, uname().release, uname().version
+      doAssert uname().sysname.len != 0
+
+  var u: Utsname
+  if uname(u) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+  result.sysname = charArrayToString u.sysname
+  result.nodename = charArrayToString u.nodename
+  result.release = charArrayToString u.release
+  result.version = charArrayToString u.version
+  result.machine = charArrayToString u.machine
+
+proc fsync*(fd: int) =
+  ## synchronize a file's buffer cache to the storage device
+  if fsync(fd.cint) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc stat*(path: string): Stat =
+  ## Returns file status in a `Stat` structure
+  if stat(path.cstring, result) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc memoryLock*(a1: pointer, a2: int) =
+  ## Locks pages starting from a1 for a1 bytes and prevent them from being swapped.
+  if mlock(a1, a2) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc memoryLockAll*(flags: int) =
+  ## Locks all memory for the running process to prevent swapping.
+  ##
+  ## example:
+  ##   ```nim
+  ##   memoryLockAll(MCL_CURRENT or MCL_FUTURE)
+  ##   ```
+  if mlockall(flags.cint) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc memoryUnlock*(a1: pointer, a2: int) =
+  ## Unlock pages starting from a1 for a1 bytes and allow them to be swapped.
+  if munlock(a1, a2) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc memoryUnlockAll*() =
+  ## Unlocks all memory for the running process to allow swapping.
+  if munlockall() != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc sendSignal*(pid: Pid, signal: int) =
+  ## Sends a signal to a running process by calling `kill`.
+  ## Raise exception in case of failure e.g. process not running.
+  if kill(pid, signal.cint) != 0:
+    raiseOSError(OSErrorCode(errno))
+
+proc mkstemp*(prefix: string, suffix=""): (string, File) =
+  ## Creates a unique temporary file from a prefix string. A six-character string
+  ## will be added. If suffix is provided it will be added to the string
+  ## The file is created with perms 0600.
+  ## Returns the filename and a file opened in r/w mode.
+  var tmpl = cstring(prefix & "XXXXXX" & suffix)
+  let fd =
+    if len(suffix) == 0:
+      when declared(mkostemp):
+        mkostemp(tmpl, O_CLOEXEC)
+      else:
+        mkstemp(tmpl)
+    else:
+      when declared(mkostemps):
+        mkostemps(tmpl, cint(len(suffix)), O_CLOEXEC)
+      else:
+        mkstemps(tmpl, cint(len(suffix)))
+  var f: File
+  if open(f, fd, fmReadWrite):
+    return ($tmpl, f)
+  raiseOSError(OSErrorCode(errno))
+
+proc mkdtemp*(prefix: string): string =
+  ## Creates a unique temporary directory from a prefix string. Adds a six chars suffix.
+  ## The directory is created with permissions 0700. Returns the directory name.
+  var tmpl = cstring(prefix & "XXXXXX")
+  if mkdtemp(tmpl) == nil:
+    raiseOSError(OSErrorCode(errno))
+  return $tmpl
+
+proc osReleaseFile*(): Config {.since: (1, 5).} =
+  ## Gets system identification from `os-release` file and returns it as a `parsecfg.Config`.
+  ## You also need to import the `parsecfg` module to gain access to this object.
+  ## The `os-release` file is an official Freedesktop.org open standard.
+  ## Available in Linux and BSD distributions, except Android and Android-based Linux.
+  ## `os-release` file is not available on Windows and OS X by design.
+  ## * https://www.freedesktop.org/software/systemd/man/os-release.html
+  runnableExamples:
+    import std/parsecfg
+    when defined(linux):
+      let data = osReleaseFile()
+      echo "OS name: ", data.getSectionValue("", "NAME") ## the data is up to each distro.
+
+  # We do not use a {.strdefine.} because Standard says it *must* be that path.
+  for osReleaseFile in ["/etc/os-release", "/usr/lib/os-release"]:
+    if fileExists(osReleaseFile):
+      return loadConfig(osReleaseFile)
+  raise newException(IOError, "File not found: /etc/os-release, /usr/lib/os-release")
diff --git a/lib/posix/termios.nim b/lib/posix/termios.nim
new file mode 100644
index 000000000..7fb6bb81c
--- /dev/null
+++ b/lib/posix/termios.nim
@@ -0,0 +1,256 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2015 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+import std/posix
+
+type
+  Speed* = cuint
+  Cflag* = cuint
+
+const
+  NCCS* = when defined(macosx): 20 else: 32
+
+when defined(linux) and defined(amd64):
+  type
+    Termios* {.importc: "struct termios", header: "<termios.h>".} = object
+      c_iflag*: Cflag        # input mode flags
+      c_oflag*: Cflag        # output mode flags
+      c_cflag*: Cflag        # control mode flags
+      c_lflag*: Cflag        # local mode flags
+      c_line*: cuchar
+      c_cc*: array[NCCS, cuchar]  # control characters
+      c_ispeed*: Speed
+      c_ospeed*: Speed
+else:
+  type
+    Termios* {.importc: "struct termios", header: "<termios.h>".} = object
+      c_iflag*: Cflag        # input mode flags
+      c_oflag*: Cflag        # output mode flags
+      c_cflag*: Cflag        # control mode flags
+      c_lflag*: Cflag        # local mode flags
+      c_cc*: array[NCCS, cuchar]  # control characters
+
+# cc characters
+
+var
+  VINTR* {.importc, header: "<termios.h>".}: cint
+  VQUIT* {.importc, header: "<termios.h>".}: cint
+  VERASE* {.importc, header: "<termios.h>".}: cint
+  VKILL* {.importc, header: "<termios.h>".}: cint
+  VEOF* {.importc, header: "<termios.h>".}: cint
+  VTIME* {.importc, header: "<termios.h>".}: cint
+  VMIN* {.importc, header: "<termios.h>".}: cint
+  VSTART* {.importc, header: "<termios.h>".}: cint
+  VSTOP* {.importc, header: "<termios.h>".}: cint
+  VSUSP* {.importc, header: "<termios.h>".}: cint
+  VEOL* {.importc, header: "<termios.h>".}: cint
+
+# iflag bits
+
+var
+  IGNBRK* {.importc, header: "<termios.h>".}: Cflag
+  BRKINT* {.importc, header: "<termios.h>".}: Cflag
+  IGNPAR* {.importc, header: "<termios.h>".}: Cflag
+  PARMRK* {.importc, header: "<termios.h>".}: Cflag
+  INPCK* {.importc, header: "<termios.h>".}: Cflag
+  ISTRIP* {.importc, header: "<termios.h>".}: Cflag
+  INLCR* {.importc, header: "<termios.h>".}: Cflag
+  IGNCR* {.importc, header: "<termios.h>".}: Cflag
+  ICRNL* {.importc, header: "<termios.h>".}: Cflag
+  IUCLC* {.importc, header: "<termios.h>".}: Cflag
+  IXON* {.importc, header: "<termios.h>".}: Cflag
+  IXANY* {.importc, header: "<termios.h>".}: Cflag
+  IXOFF* {.importc, header: "<termios.h>".}: Cflag
+
+# oflag bits
+
+var
+  OPOST* {.importc, header: "<termios.h>".}: Cflag
+  ONLCR* {.importc, header: "<termios.h>".}: Cflag
+  OCRNL* {.importc, header: "<termios.h>".}: Cflag
+  ONOCR* {.importc, header: "<termios.h>".}: Cflag
+  ONLRET* {.importc, header: "<termios.h>".}: Cflag
+  OFILL* {.importc, header: "<termios.h>".}: Cflag
+  OFDEL* {.importc, header: "<termios.h>".}: Cflag
+  NLDLY* {.importc, header: "<termios.h>".}: Cflag
+  NL0* {.importc, header: "<termios.h>".}: Cflag
+  NL1* {.importc, header: "<termios.h>".}: Cflag
+  CRDLY* {.importc, header: "<termios.h>".}: Cflag
+  CR0* {.importc, header: "<termios.h>".}: Cflag
+  CR1* {.importc, header: "<termios.h>".}: Cflag
+  CR2* {.importc, header: "<termios.h>".}: Cflag
+  CR3* {.importc, header: "<termios.h>".}: Cflag
+  TABDLY* {.importc, header: "<termios.h>".}: Cflag
+  TAB0* {.importc, header: "<termios.h>".}: Cflag
+  TAB1* {.importc, header: "<termios.h>".}: Cflag
+  TAB2* {.importc, header: "<termios.h>".}: Cflag
+  TAB3* {.importc, header: "<termios.h>".}: Cflag
+  BSDLY* {.importc, header: "<termios.h>".}: Cflag
+  BS0* {.importc, header: "<termios.h>".}: Cflag
+  BS1* {.importc, header: "<termios.h>".}: Cflag
+  FFDLY* {.importc, header: "<termios.h>".}: Cflag
+  FF0* {.importc, header: "<termios.h>".}: Cflag
+  FF1* {.importc, header: "<termios.h>".}: Cflag
+  VTDLY* {.importc, header: "<termios.h>".}: Cflag
+  VT0* {.importc, header: "<termios.h>".}: Cflag
+  VT1* {.importc, header: "<termios.h>".}: Cflag
+
+# cflag bit meaning
+
+var
+  B0* {.importc, header: "<termios.h>".}: Speed
+  B50* {.importc, header: "<termios.h>".}: Speed
+  B75* {.importc, header: "<termios.h>".}: Speed
+  B110* {.importc, header: "<termios.h>".}: Speed
+  B134* {.importc, header: "<termios.h>".}: Speed
+  B150* {.importc, header: "<termios.h>".}: Speed
+  B200* {.importc, header: "<termios.h>".}: Speed
+  B300* {.importc, header: "<termios.h>".}: Speed
+  B600* {.importc, header: "<termios.h>".}: Speed
+  B1200* {.importc, header: "<termios.h>".}: Speed
+  B1800* {.importc, header: "<termios.h>".}: Speed
+  B2400* {.importc, header: "<termios.h>".}: Speed
+  B4800* {.importc, header: "<termios.h>".}: Speed
+  B9600* {.importc, header: "<termios.h>".}: Speed
+  B19200* {.importc, header: "<termios.h>".}: Speed
+  B38400* {.importc, header: "<termios.h>".}: Speed
+  B57600* {.importc, header: "<termios.h>".}: Speed
+  B115200* {.importc, header: "<termios.h>".}: Speed
+  B230400* {.importc, header: "<termios.h>".}: Speed
+  B460800* {.importc, header: "<termios.h>".}: Speed
+  B500000* {.importc, header: "<termios.h>".}: Speed
+  B576000* {.importc, header: "<termios.h>".}: Speed
+  B921600* {.importc, header: "<termios.h>".}: Speed
+  B1000000* {.importc, header: "<termios.h>".}: Speed
+  B1152000* {.importc, header: "<termios.h>".}: Speed
+  B1500000* {.importc, header: "<termios.h>".}: Speed
+  B2000000* {.importc, header: "<termios.h>".}: Speed
+  B2500000* {.importc, header: "<termios.h>".}: Speed
+  B3000000* {.importc, header: "<termios.h>".}: Speed
+  B3500000* {.importc, header: "<termios.h>".}: Speed
+  B4000000* {.importc, header: "<termios.h>".}: Speed
+  EXTA* {.importc, header: "<termios.h>".}: Speed
+  EXTB* {.importc, header: "<termios.h>".}: Speed
+  CSIZE* {.importc, header: "<termios.h>".}: Cflag
+  CS5* {.importc, header: "<termios.h>".}: Cflag
+  CS6* {.importc, header: "<termios.h>".}: Cflag
+  CS7* {.importc, header: "<termios.h>".}: Cflag
+  CS8* {.importc, header: "<termios.h>".}: Cflag
+  CSTOPB* {.importc, header: "<termios.h>".}: Cflag
+  CREAD* {.importc, header: "<termios.h>".}: Cflag
+  PARENB* {.importc, header: "<termios.h>".}: Cflag
+  PARODD* {.importc, header: "<termios.h>".}: Cflag
+  HUPCL* {.importc, header: "<termios.h>".}: Cflag
+  CLOCAL* {.importc, header: "<termios.h>".}: Cflag
+
+# lflag bits
+
+var
+  ISIG* {.importc, header: "<termios.h>".}: Cflag
+  ICANON* {.importc, header: "<termios.h>".}: Cflag
+  ECHO* {.importc, header: "<termios.h>".}: Cflag
+  ECHOE* {.importc, header: "<termios.h>".}: Cflag
+  ECHOK* {.importc, header: "<termios.h>".}: Cflag
+  ECHONL* {.importc, header: "<termios.h>".}: Cflag
+  NOFLSH* {.importc, header: "<termios.h>".}: Cflag
+  TOSTOP* {.importc, header: "<termios.h>".}: Cflag
+  IEXTEN* {.importc, header: "<termios.h>".}: Cflag
+
+# tcflow() and TCXONC use these
+
+var
+  TCOOFF* {.importc, header: "<termios.h>".}: cint
+  TCOON* {.importc, header: "<termios.h>".}: cint
+  TCIOFF* {.importc, header: "<termios.h>".}: cint
+  TCION* {.importc, header: "<termios.h>".}: cint
+
+# tcflush() and TCFLSH use these
+
+var
+  TCIFLUSH* {.importc, header: "<termios.h>".}: cint
+  TCOFLUSH* {.importc, header: "<termios.h>".}: cint
+  TCIOFLUSH* {.importc, header: "<termios.h>".}: cint
+
+# tcsetattr uses these
+
+var
+  TCSANOW* {.importc, header: "<termios.h>".}: cint
+  TCSADRAIN* {.importc, header: "<termios.h>".}: cint
+  TCSAFLUSH* {.importc, header: "<termios.h>".}: cint
+
+# Compare a character C to a value VAL from the `cc' array in a
+#   `struct termios'.  If VAL is _POSIX_VDISABLE, no character can match it.
+
+template cceq*(val, c): untyped =
+  c == val and val != POSIX_VDISABLE
+
+# Return the output baud rate stored in *TERMIOS_P.
+
+proc cfGetOspeed*(termios: ptr Termios): Speed {.importc: "cfgetospeed",
+    header: "<termios.h>".}
+# Return the input baud rate stored in *TERMIOS_P.
+
+proc cfGetIspeed*(termios: ptr Termios): Speed {.importc: "cfgetispeed",
+    header: "<termios.h>".}
+# Set the output baud rate stored in *TERMIOS_P to SPEED.
+
+proc cfSetOspeed*(termios: ptr Termios; speed: Speed): cint {.
+    importc: "cfsetospeed", header: "<termios.h>".}
+# Set the input baud rate stored in *TERMIOS_P to SPEED.
+
+proc cfSetIspeed*(termios: ptr Termios; speed: Speed): cint {.
+    importc: "cfsetispeed", header: "<termios.h>".}
+# Set both the input and output baud rates in *TERMIOS_OP to SPEED.
+
+proc tcGetAttr*(fd: cint; termios: ptr Termios): cint {.
+    importc: "tcgetattr", header: "<termios.h>".}
+# Set the state of FD to *TERMIOS_P.
+#   Values for OPTIONAL_ACTIONS (TCSA*) are in <bits/termios.h>.
+
+proc tcSetAttr*(fd: cint; optional_actions: cint; termios: ptr Termios): cint {.
+    importc: "tcsetattr", header: "<termios.h>".}
+# Set *TERMIOS_P to indicate raw mode.
+
+proc tcSendBreak*(fd: cint; duration: cint): cint {.importc: "tcsendbreak",
+    header: "<termios.h>".}
+# Wait for pending output to be written on FD.
+#
+#   This function is a cancellation point and therefore not marked with
+#  .
+
+proc tcDrain*(fd: cint): cint {.importc: "tcdrain", header: "<termios.h>".}
+# Flush pending data on FD.
+#   Values for QUEUE_SELECTOR (TC{I,O,IO}FLUSH) are in <bits/termios.h>.
+
+proc tcFlush*(fd: cint; queue_selector: cint): cint {.importc: "tcflush",
+    header: "<termios.h>".}
+# Suspend or restart transmission on FD.
+#   Values for ACTION (TC[IO]{OFF,ON}) are in <bits/termios.h>.
+
+proc tcFlow*(fd: cint; action: cint): cint {.importc: "tcflow",
+    header: "<termios.h>".}
+# Get process group ID for session leader for controlling terminal FD.
+
+# Window size ioctl.  Solaris based systems have an uncommen place for this.
+when defined(solaris) or defined(sunos):
+  var TIOCGWINSZ*{.importc, header: "<sys/termios.h>".}: culong
+else:
+  var TIOCGWINSZ*{.importc, header: "<sys/ioctl.h>".}: culong
+
+when defined(nimHasStyleChecks):
+  {.push styleChecks: off.}
+
+type IOctl_WinSize* = object
+  ws_row*, ws_col*, ws_xpixel*, ws_ypixel*: cushort
+
+when defined(nimHasStyleChecks):
+  {.pop.}
+
+proc ioctl*(fd: cint, request: culong, reply: ptr IOctl_WinSize): int {.
+  importc: "ioctl", header: "<stdio.h>", varargs.}