# HG changeset patch # User Eli Zaretskii # Date 895072338 0 # Node ID d313bff62b93b4ce1dd11f268804f828add1fd0a # Parent 8697087ea0262af0987a2176bd3d5f9039c7c9a9 (init_environment): Set TMPDIR to an existing directory. Abort if none of the usual places is available. diff -r 8697087ea026 -r d313bff62b93 src/msdos.c --- a/src/msdos.c Wed May 13 06:47:40 1998 +0000 +++ b/src/msdos.c Wed May 13 15:12:18 1998 +0000 @@ -2769,6 +2769,38 @@ { 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". */