tweaks: reshuffle a few lines, and condense some comments

master
Benno Schulenberg 2019-02-10 17:04:55 +01:00
parent b57336ad00
commit 32d7d3900d
1 changed files with 9 additions and 14 deletions

View File

@ -1415,29 +1415,24 @@ char *check_writable_directory(const char *path)
} }
/* This function calls mkstemp(($TMPDIR|P_tmpdir|/tmp/)"nano.XXXXXX"). /* This function calls mkstemp(($TMPDIR|P_tmpdir|/tmp/)"nano.XXXXXX").
* On success, it returns the malloc()ed filename and corresponding FILE * On success, it returns the malloc()ed filename and corresponding
* stream, opened in "r+b" mode. On error, it returns NULL for the * FILE stream, opened in "r+b" mode. On error, it returns NULL for
* filename and leaves the FILE stream unchanged. */ * the filename and leaves the FILE stream unchanged. */
char *safe_tempfile(FILE **f) char *safe_tempfile(FILE **f)
{ {
const char *tmpdir_env = getenv("TMPDIR");
char *full_tempdir = NULL; char *full_tempdir = NULL;
const char *tmpdir_env;
int fd;
mode_t original_umask = 0; mode_t original_umask = 0;
int fd;
/* If $TMPDIR is set, set tempdir to it, run it through /* Get the absolute path for the first directory among $TMPDIR
* get_full_path(), and save the result in full_tempdir. Otherwise, * and P_tmpdir that is writable, otherwise use /tmp/. */
* leave full_tempdir set to NULL. */
tmpdir_env = getenv("TMPDIR");
if (tmpdir_env != NULL) if (tmpdir_env != NULL)
full_tempdir = check_writable_directory(tmpdir_env); full_tempdir = check_writable_directory(tmpdir_env);
/* If $TMPDIR is unset, empty, or not a writable directory, and
* full_tempdir is NULL, try P_tmpdir instead. */
if (full_tempdir == NULL) if (full_tempdir == NULL)
full_tempdir = check_writable_directory(P_tmpdir); full_tempdir = check_writable_directory(P_tmpdir);
/* if P_tmpdir is NULL, use /tmp. */
if (full_tempdir == NULL) if (full_tempdir == NULL)
full_tempdir = mallocstrcpy(NULL, "/tmp/"); full_tempdir = mallocstrcpy(NULL, "/tmp/");
@ -1516,8 +1511,8 @@ int prompt_failed_backupwrite(const char *filename)
{ {
static int choice; static int choice;
static char *prevfile = NULL; static char *prevfile = NULL;
/* The last file we were passed, so we don't keep asking this. /* The last filename we were passed, so we don't keep asking this. */
* Though maybe we should? */
if (prevfile == NULL || strcmp(filename, prevfile)) { if (prevfile == NULL || strcmp(filename, prevfile)) {
choice = do_yesno_prompt(FALSE, _("Failed to write backup file; " choice = do_yesno_prompt(FALSE, _("Failed to write backup file; "
"continue saving? (Say N if unsure.) ")); "continue saving? (Say N if unsure.) "));