From 47784ac0fa2d082d958163db3617ac72ebb1650f Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 12 Sep 2018 09:38:41 -0400 Subject: [PATCH] added status return to buf_save --- inc/edit.h | 2 +- lib/buf.c | 5 +++-- tide.c | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index 78042f2..8e99967 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -37,7 +37,7 @@ typedef struct { void buf_init(Buf* buf); void buf_load(Buf* buf, char* path); void buf_reload(Buf* buf); -void buf_save(Buf* buf); +int buf_save(Buf* buf); size_t buf_end(Buf* buf); int buf_getrat(Buf* buf, size_t off); diff --git a/lib/buf.c b/lib/buf.c index 3c80c61..0501605 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -73,8 +73,8 @@ void buf_reload(Buf* buf) { buf_load(buf, path); } -void buf_save(Buf* buf) { - if (0 == buf_end(buf)) return; +int buf_save(Buf* buf) { + if (0 == buf_end(buf)) return buf->status; char* wptr; long fd, nwrite = 0, towrite = 0; if (buf->path && (fd = open(buf->path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) >= 0) { @@ -92,6 +92,7 @@ void buf_save(Buf* buf) { } else { buf->status = ERRORED; } + return buf->status; } static void buf_resize(Buf* buf, size_t sz) { diff --git a/tide.c b/tide.c index 03e4a1a..6927760 100644 --- a/tide.c +++ b/tide.c @@ -265,8 +265,7 @@ static void put(char* arg) { if (!path) path = strdup(arg); free(view->buffer.path); view->buffer.path = path; - buf_save(&(view->buffer)); - if (view->buffer.status == NORMAL) { + if (buf_save(&(view->buffer)) == NORMAL) { char* path = realpath(view->buffer.path, NULL); if (path) { free(view->buffer.path); -- 2.49.0