From 69e6ccf64124a631a3995842c311e3c2df26ff9f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 14 Jul 2020 12:51:21 +0200 Subject: [PATCH] tweaks: reshuffle a fragment of code, to elide a 'goto' --- src/files.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/files.c b/src/files.c index d96ca665..aa6baa3b 100644 --- a/src/files.c +++ b/src/files.c @@ -1607,16 +1607,11 @@ bool backup_file(char *realname, char **backupname) statusbar(_("Making backup...")); + if (ISSET(MAKE_BACKUP)) { /* If no backup directory was specified, we make a simple backup * by appending a tilde to the original file name. Otherwise, * we create a numbered backup in the specified directory. */ - if (!ISSET(MAKE_BACKUP)) { - *backupname = charalloc(strlen(realname) + 8); - sprintf(*backupname, "%s~XXXXXX", realname); - - backup_fd = mkstemp(*backupname); - goto try_backup; - } else if (backup_dir == NULL) { + if (backup_dir == NULL) { *backupname = charalloc(strlen(realname) + 2); sprintf(*backupname, "%s~", realname); } else { @@ -1659,8 +1654,14 @@ bool backup_file(char *realname, char **backupname) /* Create the backup file (or truncate the existing one). */ backup_fd = open(*backupname, backup_cflags, S_IRUSR|S_IWUSR); + } else { + *backupname = charalloc(strlen(realname) + 8); + sprintf(*backupname, "%s~XXXXXX", realname); - try_backup: + backup_fd = mkstemp(*backupname); + } + + retry_backup: if (backup_fd >= 0) backup_file = fdopen(backup_fd, "wb"); @@ -1732,7 +1733,7 @@ bool backup_file(char *realname, char **backupname) } second_attempt = TRUE; - goto try_backup; + goto retry_backup; } /* If all attempts failed, notify the user, because if something goes