Update.
[glibc.git] / db2 / os / os_tmpdir.c
blob0b0bbc7c614dc7d3acc47203f83d128cd96f549a
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_tmpdir.c 10.3 (Sleepycat) 10/13/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
17 #include <errno.h>
18 #include <stdlib.h>
19 #endif
21 #include "db_int.h"
22 #include "common_ext.h"
24 #ifdef macintosh
25 #include <TFileSpec.h>
26 #endif
29 * __os_tmpdir --
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));
37 int
38 __os_tmpdir(dbenv, flags)
39 DB_ENV *dbenv;
40 u_int32_t flags;
43 * !!!
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[] = {
51 "/var/tmp",
52 "/usr/tmp",
53 "/temp", /* Windows. */
54 "/tmp",
55 "C:/temp", /* Windows. */
56 "C:/tmp", /* Windows. */
57 NULL
59 const char * const *lp, *p;
61 /* Use the environment if it's permitted and initialized. */
62 p = NULL;
63 #ifdef HAVE_GETEUID
64 if (LF_ISSET(DB_USE_ENVIRON) ||
65 (LF_ISSET(DB_USE_ENVIRON_ROOT) && getuid() == 0))
66 #else
67 if (LF_ISSET(DB_USE_ENVIRON))
68 #endif
70 if ((p = getenv("TMPDIR")) != NULL && p[0] == '\0') {
71 __db_err(dbenv, "illegal TMPDIR environment variable");
72 return (EINVAL);
74 /* Windows */
75 if (p == NULL && (p = getenv("TEMP")) != NULL && p[0] == '\0') {
76 __db_err(dbenv, "illegal TEMP environment variable");
77 return (EINVAL);
79 /* Windows */
80 if (p == NULL && (p = getenv("TMP")) != NULL && p[0] == '\0') {
81 __db_err(dbenv, "illegal TMP environment variable");
82 return (EINVAL);
84 /* Macintosh */
85 if (p == NULL &&
86 (p = getenv("TempFolder")) != NULL && p[0] == '\0') {
87 __db_err(dbenv,
88 "illegal TempFolder environment variable");
89 return (EINVAL);
93 #ifdef macintosh
94 /* Get the path to the temporary folder. */
95 if (p == NULL) {
96 FSSpec spec;
98 if (!Special2FSSpec(kTemporaryFolderType,
99 kOnSystemDisk, 0, &spec))
100 (void)__os_strdup(FSp2FullPath(&spec), &p);
102 #endif
104 /* Step through the list looking for a possibility. */
105 if (p == NULL)
106 for (lp = list; *lp != NULL; ++lp)
107 if (__os_exists(p = *lp, NULL) == 0)
108 break;
109 if (p == NULL)
110 return (0);
112 return (__os_strdup(p, &dbenv->db_tmp_dir));