1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 09:47:17 +00:00

Make file/close idempotent.

It is easier to use constructs like defer
with complex control flow if it is safe to close
a file twice.
This commit is contained in:
Andrew Chambers 2020-01-21 22:03:57 +13:00
parent 1ec2e08f21
commit 46f57f5c38

View File

@ -290,7 +290,7 @@ static Janet cfun_io_fclose(int32_t argc, Janet *argv) {
janet_fixarity(argc, 1); janet_fixarity(argc, 1);
IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype); IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype);
if (iof->flags & JANET_FILE_CLOSED) if (iof->flags & JANET_FILE_CLOSED)
janet_panic("file is closed"); return janet_wrap_nil();
if (iof->flags & (JANET_FILE_NOT_CLOSEABLE)) if (iof->flags & (JANET_FILE_NOT_CLOSEABLE))
janet_panic("file not closable"); janet_panic("file not closable");
if (iof->flags & JANET_FILE_PIPED) { if (iof->flags & JANET_FILE_PIPED) {