annotate lib/tmpdir.c @ 16214:ec738d6aeef5

Talk about "native Windows API", not "Win32". * lib/classpath.c: Update comments to mention native Windows. * lib/csharpexec.c: Likewise. * lib/dup2.c: Likewise. * lib/error.c: Likewise. * lib/fcntl.c: Likewise. * lib/filename.h: Likewise. * lib/findprog.c: Likewise. * lib/get-rusage-as.c: Likewise. * lib/get-rusage-data.c: Likewise. * lib/getpagesize.c: Likewise. * lib/javaexec.c: Likewise. * lib/msvc-inval.c: Likewise. * lib/msvc-nothrow.c: Likewise. * lib/nanosleep.c: Likewise. * lib/nonblocking.c: Likewise. * lib/printf-parse.c: Likewise. * lib/setlocale.c: Likewise. * lib/sigaction.c: Likewise. * lib/strerror_r.c: Likewise. * lib/tmpdir.c: Likewise. * lib/vasnprintf.c: Likewise. * lib/w32spawn.h: Likewise. * lib/waitpid.c: Likewise. * lib/stdio.in.h (fdopen, fopen, freopen): Likewise. * m4/locale-ar.m4: Likewise. * m4/locale-fr.m4: Likewise. * m4/locale-ja.m4: Likewise. * m4/locale-tr.m4: Likewise. * m4/locale-zh.m4: Likewise. * m4/printf.m4: Likewise. * tests/test-cloexec.c: Likewise. * tests/test-copy-acl.sh: Likewise. * tests/test-copy-file.sh: Likewise. * tests/test-file-has-acl.sh: Likewise. * tests/test-set-mode-acl.sh: Likewise. * tests/test-dup-safer.c: Likewise. * tests/test-dup2.c: Likewise. * tests/test-dup3.c: Likewise. * tests/test-fcntl.c: Likewise. * tests/test-nonblocking-pipe.h: Likewise. * tests/test-nonblocking-socket.h: Likewise. * tests/test-pipe.c: Likewise. * tests/test-pipe2.c: Likewise. * tests/test-spawn-pipe-child.c: Likewise. * doc/acl-resources.txt: Likewise. * lib/getaddrinfo.c (WINDOWS_NATIVE): Renamed from WIN32_NATIVE. * tests/test-poll.c (WINDOWS_NATIVE): Likewise. * tests/test-select.h (WINDOWS_NATIVE): Likewise. * lib/localcharset.c: Update comments to mention native Windows. (WINDOWS_NATIVE): Renamed from WIN32_NATIVE. * lib/localename.c: Likewise. * lib/progreloc.c: Likewise. * lib/relocatable.c: Likewise. * lib/poll.c (WINDOWS_NATIVE): Renamed from WIN32_NATIVE. (windows_compute_revents): Renamed from win32_compute_revents. (windows_compute_revents_socket): Renamed from win32_compute_revents_socket. * lib/select.c: Update comments to mention native Windows. (windows_poll_handle): Renamed from win32_poll_handle. * m4/threadlib.m4: Update comments to mention native Windows. (gl_THREADLIB_EARLY_BODY, gl_THREADLIB_BODY): Expect --enable-threads=windows instead of --enable-threads=win32. Set USE_WINDOWS_THREADS, not USE_WIN32_THREADS. * lib/glthread/lock.h: Update comments to mention native Windows. (USE_WINDOWS_THREADS): Renamed from USE_WIN32_THREADS. * lib/glthread/lock.c (USE_WINDOWS_THREADS): Renamed from USE_WIN32_THREADS. * lib/glthread/cond.h (USE_WINDOWS_THREADS): Likewise. * lib/glthread/cond.c (USE_WINDOWS_THREADS): Likewise. * lib/glthread/thread.h (USE_WINDOWS_THREADS): Likewise. * lib/glthread/thread.c (USE_WINDOWS_THREADS): Likewise. * lib/glthread/tls.h (USE_WINDOWS_THREADS): Likewise. * lib/glthread/tls.c (USE_WINDOWS_THREADS): Likewise. * lib/glthread/yield.h (USE_WINDOWS_THREADS): Likewise. * tests/test-cond.c (USE_WINDOWS_THREADS): Likewise. * tests/test-thread_create.c (USE_WINDOWS_THREADS): Likewise. * tests/test-lock.c (USE_WINDOWS_THREADS): Likewise. (TEST_WINDOWS_THREADS): Renamed from TEST_WIN32_THREADS. * tests/test-tls.c: Likewise. Rationale: Microsoft renamed the "Win32 API" to "Windows API", as it is available on both 32-bit and 64-bit Windows systems. But in gnulib, we treat Cygwin like a Unix platform, therefore the main line of distinction is between "native Windows" on one side and Unix/ POSIX systems on the other side. More details in <https://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00027.html>. Suggested by Paul Eggert.
author Bruno Haible <bruno@clisp.org>
date Wed, 04 Jan 2012 14:31:33 +0100
parents 8250f2777afc
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 15534
diff changeset
1 /* Copyright (C) 1999, 2001-2002, 2006, 2009-2012 Free Software Foundation,
12559
c2cbabec01dd update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents: 12518
diff changeset
2 Inc.
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 This file is part of the GNU C Library.
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7588
diff changeset
5 This program is free software: you can redistribute it and/or modify
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 7043
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7588
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7588
diff changeset
8 (at your option) any later version.
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 7043
diff changeset
10 This program is distributed in the hope that it will be useful,
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 7043
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 7043
diff changeset
13 GNU General Public License for more details.
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
7139
adb21c293305 Add copyright notices to long-enough files that lack them, since
Paul Eggert <eggert@cs.ucla.edu>
parents: 7043
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7588
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Extracted from sysdeps/posix/tempname.c. */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
7304
1c4ed7637c24 Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 7139
diff changeset
20 #include <config.h>
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 /* Specification. */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include "tmpdir.h"
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdbool.h>
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdlib.h>
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <string.h>
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <errno.h>
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #ifndef __set_errno
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 # define __set_errno(Val) errno = (Val)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #endif
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include <stdio.h>
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #ifndef P_tmpdir
15534
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
36 # ifdef _P_tmpdir /* native Windows */
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
37 # define P_tmpdir _P_tmpdir
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
38 # else
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
39 # define P_tmpdir "/tmp"
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
40 # endif
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #endif
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #include <sys/stat.h>
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
15534
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
45 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
46 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
47 # include <windows.h>
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
48 #endif
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
49
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
50 #include "pathmax.h"
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
51
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 #if _LIBC
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 # define struct_stat64 struct stat64
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 #else
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 # define struct_stat64 struct stat
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 # define __xstat64(version, path, buf) stat (path, buf)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 #endif
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 #if ! (HAVE___SECURE_GETENV || _LIBC)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 # define __secure_getenv getenv
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 #endif
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* Pathname support.
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 ISSLASH(C) tests whether C is a directory separator character.
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
16214
ec738d6aeef5 Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
67 /* Native Windows, Cygwin, OS/2, DOS */
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 # define ISSLASH(C) ((C) == '/' || (C) == '\\')
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 #else
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 /* Unix */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 # define ISSLASH(C) ((C) == '/')
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 #endif
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 /* Return nonzero if DIR is an existent directory. */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 static bool
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 direxists (const char *dir)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 {
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 struct_stat64 buf;
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 }
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 /* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 non-null and exists, uses it; otherwise uses the first of $TMPDIR,
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 for use with mk[s]temp. Will fail (-1) if DIR is non-null and
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 doesn't exist, none of the searched dirs exists, or there's not
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 enough space in TMPL. */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 int
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
91 bool try_tmpdir)
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 {
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 const char *d;
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 size_t dlen, plen;
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 if (!pfx || !pfx[0])
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 {
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 pfx = "file";
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 plen = 4;
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 else
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 plen = strlen (pfx);
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 if (plen > 5)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
105 plen = 5;
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 }
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 if (try_tmpdir)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 {
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 d = __secure_getenv ("TMPDIR");
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 if (d != NULL && direxists (d))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
112 dir = d;
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 else if (dir != NULL && direxists (dir))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
114 /* nothing */ ;
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
116 dir = NULL;
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 }
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 if (dir == NULL)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 {
15534
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
120 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
121 char dirbuf[PATH_MAX];
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
122 DWORD retval;
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
123
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
124 /* Find Windows temporary file directory.
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
125 We try this before P_tmpdir because Windows defines P_tmpdir to "\\"
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
126 and will therefore try to put all temporary files in the root
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
127 directory (unless $TMPDIR is set). */
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
128 retval = GetTempPath (PATH_MAX, dirbuf);
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
129 if (retval > 0 && retval < PATH_MAX && direxists (dirbuf))
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
130 dir = dirbuf;
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
131 else
3ef509e539a1 tmpdir: Use a good default directory on native Windows.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
132 #endif
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 if (direxists (P_tmpdir))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
134 dir = P_tmpdir;
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
136 dir = "/tmp";
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
138 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
139 __set_errno (ENOENT);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
140 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
141 }
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 }
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 dlen = strlen (dir);
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 while (dlen >= 1 && ISSLASH (dir[dlen - 1]))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
146 dlen--; /* remove trailing slashes */
7043
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 /* check we have room for "${dir}/${pfx}XXXXXX\0" */
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 if (tmpl_len < dlen + 1 + plen + 6 + 1)
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 {
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 __set_errno (EINVAL);
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 return -1;
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 }
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx);
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 return 0;
4f84bccd7da0 New module 'tmpdir'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 }