From af23040d9c9824800515a7116f0a5206bc901794 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 29 May 2019 11:40:07 -0400 Subject: [PATCH] file/close returns an integer. If opened with popen, returns the exit code. Otherwise returns nil. --- src/core/io.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/io.c b/src/core/io.c index 7a665eaf..42bccfe6 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -286,12 +286,15 @@ static Janet cfun_io_fclose(int32_t argc, Janet *argv) { #ifdef JANET_WINDOWS #define pclose _pclose #endif - if (pclose(iof->file)) janet_panic("could not close file"); + int status = pclose(iof->file); + iof->flags |= IO_CLOSED; + if (status) janet_panic("could not close file"); + return janet_wrap_integer(status); } else { if (fclose(iof->file)) janet_panic("could not close file"); + iof->flags |= IO_CLOSED; + return janet_wrap_nil(); } - iof->flags |= IO_CLOSED; - return argv[0]; } /* Seek a file */