vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit d410bb2a150099c1bbecb356f3193ea091d96bc3 parent 3b892f231e4948c037a43bba4dd46aee2b514855 Author: Marc André Tanner <mat@brain-dump.org> Date: Sat, 25 Oct 2014 14:27:10 +0200 Change return type of text_save Diffstat:
| M | text.c | | | 8 | ++++---- |
| M | text.h | | | 2 | +- |
| M | vis.c | | | 2 | +- |
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/text.c b/text.c @@ -598,12 +598,12 @@ size_t text_redo(Text *txt) { * and then atomically moved to its final (possibly alredy existing) destination * using rename(2). */ -int text_save(Text *txt, const char *filename) { +bool text_save(Text *txt, const char *filename) { int fd = -1; size_t len = strlen(filename) + 10; char *tmpname = malloc(len); if (!tmpname) - return -1; + return false; snprintf(tmpname, len, "%s~", filename); // TODO preserve user/group struct stat meta; @@ -642,12 +642,12 @@ int text_save(Text *txt, const char *filename) { if (!txt->filename) text_filename_set(txt, filename); free(tmpname); - return 0; + return true; err: if (fd != -1) close(fd); free(tmpname); - return -1; + return false; } ssize_t text_write(Text *txt, int fd) { diff --git a/text.h b/text.h @@ -84,7 +84,7 @@ size_t text_size(Text*); bool text_modified(Text*); /* test whether the underlying file uses UNIX style \n or Windows style \r\n newlines */ bool text_newlines_crnl(Text*); -int text_save(Text*, const char *file); +bool text_save(Text*, const char *file); ssize_t text_write(Text*, int fd); void text_free(Text*); diff --git a/vis.c b/vis.c @@ -1421,7 +1421,7 @@ static bool cmd_write(Filerange *range, const char *argv[]) { return false; } for (const char **file = &argv[1]; *file; file++) { - if (text_save(text, *file)) { + if (!text_save(text, *file)) { editor_info_show(vis, "Can't write `%s'", *file); return false; }