db

os_tmpdir.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1998, 1999, 2000
00005  * Sleepycat Software. All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__tmpdir_8c-source.html,v 1.1 2008年06月08日 10:21:33 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <errno.h>
00018 #include <stdlib.h>
00019 #endif
00020 
00021 #include "db_int.h"
00022 
00023 #ifdef macintosh
00024 #include <TFileSpec.h>
00025 #endif
00026 
00027 /*
00028  * CDB___os_tmpdir --
00029  * Set the temporary directory path.
00030  *
00031  * The order of items in the list structure and the order of checks in
00032  * the environment are documented.
00033  *
00034  * PUBLIC: int CDB___os_tmpdir __P((DB_ENV *, u_int32_t));
00035  */
00036 int
00037 CDB___os_tmpdir(dbenv, flags)
00038 DB_ENV *dbenv;
00039 u_int32_t flags;
00040 {
00041 /*
00042  * !!!
00043  * Don't change this to:
00044  *
00045  * static const char * const list[]
00046  *
00047  * because it creates a text relocation in position independent code.
00048  */
00049 static const char * list[] = {
00050 "/var/tmp",
00051 "/usr/tmp",
00052 "/temp", /* Windows. */
00053 "/tmp",
00054 "C:/temp", /* Windows. */
00055 "C:/tmp", /* Windows. */
00056 NULL
00057 };
00058 const char * const *lp, *p;
00059 
00060 /* Use the environment if it's permitted and initialized. */
00061 if (LF_ISSET(DB_USE_ENVIRON) ||
00062 (LF_ISSET(DB_USE_ENVIRON_ROOT) && CDB___os_isroot() == 0)) {
00063 if ((p = getenv("TMPDIR")) != NULL && p[0] == '0円') {
00064 CDB___db_err(dbenv, "illegal TMPDIR environment variable");
00065 return (EINVAL);
00066 }
00067 /* Windows */
00068 if (p == NULL && (p = getenv("TEMP")) != NULL && p[0] == '0円') {
00069 CDB___db_err(dbenv, "illegal TEMP environment variable");
00070 return (EINVAL);
00071 }
00072 /* Windows */
00073 if (p == NULL && (p = getenv("TMP")) != NULL && p[0] == '0円') {
00074 CDB___db_err(dbenv, "illegal TMP environment variable");
00075 return (EINVAL);
00076 }
00077 /* Macintosh */
00078 if (p == NULL &&
00079 (p = getenv("TempFolder")) != NULL && p[0] == '0円') {
00080 CDB___db_err(dbenv,
00081 "illegal TempFolder environment variable");
00082 return (EINVAL);
00083 }
00084 if (p != NULL)
00085 return (CDB___os_strdup(dbenv, p, &dbenv->db_tmp_dir));
00086 }
00087 
00088 #ifdef macintosh
00089 /* Get the path to the temporary folder. */
00090 {FSSpec spec;
00091 
00092 if (!Special2FSSpec(kTemporaryFolderType,
00093 kOnSystemDisk, 0, &spec))
00094 return (CDB___os_strdup(dbenv,
00095 FSp2FullPath(&spec), &dbenv->db_tmp_dir));
00096 }
00097 #endif
00098 #ifdef _WIN32
00099 /* Get the path to the temporary directory. */
00100 {int len;
00101 char temp[_MAX_PATH + 1];
00102 char *eos;
00103 int isdir;
00104 
00105 if ((len = GetTempPath(sizeof(temp) - 1, temp)) > 2) {
00106 eos = &temp[len];
00107 *eos-- = '0円';
00108 if (*eos == '\\' || *eos == '/')
00109 *eos = '0円';
00110 if (CDB___os_exists(temp, &isdir) == 0 && isdir != 0)
00111 return (CDB___os_strdup(dbenv, temp, &dbenv->db_tmp_dir));
00112 }
00113 }
00114 #endif
00115 
00116 /* Step through the static list looking for a possibility. */
00117 for (lp = list; *lp != NULL; ++lp)
00118 if (CDB___os_exists(*lp, NULL) == 0)
00119 return (CDB___os_strdup(dbenv, *lp, &dbenv->db_tmp_dir));
00120 return (0);
00121 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by doxygen 1.5.5

AltStyle によって変換されたページ (->オリジナル) /