tweaks: reshuffle some lines to elide a variable

Having a local variable that gets assigned to just once looks rather
poor.  To me it makes more sense to have two separate exit points: one
for failure somewhere in the middle, and one for success at the end.
This way it is completely clear which value gets returned when.
This commit is contained in:
Benno Schulenberg 2021-07-10 16:07:33 +02:00
parent 30aaea2d04
commit 806e8e439f
1 changed files with 6 additions and 6 deletions

View File

@ -1758,8 +1758,6 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
/* An iterator for moving through the lines of the buffer. */
size_t lineswritten = 0;
/* The number of lines written, for feedback on the status bar. */
bool retval = FALSE;
/* The return value, to become TRUE when writing has succeeded. */
#ifdef ENABLE_OPERATINGDIR
/* If we're writing a temporary file, we're probably going outside
@ -1955,7 +1953,11 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
if (fclose(thefile) != 0) {
statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
goto cleanup_and_exit;
cleanup_and_exit:
free(tempname);
free(realname);
return FALSE;
}
/* When having written an entire buffer, update some administrivia. */
@ -2011,13 +2013,11 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
if (!tmp)
statusline(REMARK, P_("Wrote %zu line", "Wrote %zu lines",
lineswritten), lineswritten);
retval = TRUE;
cleanup_and_exit:
free(tempname);
free(realname);
return retval;
return TRUE;
}
#ifndef NANO_TINY