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
|
case mode
|
||||||
of fmRead, fmReadWriteExisting:
|
of fmRead, fmReadWriteExisting:
|
||||||
OPEN_EXISTING
|
OPEN_EXISTING
|
||||||
of fmAppend, fmReadWrite, fmWrite:
|
of fmReadWrite, fmWrite:
|
||||||
if fileExists(filename):
|
CREATE_ALWAYS
|
||||||
OPEN_EXISTING
|
of fmAppend:
|
||||||
else:
|
OPEN_ALWAYS
|
||||||
CREATE_NEW
|
|
||||||
else:
|
else:
|
||||||
proc getPosixFlags(mode: FileMode): cint =
|
proc getPosixFlags(mode: FileMode): cint =
|
||||||
case mode
|
case mode
|
||||||
of fmRead:
|
of fmRead:
|
||||||
result = O_RDONLY
|
result = O_RDONLY
|
||||||
of fmWrite:
|
of fmWrite:
|
||||||
result = O_WRONLY or O_CREAT
|
result = O_WRONLY or O_CREAT or O_TRUNC
|
||||||
of fmAppend:
|
of fmAppend:
|
||||||
result = O_WRONLY or O_CREAT or O_APPEND
|
result = O_WRONLY or O_CREAT or O_APPEND
|
||||||
of fmReadWrite:
|
of fmReadWrite:
|
||||||
result = O_RDWR or O_CREAT
|
result = O_RDWR or O_CREAT or O_TRUNC
|
||||||
of fmReadWriteExisting:
|
of fmReadWriteExisting:
|
||||||
result = O_RDWR
|
result = O_RDWR
|
||||||
result = result or O_NONBLOCK
|
result = result or O_NONBLOCK
|
||||||
|
|
|
||||||
|
|
@ -666,6 +666,7 @@ const
|
||||||
CREATE_ALWAYS* = 2'i32
|
CREATE_ALWAYS* = 2'i32
|
||||||
CREATE_NEW* = 1'i32
|
CREATE_NEW* = 1'i32
|
||||||
OPEN_EXISTING* = 3'i32
|
OPEN_EXISTING* = 3'i32
|
||||||
|
OPEN_ALWAYS* = 4'i32
|
||||||
FILE_BEGIN* = 0'i32
|
FILE_BEGIN* = 0'i32
|
||||||
INVALID_SET_FILE_POINTER* = -1'i32
|
INVALID_SET_FILE_POINTER* = -1'i32
|
||||||
NO_ERROR* = 0'i32
|
NO_ERROR* = 0'i32
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@ proc main() {.async.} =
|
||||||
await file.write("test2")
|
await file.write("test2")
|
||||||
file.close()
|
file.close()
|
||||||
file = openAsync(fn, fmWrite)
|
file = openAsync(fn, fmWrite)
|
||||||
await file.write("test3")
|
await file.write("t3")
|
||||||
file.close()
|
file.close()
|
||||||
file = openAsync(fn, fmRead)
|
file = openAsync(fn, fmRead)
|
||||||
let data = await file.readAll()
|
let data = await file.readAll()
|
||||||
doAssert data == "test3"
|
doAssert data == "t3"
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue