add sl_write_file

This commit is contained in:
sam 2024-07-22 21:05:09 +12:00
parent b0b09f6fd9
commit deb02231af

18
slibs.h
View file

@ -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_write_file(const char *filename, const sl_string buffer);
#ifdef SL_IMPLEMENTATION
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);
}
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 // SLIBS_H