From 3db7539e3dff2424a22c230180731b86e890f4d7 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 5 May 2020 02:00:38 -0700 Subject: [PATCH] fixup --- lib/posix/posix.nim | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 34ece8b1ba22a..5ecec94d5956b 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -97,10 +97,20 @@ const StatHasNanoseconds* = defined(linux) or defined(freebsd) or # Platform common stuff (avoids repetition) -type - # DIR* {.importc: "DIR*", header: "".} = ptr object - DIR* {.importc: "DIR12", header: "".} = ptr object - ## A type representing a directory stream. +when defined(nimBackendHasPosixDIR): + # This should be auto-detected, like NIM_EmulateOverflowChecks, by + # calling preprocessor, see https://github.com/nim-lang/RFCs/issues/205 + # proposal 5. + type + DIR* {.importc: "DIR", header: "".} = object + ## on some systems, this is a forward declared type and should only + ## be used via pointer, ie via `C_DIR` + C_DIR* = ptr DIR + ## A ptr type representing a directory stream. +else: + type + C_DIR* {.importc: "DIR*", header: "".} = ptr object + ## A ptr type representing a directory stream. # Platform specific stuff @@ -173,14 +183,14 @@ proc IN6ADDR_ANY_INIT* (): In6Addr {.importc, header: "".} proc IN6ADDR_LOOPBACK_INIT* (): In6Addr {.importc, header: "".} # dirent.h -proc closedir*(a1: DIR): cint {.importc, header: "".} -proc opendir*(a1: cstring): DIR {.importc, header: "", sideEffect.} -proc readdir*(a1: DIR): ptr Dirent {.importc, header: "", sideEffect.} -proc readdir_r*(a1: DIR, a2: ptr Dirent, a3: ptr ptr Dirent): cint {. +proc closedir*(a1: C_DIR): cint {.importc, header: "".} +proc opendir*(a1: cstring): C_DIR {.importc, header: "", sideEffect.} +proc readdir*(a1: C_DIR): ptr Dirent {.importc, header: "", sideEffect.} +proc readdir_r*(a1: C_DIR, a2: ptr Dirent, a3: ptr ptr Dirent): cint {. importc, header: "", sideEffect.} -proc rewinddir*(a1: DIR) {.importc, header: "".} -proc seekdir*(a1: DIR, a2: int) {.importc, header: "".} -proc telldir*(a1: DIR): int {.importc, header: "".} +proc rewinddir*(a1: C_DIR) {.importc, header: "".} +proc seekdir*(a1: C_DIR, a2: int) {.importc, header: "".} +proc telldir*(a1: C_DIR): int {.importc, header: "".} # dlfcn.h proc dlclose*(a1: pointer): cint {.importc, header: "", sideEffect.}