add sl_write_file
This commit is contained in:
parent
b0b09f6fd9
commit
deb02231af
1 changed files with 18 additions and 0 deletions
18
slibs.h
18
slibs.h
|
@ -199,6 +199,7 @@ void sl_append_c_str(sl_string *sl_str, const char *c_str)
|
||||||
});
|
});
|
||||||
|
|
||||||
void sl_read_file(const char *filename, sl_string *buffer);
|
void sl_read_file(const char *filename, sl_string *buffer);
|
||||||
|
void sl_write_file(const char *filename, const sl_string buffer);
|
||||||
|
|
||||||
#ifdef SL_IMPLEMENTATION
|
#ifdef SL_IMPLEMENTATION
|
||||||
void sl_read_file(const char *filename, sl_string *buffer)
|
void sl_read_file(const char *filename, sl_string *buffer)
|
||||||
|
@ -221,6 +222,23 @@ void sl_read_file(const char *filename, sl_string *buffer)
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sl_write_file(const char *filename, const sl_string buffer)
|
||||||
|
{
|
||||||
|
FILE *file = fopen(filename, "w");
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: could not open file %s\n", filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (sl_vec_it(c, buffer))
|
||||||
|
{
|
||||||
|
fputc(*c, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // SLIBS_H
|
#endif // SLIBS_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue