Skip to content

Commit

Permalink
Linux updates (#14170)
Browse files Browse the repository at this point in the history
* Add posix_memalign()

* Add linux-specific open() flags

O_TMPFILE: since Linux 3.11
O_PATH: since Linux 2.6.39
O_NOATIME: since Linux 2.6.8
O_DIRECT: since Linux 2.4.10

* Fix Stat type

* Fix POSIX AF_INET* const generation
  • Loading branch information
wltsmrz authored May 4, 2020
1 parent 44f377f commit c817e85
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 2 additions & 0 deletions lib/posix/posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ proc mkdtemp*(tmpl: cstring): pointer {.importc, header: "<stdlib.h>", sideEffec
when defined(linux) or defined(bsd):
proc mkostemp*(tmpl: cstring, 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.
Expand Down
9 changes: 1 addition & 8 deletions lib/posix/posix_linux_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ type
type
SocketHandle* = distinct cint # The type used to represent socket descriptors

# not detected by detect.nim, guarded by #ifdef __USE_UNIX98 in glibc
const SIG_HOLD* = cast[Sighandler](2)

type
Time* {.importc: "time_t", header: "<time.h>".} = distinct clong

Expand Down Expand Up @@ -228,7 +225,7 @@ type
st_mode*: Mode ## Mode of file (see below).
st_uid*: Uid ## User ID of file.
st_gid*: Gid ## Group ID of file.
pad0: cint
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
Expand All @@ -244,8 +241,6 @@ type
st_atim*: Timespec ## Time of last access.
st_mtim*: Timespec ## Time of last data modification.
st_ctim*: Timespec ## Time of last status change.
reserved: array[3, clong]


Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
final, pure.} = object ## struct statvfs
Expand Down Expand Up @@ -573,8 +568,6 @@ var
# Regenerate using detect.nim!
include posix_linux_amd64_consts

const POSIX_SPAWN_USEVFORK* = cint(0x40) # needs _GNU_SOURCE!

# <sys/wait.h>
proc WEXITSTATUS*(s: cint): cint = (s and 0xff00) shr 8
proc WTERMSIG*(s:cint): cint = s and 0x7f
Expand Down
15 changes: 14 additions & 1 deletion lib/posix/posix_linux_amd64_consts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ 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)
Expand Down Expand Up @@ -174,13 +178,20 @@ 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)
Expand Down Expand Up @@ -402,6 +413,7 @@ 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)
Expand Down Expand Up @@ -473,7 +485,7 @@ const SOCK_SEQPACKET* = cint(5)
const SOCK_STREAM* = cint(1)
const SOCK_CLOEXEC* = cint(524288)
const SOL_SOCKET* = cint(1)
const SOMAXCONN* = cint(128)
const SOMAXCONN* = cint(4096)
const SO_REUSEPORT* = cint(15)
const MSG_NOSIGNAL* = cint(16384)
const MSG_PEEK* = cint(2)
Expand Down Expand Up @@ -531,6 +543,7 @@ 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)
Expand Down
21 changes: 16 additions & 5 deletions tools/detect/detect.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const

cfile = """
/* Generated by detect.nim */
#define _GNU_SOURCE
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -119,10 +121,14 @@ proc v(name: string, typ = "cint", no_other = false) =
addf(tl,
"#ifdef $3\n fprintf(f, \"const $1* = $2(%ld)\\n\", $3);\n#endif\n",
n, t, name)
of "cint", "cshort", "InAddrScalar", "TSa_Family":
of "cint", "cshort", "TSa_Family":
addf(tl,
"#ifdef $3\n fprintf(f, \"const $1* = $2(%d)\\n\", $3);\n#endif\n",
n, t, name)
of "InAddrScalar":
addf(tl,
"#ifdef $3\n fprintf(f, \"const $1* = $2(%u)\\n\", $3);\n#endif\n",
n, t, name)
else:
addf(tl,
"#ifdef $3\n fprintf(f, \"const $1* = cast[$2](%d)\\n\", $3);\n#endif\n",
Expand Down Expand Up @@ -256,6 +262,10 @@ v("O_RDONLY")
v("O_RDWR")
v("O_WRONLY")
v("O_CLOEXEC")
v("O_DIRECT")
v("O_PATH")
v("O_NOATIME")
v("O_TMPFILE")
v("POSIX_FADV_NORMAL")
v("POSIX_FADV_SEQUENTIAL")
v("POSIX_FADV_RANDOM")
Expand Down Expand Up @@ -433,6 +443,7 @@ header("<netinet/in.h>")
v("IPPROTO_IP")
v("IPPROTO_IPV6")
v("IPPROTO_ICMP")
v("IPPROTO_ICMPV6")
v("IPPROTO_RAW")
v("IPPROTO_TCP")
v("IPPROTO_UDP")
Expand Down Expand Up @@ -631,10 +642,10 @@ v("MSG_NOSIGNAL", no_other = true)
v("MSG_PEEK")
v("MSG_TRUNC")
v("MSG_WAITALL")
v("AF_INET", "TSa_Family")
v("AF_INET6", "TSa_Family")
v("AF_UNIX", "TSa_Family")
v("AF_UNSPEC", "TSa_Family")
v("AF_INET")
v("AF_INET6")
v("AF_UNIX")
v("AF_UNSPEC")
v("SHUT_RD")
v("SHUT_RDWR")
v("SHUT_WR")
Expand Down

0 comments on commit c817e85

Please sign in to comment.