From 68dd9ac979d5c3afd72f3d2fb0d6dcda32b3c384 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 23 Aug 2011 08:40:27 +0200 Subject: [PATCH] tmpdir: Use a good default directory on native Windows. * lib/tmpdir.c: Include , pathmax.h. (P_tmpdir): Default to _P_tmpdir on native Windows. (path_search): On native Windows, try the value returned by GetTempPath before trying P_tmpdir. * modules/tmpdir (Depends-on): Add pathmax. Suggested by John Darrington . --- ChangeLog | 10 ++++++++++ lib/tmpdir.c | 26 +++++++++++++++++++++++++- modules/tmpdir | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 59b1b4b28..a24557021 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-08-23 Bruno Haible + + tmpdir: Use a good default directory on native Windows. + * lib/tmpdir.c: Include , pathmax.h. + (P_tmpdir): Default to _P_tmpdir on native Windows. + (path_search): On native Windows, try the value returned by GetTempPath + before trying P_tmpdir. + * modules/tmpdir (Depends-on): Add pathmax. + Suggested by John Darrington . + 2011-08-20 Reuben Thomas doc: fix typo in README-release diff --git a/lib/tmpdir.c b/lib/tmpdir.c index 5590ac3ba..f159f16b4 100644 --- a/lib/tmpdir.c +++ b/lib/tmpdir.c @@ -33,11 +33,22 @@ #include #ifndef P_tmpdir -# define P_tmpdir "/tmp" +# ifdef _P_tmpdir /* native Windows */ +# define P_tmpdir _P_tmpdir +# else +# define P_tmpdir "/tmp" +# endif #endif #include +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include +#endif + +#include "pathmax.h" + #if _LIBC # define struct_stat64 struct stat64 #else @@ -106,6 +117,19 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, } if (dir == NULL) { +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + char dirbuf[PATH_MAX]; + DWORD retval; + + /* Find Windows temporary file directory. + We try this before P_tmpdir because Windows defines P_tmpdir to "\\" + and will therefore try to put all temporary files in the root + directory (unless $TMPDIR is set). */ + retval = GetTempPath (PATH_MAX, dirbuf); + if (retval > 0 && retval < PATH_MAX && direxists (dirbuf)) + dir = dirbuf; + else +#endif if (direxists (P_tmpdir)) dir = P_tmpdir; else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp")) diff --git a/modules/tmpdir b/modules/tmpdir index a42fdc45b..0dd1780fd 100644 --- a/modules/tmpdir +++ b/modules/tmpdir @@ -9,6 +9,7 @@ m4/tmpdir.m4 Depends-on: stdbool sys_stat +pathmax configure.ac: gt_TMPDIR -- 2.11.0