2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
8 #pragma ident "%Z%%M% %I% %E% SMI"
13 static const char sccsid
[] = "@(#)os_tmpdir.c 10.3 (Sleepycat) 10/13/98";
16 #ifndef NO_SYSTEM_INCLUDES
17 #include <sys/types.h>
24 #include "common_ext.h"
27 #include <TFileSpec.h>
32 * Set the temporary directory path.
34 * The order of items in the list structure and the order of checks in
35 * the environment are documented.
37 * PUBLIC: int __os_tmpdir __P((DB_ENV *, u_int32_t));
40 __os_tmpdir(dbenv
, flags
)
46 * Don't change this to:
48 * static const char * const list[]
50 * because it creates a text relocation in position independent code.
52 static const char * list
[] = {
55 "/temp", /* Windows. */
57 "C:/temp", /* Windows. */
58 "C:/tmp", /* Windows. */
61 const char * const *lp
, *p
;
63 /* Use the environment if it's permitted and initialized. */
66 if (LF_ISSET(DB_USE_ENVIRON
) ||
67 (LF_ISSET(DB_USE_ENVIRON_ROOT
) && getuid() == 0))
69 if (LF_ISSET(DB_USE_ENVIRON
))
72 if ((p
= getenv("TMPDIR")) != NULL
&& p
[0] == '\0') {
73 __db_err(dbenv
, "illegal TMPDIR environment variable");
77 if (p
== NULL
&& (p
= getenv("TEMP")) != NULL
&& p
[0] == '\0') {
78 __db_err(dbenv
, "illegal TEMP environment variable");
82 if (p
== NULL
&& (p
= getenv("TMP")) != NULL
&& p
[0] == '\0') {
83 __db_err(dbenv
, "illegal TMP environment variable");
88 (p
= getenv("TempFolder")) != NULL
&& p
[0] == '\0') {
90 "illegal TempFolder environment variable");
96 /* Get the path to the temporary folder. */
100 if (!Special2FSSpec(kTemporaryFolderType
,
101 kOnSystemDisk
, 0, &spec
))
102 (void)__os_strdup(FSp2FullPath(&spec
), &p
);
106 /* Step through the list looking for a possibility. */
108 for (lp
= list
; *lp
!= NULL
; ++lp
)
109 if (__os_exists(p
= *lp
, NULL
) == 0)
114 return (__os_strdup(p
, &dbenv
->db_tmp_dir
));