2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)os_tmpdir.c 10.3 (Sleepycat) 10/13/98";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
22 #include "common_ext.h"
25 #include <TFileSpec.h>
30 * Set the temporary directory path.
32 * The order of items in the list structure and the order of checks in
33 * the environment are documented.
35 * PUBLIC: int __os_tmpdir __P((DB_ENV *, u_int32_t));
38 __os_tmpdir(dbenv
, flags
)
44 * Don't change this to:
46 * static const char * const list[]
48 * because it creates a text relocation in position independent code.
50 static const char * list
[] = {
53 "/temp", /* Windows. */
55 "C:/temp", /* Windows. */
56 "C:/tmp", /* Windows. */
59 const char * const *lp
, *p
;
61 /* Use the environment if it's permitted and initialized. */
64 if (LF_ISSET(DB_USE_ENVIRON
) ||
65 (LF_ISSET(DB_USE_ENVIRON_ROOT
) && getuid() == 0))
67 if (LF_ISSET(DB_USE_ENVIRON
))
70 if ((p
= getenv("TMPDIR")) != NULL
&& p
[0] == '\0') {
71 __db_err(dbenv
, "illegal TMPDIR environment variable");
75 if (p
== NULL
&& (p
= getenv("TEMP")) != NULL
&& p
[0] == '\0') {
76 __db_err(dbenv
, "illegal TEMP environment variable");
80 if (p
== NULL
&& (p
= getenv("TMP")) != NULL
&& p
[0] == '\0') {
81 __db_err(dbenv
, "illegal TMP environment variable");
86 (p
= getenv("TempFolder")) != NULL
&& p
[0] == '\0') {
88 "illegal TempFolder environment variable");
94 /* Get the path to the temporary folder. */
98 if (!Special2FSSpec(kTemporaryFolderType
,
99 kOnSystemDisk
, 0, &spec
))
100 (void)__os_strdup(FSp2FullPath(&spec
), &p
);
104 /* Step through the list looking for a possibility. */
106 for (lp
= list
; *lp
!= NULL
; ++lp
)
107 if (__os_exists(p
= *lp
, NULL
) == 0)
112 return (__os_strdup(p
, &dbenv
->db_tmp_dir
));