diff options
| author | Eli Zaretskii | 1998-05-13 15:12:18 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 1998-05-13 15:12:18 +0000 |
| commit | 360c227503bf075f82755032aa5bec4ab2414864 (patch) | |
| tree | d0bd2c67540cd498b2f4c58f0cffefd687c75ec9 /src | |
| parent | feb9dc27d7e1f2ddc4a4eef84937f701e18e8445 (diff) | |
| download | emacs-360c227503bf075f82755032aa5bec4ab2414864.tar.gz emacs-360c227503bf075f82755032aa5bec4ab2414864.zip | |
(init_environment): Set TMPDIR to an existing
directory. Abort if none of the usual places is available.
Diffstat (limited to 'src')
| -rw-r--r-- | src/msdos.c | 32 |
1 files changed, 32 insertions, 0 deletions
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) | |||
| 2769 | { | 2769 | { |
| 2770 | char *s, *t, *root; | 2770 | char *s, *t, *root; |
| 2771 | int len; | 2771 | int len; |
| 2772 | static const char * const tempdirs[] = { | ||
| 2773 | "$TMPDIR", "$TEMP", "$TMP", "c:/" | ||
| 2774 | }; | ||
| 2775 | int i; | ||
| 2776 | const int imax = sizeof (tempdirs) / sizeof (tempdirs[0]); | ||
| 2777 | |||
| 2778 | /* Make sure they have a usable $TMPDIR. Many Emacs functions use | ||
| 2779 | temporary files and assume "/tmp" if $TMPDIR is unset, which | ||
| 2780 | will break on DOS/Windows. Refuse to work if we cannot find | ||
| 2781 | a directory, not even "c:/", usable for that purpose. */ | ||
| 2782 | for (i = 0; i < imax ; i++) | ||
| 2783 | { | ||
| 2784 | const char *tmp = tempdirs[i]; | ||
| 2785 | |||
| 2786 | if (*tmp == '$') | ||
| 2787 | tmp = getenv (tmp + 1); | ||
| 2788 | /* Note that `access' can lie to us if the directory resides on a | ||
| 2789 | read-only filesystem, like CD-ROM or a write-protected floppy. | ||
| 2790 | The only way to be really sure is to actually create a file and | ||
| 2791 | see if it succeeds. But I think that's too much to ask. */ | ||
| 2792 | if (tmp && access (tmp, D_OK) == 0) | ||
| 2793 | { | ||
| 2794 | setenv ("TMPDIR", tmp, 1); | ||
| 2795 | break; | ||
| 2796 | } | ||
| 2797 | } | ||
| 2798 | if (i >= imax) | ||
| 2799 | cmd_error_internal | ||
| 2800 | (Fcons (Qerror, | ||
| 2801 | Fcons (build_string ("no usable temporary directories found!!"), | ||
| 2802 | Qnil)), | ||
| 2803 | "While setting TMPDIR: "); | ||
| 2772 | 2804 | ||
| 2773 | /* Find our root from argv[0]. Assuming argv[0] is, say, | 2805 | /* Find our root from argv[0]. Assuming argv[0] is, say, |
| 2774 | "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */ | 2806 | "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */ |