From 46f57f5c38066c73fa538a8c2ac169b7864d02dd Mon Sep 17 00:00:00 2001 From: Andrew Chambers Date: Tue, 21 Jan 2020 22:03:57 +1300 Subject: [PATCH] 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. --- src/core/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/io.c b/src/core/io.c index 585ba2c2..edaefef6 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -290,7 +290,7 @@ static Janet cfun_io_fclose(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype); if (iof->flags & JANET_FILE_CLOSED) - janet_panic("file is closed"); + return janet_wrap_nil(); if (iof->flags & (JANET_FILE_NOT_CLOSEABLE)) janet_panic("file not closable"); if (iof->flags & JANET_FILE_PIPED) {