no longer exit when file not found
This commit is contained in:
parent
2061729f4b
commit
986006449d
1 changed files with 5 additions and 3 deletions
8
slibs.h
8
slibs.h
|
@ -141,10 +141,11 @@ typedef sl_vec(char) sl_string;
|
|||
|
||||
#define sl_str_free(str) sl_vec_free(str)
|
||||
|
||||
char* sl_c_str(sl_string str);
|
||||
char *sl_c_str(sl_string str);
|
||||
|
||||
#ifdef SL_IMPLEMENTATION
|
||||
char* sl_c_str(sl_string str) {
|
||||
char *sl_c_str(sl_string str)
|
||||
{
|
||||
sl_vec_push(str, '\0');
|
||||
return str.data;
|
||||
}
|
||||
|
@ -211,7 +212,6 @@ FILE *sl_open_file(const char *filename, const char *mode)
|
|||
if (!file)
|
||||
{
|
||||
fprintf(stderr, "Error: could not open file %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
@ -219,6 +219,7 @@ FILE *sl_open_file(const char *filename, const char *mode)
|
|||
sl_string *sl_read_file(const char *filename)
|
||||
{
|
||||
FILE *file = sl_open_file(filename, "r");
|
||||
if(!file) return NULL;
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
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)
|
||||
{
|
||||
FILE *file = sl_open_file(filename, "w");
|
||||
if(!file) return;
|
||||
|
||||
fputs(sl_c_str(buffer), file);
|
||||
fclose(file);
|
||||
|
|
Loading…
Add table
Reference in a new issue