From d473a991d015130c59690f2e8738121216e20860 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sun, 28 Dec 2025 16:36:21 -0500 Subject: don't throw error on opening nonexistent file, "wb" for txt_save --- txt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'txt.c') diff --git a/txt.c b/txt.c index 0b13a9e..61b0c22 100644 --- a/txt.c +++ b/txt.c @@ -147,12 +147,13 @@ u32 txt_delete_c(Txt *b, u32 cur) { int txt_load(Txt *b, const char *path) { struct stat sb; int fd = open(path, O_RDONLY); - if (fd == -1) return -1; + if (fd == -1) goto empty_file; if (fstat(fd, &sb)) { close(fd); return -1; } if (!sb.st_size) { +empty_file: txt_buf_fit(b, TXT_SRC, 8192); goto done; } @@ -175,7 +176,7 @@ done: } int txt_save(Txt *t, const char *path) { - FILE *f = fopen(path, "w"); + FILE *f = fopen(path, "wb"); if (!f) return -1; for (u32 i = 0; i < t->ptbl.n; i++) { TxtPiece *p = &t->ptbl.v[i]; -- cgit v1.2.3