mirror of
git://git.sv.gnu.org/nano.git
synced 2025-02-02 14:35:42 +03:00
tweaks: avoid three unneeded calls of umask() in the normal case
This commit is contained in:
parent
f5693d4151
commit
a1bef0e953
15
src/files.c
15
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user