Skip to content

Commit

Permalink
Change return type of text_save
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Oct 25, 2014
1 parent ecce157 commit d19c796
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);

Expand Down
2 changes: 1 addition & 1 deletion vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d19c796

Please sign in to comment.