From c8c69d5449f681b06f8cc86f1bfb2e5f4fc9346f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 3 Jul 2004 03:22:23 +0000 Subject: [PATCH] for consistency with nano 1.2.x and with other editors, make the mode of newly created files 666 instead of 600 before it's modified by the umask; also add a few more minor comment fixes git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1838 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/files.c | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index e69e30ec..428c4cd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,10 @@ CVS code - close_open_file() - Tweak to no longer rely on the return values of open_(prev|next)file(). (DLR) + write_file() + - For consistency with nano 1.2.x and with other editors, make + the mode of newly created files 666 instead of 600 before + it's modified by the umask. (DLR) - global.c: shortcut_init() - Fix erroneous #ifdef so that nano compiles with diff --git a/src/files.c b/src/files.c index abc0cfbe..9e109329 100644 --- a/src/files.c +++ b/src/files.c @@ -1369,7 +1369,7 @@ int copy_file(FILE *inn, FILE *out) return retval; } -/* Write a file out. If tmp is nonzero, we set the umask to disallow +/* Write a file out. If tmp is FALSE, we set the umask to disallow * anyone else from accessing the file, we don't set the global variable * filename to its name, and we don't print out how many lines we wrote * on the statusbar. @@ -1392,12 +1392,12 @@ int write_file(const char *name, int tmp, int append, int nonamechange) size_t lineswritten = 0; const filestruct *fileptr = fileage; int fd; - mode_t original_umask = 0; + mode_t original_umask; /* Our umask, from when nano started. */ int realexists; - /* The result of stat(). True if the file exists, false + /* The result of stat(). TRUE if the file exists, FALSE * otherwise. If name is a link that points nowhere, realexists - * is false. */ + * is FALSE. */ struct stat st; /* The status fields filled in by stat(). */ int anyexists; @@ -1438,7 +1438,8 @@ int write_file(const char *name, int tmp, int append, int nonamechange) /* If NOFOLLOW_SYMLINKS is set, it doesn't make sense to prepend or * append to a symlink. Here we warn about the contradiction. */ if (ISSET(NOFOLLOW_SYMLINKS) && anyexists && S_ISLNK(lst.st_mode)) { - statusbar(_("Cannot prepend or append to a symlink with --nofollow set")); + statusbar( + _("Cannot prepend or append to a symlink with --nofollow set")); goto cleanup_and_exit; } @@ -1554,12 +1555,13 @@ int write_file(const char *name, int tmp, int append, int nonamechange) original_umask = umask(0); umask(original_umask); + /* If we create a temp file, we don't let anyone else access it. We - * create a temp file if tmp is nonzero or if we prepend. */ + * create a temp file if tmp is TRUE or if we're prepending. */ if (tmp || append == 2) umask(S_IRWXG | S_IRWXO); - /* If we are prepending, copy the file to a temp file. */ + /* If we're prepending, copy the file to a temp file. */ if (append == 2) { int fd_source; FILE *f_source = NULL; @@ -1600,13 +1602,13 @@ int write_file(const char *name, int tmp, int append, int nonamechange) } } - /* Now open the file in place. Use O_EXCL if tmp is nonzero. This - * is now copied from joe, because wiggy says so *shrug*. */ + /* Now open the file in place. Use O_EXCL if tmp is TRUE. This is + * now copied from joe, because wiggy says so *shrug*. */ fd = open(realname, O_WRONLY | O_CREAT | (append == 1 ? O_APPEND : (tmp ? O_EXCL : O_TRUNC)), - S_IRUSR | S_IWUSR); + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - /* Put the umask back to the user's original value. */ + /* Set the umask back to the user's original value. */ umask(original_umask); /* First, just give up if we couldn't even open the file. */ -- 2.39.5