nano

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

commit a1bef0e953fda29600c78607a4f4e196134d3435
parent f5693d4151ece1a3b59c53e21c0eb1d6d940fdd1
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 16 Oct 2019 19:17:42 +0200

tweaks: avoid three unneeded calls of umask() in the normal case

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

diff --git a/src/files.c b/src/files.c @@ -1708,14 +1708,10 @@ bool write_file(const char *name, FILE *stream, bool tmp, skip_backup: #endif /* !NANO_TINY */ - if (stream == NULL) { + /* When going to create an emergency file, don't let others access it. */ + if (stream == NULL && tmp) { original_umask = umask(0); - - /* When writing an emergency file, we don't let anyone else access it. */ - if (tmp) - umask(S_IRWXG | S_IRWXO); - else - umask(original_umask); + umask(S_IRWXG | S_IRWXO); } #ifndef NANO_TINY @@ -1774,8 +1770,9 @@ bool write_file(const char *name, FILE *stream, bool tmp, restore_handler_for_Ctrl_C(); block_sigwinch(FALSE); #endif - /* Set the umask back to the user's original value. */ - umask(original_umask); + /* When this is an emergency file, restore the original umask. */ + if (tmp) + umask(original_umask); /* If we couldn't open the file, give up. */ if (fd == -1) {