mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 08:10:05 +00:00
Minor os.read() fixes
This commit is contained in:
parent
cfb4df66f9
commit
24bbc22cd4
@ -256,6 +256,11 @@ int cosmoB_osRead(CState *state, int nargs, CValue *args) {
|
|||||||
char *buf;
|
char *buf;
|
||||||
size_t size, bRead;
|
size_t size, bRead;
|
||||||
|
|
||||||
|
if (file == NULL) {
|
||||||
|
// return nil, file doesn't exist
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// grab the size of the file
|
// grab the size of the file
|
||||||
fseek(file, 0L, SEEK_END);
|
fseek(file, 0L, SEEK_END);
|
||||||
size = ftell(file);
|
size = ftell(file);
|
||||||
@ -266,8 +271,7 @@ int cosmoB_osRead(CState *state, int nargs, CValue *args) {
|
|||||||
|
|
||||||
if (bRead < size) {
|
if (bRead < size) {
|
||||||
// an error occured! we don't need to really throw an error, returning a nil is good enough
|
// an error occured! we don't need to really throw an error, returning a nil is good enough
|
||||||
cosmoV_pushNil(state);
|
return 0;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[bRead] = '\0'; // place the NULL terminator at the end of the buffer
|
buf[bRead] = '\0'; // place the NULL terminator at the end of the buffer
|
||||||
|
Loading…
Reference in New Issue
Block a user