tweaks: rename a variable, to avoid overrepetition of 'backup'

Also, reshuffle three calls of fclose().
master
Benno Schulenberg 2020-07-14 13:04:34 +02:00
parent a2b7fc1c81
commit bde8858a3a
1 changed files with 14 additions and 14 deletions

View File

@ -1613,25 +1613,25 @@ bool backup_file(char *realname, char **backupname)
*backupname = charalloc(strlen(realname) + 2); *backupname = charalloc(strlen(realname) + 2);
sprintf(*backupname, "%s~", realname); sprintf(*backupname, "%s~", realname);
} else { } else {
char *backuptemp = get_full_path(realname); char *thename = get_full_path(realname);
/* If we have a valid absolute path, replace each slash /* If we have a valid absolute path, replace each slash
* in this full path with an exclamation mark. Otherwise, * in this full path with an exclamation mark. Otherwise,
* just use the file-name portion of the given path. */ * just use the file-name portion of the given path. */
if (backuptemp) { if (thename) {
for (int i = 0; backuptemp[i] != '\0'; i++) for (int i = 0; thename[i] != '\0'; i++)
if (backuptemp[i] == '/') if (thename[i] == '/')
backuptemp[i] = '!'; thename[i] = '!';
} else } else
backuptemp = copy_of(tail(realname)); thename = copy_of(tail(realname));
*backupname = charalloc(strlen(backup_dir) + strlen(backuptemp) + 1); *backupname = charalloc(strlen(backup_dir) + strlen(thename) + 1);
sprintf(*backupname, "%s%s", backup_dir, backuptemp); sprintf(*backupname, "%s%s", backup_dir, thename);
free(backuptemp); free(thename);
backuptemp = get_next_filename(*backupname, "~"); thename = get_next_filename(*backupname, "~");
free(*backupname); free(*backupname);
*backupname = backuptemp; *backupname = thename;
/* If all numbered backup names are taken, the user must /* If all numbered backup names are taken, the user must
* be fond of backups. Thus, without one, do not go on. */ * be fond of backups. Thus, without one, do not go on. */
@ -1690,8 +1690,8 @@ bool backup_file(char *realname, char **backupname)
verdict = copy_file(original, backup_file, FALSE); verdict = copy_file(original, backup_file, FALSE);
if (verdict < 0) { if (verdict < 0) {
fclose(backup_file);
statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno)); statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno));
fclose(backup_file);
return FALSE; return FALSE;
} else if (verdict > 0) { } else if (verdict > 0) {
fclose(backup_file); fclose(backup_file);
@ -1948,12 +1948,12 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
verdict = copy_file(source, thefile, FALSE); verdict = copy_file(source, thefile, FALSE);
if (verdict < 0) { if (verdict < 0) {
fclose(thefile);
statusline(ALERT, _("Error reading temp file: %s"), strerror(errno)); statusline(ALERT, _("Error reading temp file: %s"), strerror(errno));
fclose(thefile);
goto cleanup_and_exit; goto cleanup_and_exit;
} else if (verdict > 0) { } else if (verdict > 0) {
fclose(thefile);
statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno)); statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
fclose(thefile);
goto cleanup_and_exit; goto cleanup_and_exit;
} }