nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 69e6ccf64124a631a3995842c311e3c2df26ff9f
parent 14717d74499e0418468e818080cb1ffe6f182173
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 14 Jul 2020 12:51:21 +0200

tweaks: reshuffle a fragment of code, to elide a 'goto'

Diffstat:
Msrc/files.c | 19++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git 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); + + backup_fd = mkstemp(*backupname); + } - try_backup: + 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