Fix AsyncFile open flags. Fixes #5531
This commit is contained in:
parent
b5538990a2
commit
319e88585a
3 changed files with 9 additions and 9 deletions
|
|
@ -50,22 +50,21 @@ when defined(windows) or defined(nimdoc):
|
|||
case mode
|
||||
of fmRead, fmReadWriteExisting:
|
||||
OPEN_EXISTING
|
||||
of fmAppend, fmReadWrite, fmWrite:
|
||||
if fileExists(filename):
|
||||
OPEN_EXISTING
|
||||
else:
|
||||
CREATE_NEW
|
||||
of fmReadWrite, fmWrite:
|
||||
CREATE_ALWAYS
|
||||
of fmAppend:
|
||||
OPEN_ALWAYS
|
||||
else:
|
||||
proc getPosixFlags(mode: FileMode): cint =
|
||||
case mode
|
||||
of fmRead:
|
||||
result = O_RDONLY
|
||||
of fmWrite:
|
||||
result = O_WRONLY or O_CREAT
|
||||
result = O_WRONLY or O_CREAT or O_TRUNC
|
||||
of fmAppend:
|
||||
result = O_WRONLY or O_CREAT or O_APPEND
|
||||
of fmReadWrite:
|
||||
result = O_RDWR or O_CREAT
|
||||
result = O_RDWR or O_CREAT or O_TRUNC
|
||||
of fmReadWriteExisting:
|
||||
result = O_RDWR
|
||||
result = result or O_NONBLOCK
|
||||
|
|
|
|||
|
|
@ -666,6 +666,7 @@ const
|
|||
CREATE_ALWAYS* = 2'i32
|
||||
CREATE_NEW* = 1'i32
|
||||
OPEN_EXISTING* = 3'i32
|
||||
OPEN_ALWAYS* = 4'i32
|
||||
FILE_BEGIN* = 0'i32
|
||||
INVALID_SET_FILE_POINTER* = -1'i32
|
||||
NO_ERROR* = 0'i32
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ proc main() {.async.} =
|
|||
await file.write("test2")
|
||||
file.close()
|
||||
file = openAsync(fn, fmWrite)
|
||||
await file.write("test3")
|
||||
await file.write("t3")
|
||||
file.close()
|
||||
file = openAsync(fn, fmRead)
|
||||
let data = await file.readAll()
|
||||
doAssert data == "test3"
|
||||
doAssert data == "t3"
|
||||
file.close()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue