Merge pull request #3947 from def-/iofbf
Support IOFBF and IONBF on all systems
This commit is contained in:
commit
a1a44c99de
3 changed files with 14 additions and 21 deletions
|
|
@ -47,8 +47,9 @@ const
|
||||||
EV_ERROR* = 0x4000 ## Error, data contains errno
|
EV_ERROR* = 0x4000 ## Error, data contains errno
|
||||||
|
|
||||||
type
|
type
|
||||||
KEvent* {.importc: "struct kevent",
|
KEvent* {.importc: "struct kevent", pure, final
|
||||||
header: "<sys/event.h>", pure, final.} = object
|
header: """#include <sys/types.h>
|
||||||
|
#include <sys/event.h>""".} = object
|
||||||
ident*: cuint ## identifier for this event (uintptr_t)
|
ident*: cuint ## identifier for this event (uintptr_t)
|
||||||
filter*: cshort ## filter for event
|
filter*: cshort ## filter for event
|
||||||
flags*: cushort ## general flags
|
flags*: cushort ## general flags
|
||||||
|
|
|
||||||
|
|
@ -1350,15 +1350,12 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||||
## Returns the filename of the application's executable.
|
## Returns the filename of the application's executable.
|
||||||
##
|
##
|
||||||
## This procedure will resolve symlinks.
|
## This procedure will resolve symlinks.
|
||||||
##
|
|
||||||
## **Note**: This does not work reliably on BSD.
|
|
||||||
|
|
||||||
# Linux: /proc/<pid>/exe
|
# Linux: /proc/<pid>/exe
|
||||||
# Solaris:
|
# Solaris:
|
||||||
# /proc/<pid>/object/a.out (filename only)
|
# /proc/<pid>/object/a.out (filename only)
|
||||||
# /proc/<pid>/path/a.out (complete pathname)
|
# /proc/<pid>/path/a.out (complete pathname)
|
||||||
# *BSD (and maybe Darwin too):
|
# FreeBSD: /proc/<pid>/file
|
||||||
# /proc/<pid>/file
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
var buf = newWideCString("", 256)
|
var buf = newWideCString("", 256)
|
||||||
|
|
@ -1368,15 +1365,6 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||||
result = newString(256)
|
result = newString(256)
|
||||||
var len = getModuleFileNameA(0, result, 256)
|
var len = getModuleFileNameA(0, result, 256)
|
||||||
setlen(result, int(len))
|
setlen(result, int(len))
|
||||||
elif defined(linux) or defined(aix):
|
|
||||||
result = getApplAux("/proc/self/exe")
|
|
||||||
if result.len == 0: result = getApplHeuristic()
|
|
||||||
elif defined(solaris):
|
|
||||||
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
|
|
||||||
if result.len == 0: result = getApplHeuristic()
|
|
||||||
elif defined(freebsd):
|
|
||||||
result = getApplAux("/proc/" & $getpid() & "/file")
|
|
||||||
if result.len == 0: result = getApplHeuristic()
|
|
||||||
elif defined(macosx):
|
elif defined(macosx):
|
||||||
var size: cuint32
|
var size: cuint32
|
||||||
getExecPath1(nil, size)
|
getExecPath1(nil, size)
|
||||||
|
|
@ -1386,9 +1374,15 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||||
if result.len > 0:
|
if result.len > 0:
|
||||||
result = result.expandFilename
|
result = result.expandFilename
|
||||||
else:
|
else:
|
||||||
|
when defined(linux) or defined(aix) or defined(netbsd):
|
||||||
|
result = getApplAux("/proc/self/exe")
|
||||||
|
elif defined(solaris):
|
||||||
|
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
|
||||||
|
elif defined(freebsd):
|
||||||
|
result = getApplAux("/proc/" & $getpid() & "/file")
|
||||||
# little heuristic that may work on other POSIX-like systems:
|
# little heuristic that may work on other POSIX-like systems:
|
||||||
result = string(getEnv("_"))
|
if result.len == 0:
|
||||||
if result.len == 0: result = getApplHeuristic()
|
result = getApplHeuristic()
|
||||||
|
|
||||||
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||||
## Returns the filename of the application's executable.
|
## Returns the filename of the application's executable.
|
||||||
|
|
@ -1404,7 +1398,6 @@ proc getApplicationDir*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||||
|
|
||||||
proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||||
## Returns the directory of the application's executable.
|
## Returns the directory of the application's executable.
|
||||||
## **Note**: This does not work reliably on BSD.
|
|
||||||
result = splitFile(getAppFilename()).dir
|
result = splitFile(getAppFilename()).dir
|
||||||
|
|
||||||
proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [TimeEffect].} =
|
proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [TimeEffect].} =
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,11 @@ when NoFakeVars:
|
||||||
const
|
const
|
||||||
IOFBF = cint(0)
|
IOFBF = cint(0)
|
||||||
IONBF = cint(4)
|
IONBF = cint(4)
|
||||||
elif defined(macosx) or defined(linux):
|
else:
|
||||||
|
# On all systems I could find, including Linux, Mac OS X, and the BSDs
|
||||||
const
|
const
|
||||||
IOFBF = cint(0)
|
IOFBF = cint(0)
|
||||||
IONBF = cint(2)
|
IONBF = cint(2)
|
||||||
else:
|
|
||||||
{.error: "IOFBF not ported to your platform".}
|
|
||||||
else:
|
else:
|
||||||
var
|
var
|
||||||
IOFBF {.importc: "_IOFBF", nodecl.}: cint
|
IOFBF {.importc: "_IOFBF", nodecl.}: cint
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue