From 360c227503bf075f82755032aa5bec4ab2414864 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 13 May 1998 15:12:18 +0000 Subject: [PATCH] (init_environment): Set TMPDIR to an existing directory. Abort if none of the usual places is available. --- src/msdos.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/msdos.c b/src/msdos.c index 7f7f58d75cb..a557a988d1d 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -2769,6 +2769,38 @@ init_environment (argc, argv, skip_args) { char *s, *t, *root; int len; + static const char * const tempdirs[] = { + "$TMPDIR", "$TEMP", "$TMP", "c:/" + }; + int i; + const int imax = sizeof (tempdirs) / sizeof (tempdirs[0]); + + /* Make sure they have a usable $TMPDIR. Many Emacs functions use + temporary files and assume "/tmp" if $TMPDIR is unset, which + will break on DOS/Windows. Refuse to work if we cannot find + a directory, not even "c:/", usable for that purpose. */ + for (i = 0; i < imax ; i++) + { + const char *tmp = tempdirs[i]; + + if (*tmp == '$') + tmp = getenv (tmp + 1); + /* Note that `access' can lie to us if the directory resides on a + read-only filesystem, like CD-ROM or a write-protected floppy. + The only way to be really sure is to actually create a file and + see if it succeeds. But I think that's too much to ask. */ + if (tmp && access (tmp, D_OK) == 0) + { + setenv ("TMPDIR", tmp, 1); + break; + } + } + if (i >= imax) + cmd_error_internal + (Fcons (Qerror, + Fcons (build_string ("no usable temporary directories found!!"), + Qnil)), + "While setting TMPDIR: "); /* Find our root from argv[0]. Assuming argv[0] is, say, "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */ -- 2.39.2