Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions nob.h
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,6 @@ NOBDEF bool nob_write_entire_file(const char *path, const void *data, size_t siz
{
bool result = true;

const char *buf = NULL;
FILE *f = fopen(path, "wb");
if (f == NULL) {
nob_log(NOB_ERROR, "Could not open file %s for writing: %s\n", path, strerror(errno));
Expand All @@ -1769,15 +1768,10 @@ NOBDEF bool nob_write_entire_file(const char *path, const void *data, size_t siz
// ^
// data

buf = (const char*)data;
while (size > 0) {
size_t n = fwrite(buf, 1, size, f);
if (ferror(f)) {
nob_log(NOB_ERROR, "Could not write into file %s: %s\n", path, strerror(errno));
nob_return_defer(false);
}
size -= n;
buf += n;
size_t n = fwrite(data, 1, size, f);
if (n < size) {
nob_log(NOB_ERROR, "Could not write into file %s: %s\n", path, strerror(errno));
nob_return_defer(false);
}

defer:
Expand Down Expand Up @@ -2102,7 +2096,6 @@ NOBDEF bool nob_read_entire_file(const char *path, Nob_String_Builder *sb)

fread(sb->items + sb->count, m, 1, f);
if (ferror(f)) {
// TODO: Afaik, ferror does not set errno. So the error reporting in defer is not correct in this case.
nob_return_defer(false);
}
sb->count = new_count;
Expand Down