fix #19600 No error checking on fclose (#19836)

* fix #19600 No error checking on fclose

* add IOError to open
This commit is contained in:
Bung 2022-08-30 00:09:14 +08:00 • committed by GitHub
commit 04e4a5ec0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -324,7 +324,9 @@ const
proc close*(f: File) {.tags: [], gcsafe.} = proc close*(f: File) {.tags: [], gcsafe.} =
## Closes the file. ## Closes the file.
if not f.isNil: if not f.isNil:
discard c_fclose(f) let x = c_fclose(f)
if x < 0:
checkErr(f)
proc readChar*(f: File): char {.tags: [ReadIOEffect].} = proc readChar*(f: File): char {.tags: [ReadIOEffect].} =
## Reads a single character from the stream `f`. Should not be used in ## Reads a single character from the stream `f`. Should not be used in
@ -689,7 +691,7 @@ when defined(posix) and not defined(nimscript):
proc open*(f: var File, filename: string, proc open*(f: var File, filename: string,
mode: FileMode = fmRead, mode: FileMode = fmRead,
bufSize: int = -1): bool {.tags: [], raises: [], benign.} = bufSize: int = -1): bool {.tags: [], raises: [IOError], benign.} =
## Opens a file named `filename` with given `mode`. ## Opens a file named `filename` with given `mode`.
## ##
## Default mode is readonly. Returns true if the file could be opened. ## Default mode is readonly. Returns true if the file could be opened.

9
tests/misc/t19600.nim Normal file
View file

@ -0,0 +1,9 @@
discard """
targets: "c cpp"
disabled: "win"
disabled: "osx"
exitcode: 1
outputsub: "No space left on device"
"""
writeFile("/dev/full", "hello\n")