Update error handling inside extlibs
This commit is contained in:
@@ -10,7 +10,7 @@ GroundValue native_file_read(GroundScope* scope, List args) {
|
||||
char* path = args.values[0].data.stringVal;
|
||||
FILE* f = fopen(path, "r");
|
||||
if (!f) {
|
||||
return groundCreateValue(NONE);
|
||||
ERROR("Failed to open file for reading", "FileError");
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -20,7 +20,7 @@ GroundValue native_file_read(GroundScope* scope, List args) {
|
||||
char* content = malloc(fsize + 1);
|
||||
if (!content) {
|
||||
fclose(f);
|
||||
return groundCreateValue(NONE);
|
||||
ERROR("Failed to allocate memory for file reading", "FileError");
|
||||
}
|
||||
|
||||
fread(content, 1, fsize, f);
|
||||
@@ -42,7 +42,7 @@ GroundValue native_file_write(GroundScope* scope, List args) {
|
||||
|
||||
FILE* f = fopen(path, "w");
|
||||
if (!f) {
|
||||
return groundCreateValue(BOOL, 0);
|
||||
ERROR("Failed to open file for writing", "FileError");
|
||||
}
|
||||
|
||||
fprintf(f, "%s", content);
|
||||
|
||||
Reference in New Issue
Block a user