Open Clonkk opened 3 years ago
doAssert(res) # res == -1
=> you mean res == false
can you check whether it returns false directly here:
when not defined(nimInheritHandles) and declared(setInheritable):
let oshandle = when defined(windows): FileHandle getOsfhandle(filehandle) else: filehandle
if not setInheritable(oshandle, false):
return false
f = c_fdopen(filehandle, FormatOpen[mode])
if this fails, you need to check errno (and strerror) => what are the values here?
Modified tests to include errno :
var errno {.importc, header: "<errno.h>".}: cint ## error variable
proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
proc proc0()=
let file1 = open("dummy.txt", mode=fmWrite)
let dupfile1fd = duplicate(file1.getFileHandle())
var f : File
doAssert(isNil(f))
let res = open(f, dupfile1fd, mode=fmWrite)
let msg = "errno: " & $errno & " `" & $strerror(errno) & "`"
doAssert(not isNil(f))
doAssert(res)
write(f, msg)
close(f)
proc0()
Output
errno: 22 `Invalid argument
.
I tried using getOsFileHandle
instead of getFileHandle
as well
let dupfile1fd = duplicate(file1.getOsFileHandle())
Output:
Error: unhandled exception: Bad file descriptor [IOError]
Since ioutils
have moved to fusion
, could the examples posted be changed? Or transfer this issue to fusion repo.
Opening a File from a FileHandle using
does not work on Windows but does on Linux.
Example
Current Output
Expected Output
Additional Information
Works on Linux
On branch devel commit ea6c28249ae7107fba954f90dac31132564dcaad