mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-20 03:14:45 +00:00
More error checking
This commit is contained in:
parent
dedb94223f
commit
fdfd6a2af3
1 changed files with 13 additions and 7 deletions
|
@ -33895,10 +33895,14 @@ qbs *func__readfile(qbs *filespec)
|
|||
rewind(file); // rewind to start
|
||||
cont = qbs_new(len, 1); // get new string for file contents
|
||||
fread(cont->chr, 1, len, file);
|
||||
if (ferror(file)) {
|
||||
error(QB_ERROR_PATH_FILE_ACCESS_ERROR); // something went wrong
|
||||
cont = qbs_new_txt(""); // return empty on error
|
||||
}
|
||||
fclose(file);
|
||||
return cont;
|
||||
} else {
|
||||
error(QB_ERROR_FILE_NOT_FOUND); // error, we throw most common
|
||||
error(QB_ERROR_FILE_NOT_FOUND); // most common when trying to read
|
||||
return qbs_new_txt(""); // return empty on error
|
||||
}
|
||||
}
|
||||
|
@ -33914,9 +33918,11 @@ void sub__writefile(qbs *filespec, qbs *contents)
|
|||
|
||||
if (file) {
|
||||
fwrite(contents->chr, 1, contents->len, file);
|
||||
if (ferror(file))
|
||||
error(QB_ERROR_PATH_FILE_ACCESS_ERROR); // something went wrong
|
||||
fclose(file);
|
||||
} else {
|
||||
error(QB_ERROR_PATH_FILE_ACCESS_ERROR); // error, we throw best fit
|
||||
error(QB_ERROR_PATH_NOT_FOUND); // most common when making a new file
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue