no longer exit when file not found

This commit is contained in:
sam 2024-07-22 22:43:39 +12:00
parent 2061729f4b
commit 986006449d

View file

@ -144,7 +144,8 @@ typedef sl_vec(char) sl_string;
char *sl_c_str(sl_string str); char *sl_c_str(sl_string str);
#ifdef SL_IMPLEMENTATION #ifdef SL_IMPLEMENTATION
char* sl_c_str(sl_string str) { char *sl_c_str(sl_string str)
{
sl_vec_push(str, '\0'); sl_vec_push(str, '\0');
return str.data; return str.data;
} }
@ -211,7 +212,6 @@ FILE *sl_open_file(const char *filename, const char *mode)
if (!file) if (!file)
{ {
fprintf(stderr, "Error: could not open file %s\n", filename); fprintf(stderr, "Error: could not open file %s\n", filename);
exit(1);
} }
return file; return file;
} }
@ -219,6 +219,7 @@ FILE *sl_open_file(const char *filename, const char *mode)
sl_string *sl_read_file(const char *filename) sl_string *sl_read_file(const char *filename)
{ {
FILE *file = sl_open_file(filename, "r"); FILE *file = sl_open_file(filename, "r");
if(!file) return NULL;
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
size_t file_size = ftell(file); size_t file_size = ftell(file);
@ -238,6 +239,7 @@ sl_string *sl_read_file(const char *filename)
void sl_write_file(const char *filename, sl_string buffer) void sl_write_file(const char *filename, sl_string buffer)
{ {
FILE *file = sl_open_file(filename, "w"); FILE *file = sl_open_file(filename, "w");
if(!file) return;
fputs(sl_c_str(buffer), file); fputs(sl_c_str(buffer), file);
fclose(file); fclose(file);