1N/A/*-
1N/A * See the file LICENSE for redistribution information.
1N/A *
1N/A * Copyright (c) 1998
1N/A * Sleepycat Software. All rights reserved.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include "config.h"
1N/A
1N/A#ifndef lint
1N/Astatic const char sccsid[] = "@(#)os_tmpdir.c 10.3 (Sleepycat) 10/13/98";
1N/A#endif /* not lint */
1N/A
1N/A#ifndef NO_SYSTEM_INCLUDES
1N/A#include <sys/types.h>
1N/A
1N/A#include <errno.h>
1N/A#include <stdlib.h>
1N/A#endif
1N/A
1N/A#include "db_int.h"
1N/A#include "common_ext.h"
1N/A
1N/A#ifdef macintosh
1N/A#include <TFileSpec.h>
1N/A#endif
1N/A
1N/A/*
1N/A * __os_tmpdir --
1N/A * Set the temporary directory path.
1N/A *
1N/A * The order of items in the list structure and the order of checks in
1N/A * the environment are documented.
1N/A *
1N/A * PUBLIC: int __os_tmpdir __P((DB_ENV *, u_int32_t));
1N/A */
1N/Aint
1N/A__os_tmpdir(dbenv, flags)
1N/A DB_ENV *dbenv;
1N/A u_int32_t flags;
1N/A{
1N/A /*
1N/A * !!!
1N/A * Don't change this to:
1N/A *
1N/A * static const char * const list[]
1N/A *
1N/A * because it creates a text relocation in position independent code.
1N/A */
1N/A static const char * list[] = {
1N/A "/var/tmp",
1N/A "/usr/tmp",
1N/A "/temp", /* Windows. */
1N/A "/tmp",
1N/A "C:/temp", /* Windows. */
1N/A "C:/tmp", /* Windows. */
1N/A NULL
1N/A };
1N/A const char * const *lp, *p;
1N/A
1N/A /* Use the environment if it's permitted and initialized. */
1N/A p = NULL;
1N/A#ifdef HAVE_GETEUID
1N/A if (LF_ISSET(DB_USE_ENVIRON) ||
1N/A (LF_ISSET(DB_USE_ENVIRON_ROOT) && getuid() == 0))
1N/A#else
1N/A if (LF_ISSET(DB_USE_ENVIRON))
1N/A#endif
1N/A {
1N/A if ((p = getenv("TMPDIR")) != NULL && p[0] == '\0') {
1N/A __db_err(dbenv, "illegal TMPDIR environment variable");
1N/A return (EINVAL);
1N/A }
1N/A /* Windows */
1N/A if (p == NULL && (p = getenv("TEMP")) != NULL && p[0] == '\0') {
1N/A __db_err(dbenv, "illegal TEMP environment variable");
1N/A return (EINVAL);
1N/A }
1N/A /* Windows */
1N/A if (p == NULL && (p = getenv("TMP")) != NULL && p[0] == '\0') {
1N/A __db_err(dbenv, "illegal TMP environment variable");
1N/A return (EINVAL);
1N/A }
1N/A /* Macintosh */
1N/A if (p == NULL &&
1N/A (p = getenv("TempFolder")) != NULL && p[0] == '\0') {
1N/A __db_err(dbenv,
1N/A "illegal TempFolder environment variable");
1N/A return (EINVAL);
1N/A }
1N/A }
1N/A
1N/A#ifdef macintosh
1N/A /* Get the path to the temporary folder. */
1N/A if (p == NULL) {
1N/A FSSpec spec;
1N/A
1N/A if (!Special2FSSpec(kTemporaryFolderType,
1N/A kOnSystemDisk, 0, &spec))
1N/A (void)__os_strdup(FSp2FullPath(&spec), &p);
1N/A }
1N/A#endif
1N/A
1N/A /* Step through the list looking for a possibility. */
1N/A if (p == NULL)
1N/A for (lp = list; *lp != NULL; ++lp)
1N/A if (__os_exists(p = *lp, NULL) == 0)
1N/A break;
1N/A if (p == NULL)
1N/A return (0);
1N/A
1N/A return (__os_strdup(p, &dbenv->db_tmp_dir));
1N/A}