summaryrefslogtreecommitdiff
path: root/txt.c
diff options
context:
space:
mode:
authorWormHeamer2025-12-28 16:36:21 -0500
committerWormHeamer2025-12-28 16:36:21 -0500
commitd473a991d015130c59690f2e8738121216e20860 (patch)
tree65e2a0f4543f4e1ec0a770367c9f9f37f2a6dc01 /txt.c
parent93217174999958163609bae1bd336999af9db184 (diff)
don't throw error on opening nonexistent file, "wb" for txt_save
Diffstat (limited to 'txt.c')
-rw-r--r--txt.c5
1 files changed, 3 insertions, 2 deletions
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];