From 24bbc22cd417b04eb2511584ad668f63c716ef39 Mon Sep 17 00:00:00 2001 From: cpunch Date: Wed, 10 Feb 2021 17:11:52 -0600 Subject: [PATCH] Minor os.read() fixes --- src/cbaselib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cbaselib.c b/src/cbaselib.c index 7090735..7776836 100644 --- a/src/cbaselib.c +++ b/src/cbaselib.c @@ -256,6 +256,11 @@ int cosmoB_osRead(CState *state, int nargs, CValue *args) { char *buf; size_t size, bRead; + if (file == NULL) { + // return nil, file doesn't exist + return 0; + } + // grab the size of the file fseek(file, 0L, SEEK_END); size = ftell(file); @@ -266,8 +271,7 @@ int cosmoB_osRead(CState *state, int nargs, CValue *args) { if (bRead < size) { // an error occured! we don't need to really throw an error, returning a nil is good enough - cosmoV_pushNil(state); - return 1; + return 0; } buf[bRead] = '\0'; // place the NULL terminator at the end of the buffer