--- ray/src/common/paths.h 2003/02/22 02:07:22 2.9
+++ ray/src/common/paths.h 2005/09/19 11:30:10 2.22
@@ -1,122 +1,150 @@
-/* RCSid: $Id: paths.h,v 2.9 2003/02/22 02:07:22 greg Exp $ */
+/* RCSid $Id: paths.h,v 2.22 2005/09/19 11:30:10 schorsch Exp $ */
/*
* Definitions for paths on different machines
*/
+#ifndef _RAD_PATHS_H_
+#define _RAD_PATHS_H_
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * Copyright (c) 1990 - 2002 The Regents of the University of California,
- * through Lawrence Berkeley National Laboratory. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes Radiance software
- * (http://radsite.lbl.gov/)
- * developed by the Lawrence Berkeley National Laboratory
- * (http://www.lbl.gov/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
- * and "The Regents of the University of California" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact radiance@radsite.lbl.gov.
- *
- * 5. Products derived from this software may not be called "Radiance",
- * nor may "Radiance" appear in their name, without prior written
- * permission of Lawrence Berkeley National Laboratory.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of Lawrence Berkeley National Laboratory. For more
- * information on Lawrence Berkeley National Laboratory, please see
- * .
- */
+#include
+#include
+#include
+#include
+#include
+#include
-#ifdef MSDOS
+#ifdef _WIN32
+ #include
+ #include /* getcwd(), chdir(), _mkdir(), etc. */
-#define DIRSEP '/'
-#define ISDIRSEP(c) ((c)=='/' || (c)=='\\')
-#define CASEDIRSEP case '/': case '\\'
-#define PATHSEP ';'
-#define MAXPATH 128
-#define TEMPLATE "rtXXXXXX"
-#define TEMPLEN 8
-#define ULIBVAR "RAYPATH"
-#ifndef DEFPATH
-#define DEFPATH ";c:/ray/lib"
-#endif
-extern char *fixargv0();
+ #define access _access
+ #define mkdir(dirname,perms) _mkdir(dirname)
+ #define PATH_MAX _MAX_PATH
+ #define NULL_DEVICE "NUL"
+ #define DIRSEP '/'
+ #define ISDIRSEP(c) ((c)=='/' || (c)=='\\')
+ #define ISABS(s) ((s)!=NULL \
+ && (s[0])!='\0' \
+ && ( ISDIRSEP(s[0]) \
+ || ( (s[1])!='\0' \
+ && (isupper(s[0])||islower(s[0])) \
+ && (s[1])==':')))
+ #define CASEDIRSEP case '/': case '\\'
+ #define PATHSEP ';'
+ #define CURDIR '.'
+ #define DEFAULT_TEMPDIRS {"C:/TMP", "C:/TEMP", ".", NULL}
+ #define TEMPLATE "rtXXXXXX"
+ #define TEMPLEN 8
+ #define ULIBVAR "RAYPATH"
+ #ifndef DEFPATH
+ #define DEFPATH ";c:/ray/lib"
+ #endif
+ /* only does half the work for access() */
+ #ifndef F_OK
+ #define F_OK 00
+ #define X_OK 01
+ #define W_OK 02
+ #define R_OK 04
+ #endif
+ /* to make the permissions user specific we'd need to use CreateFile() */
+ #ifndef S_IRUSR
+ #define S_IRUSR _S_IREAD
+ #define S_IWUSR _S_IWRITE
+ #endif
-#else
-#ifdef AMIGA
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ extern char *fixargv0();
+ #ifdef __cplusplus
+ }
+ #endif
-#define DIRSEP '/'
-#define PATHSEP ';'
-#define MAXPATH 128
-#define TEMPLATE "/tmp/rtXXXXXX"
-#define TEMPLEN 13
-#define ULIBVAR "RAYPATH"
-#ifndef DEFPATH
-#define DEFPATH ";/ray/lib"
-#endif
-#define fixargv0(a0) (a0)
+#else /* everything but Windows */
+ #include
+ #include
-#else
+ #define RMAX_PATH_MAX 4096 /* our own maximum */
+ #ifndef PATH_MAX
+ #define PATH_MAX 512
+ #elif PATH_MAX > RMAX_PATH_MAX /* the OS is exaggerating */
+ #undef PATH_MAX
+ #define PATH_MAX RMAX_PATH_MAX
+ #endif
-#define DIRSEP '/'
-#define PATHSEP ':'
-#define MAXPATH 256
-#define TEMPLATE "/usr/tmp/rtXXXXXX"
-#define TEMPLEN 17
-#define ULIBVAR "RAYPATH"
-#ifndef DEFPATH
-#define DEFPATH ":/usr/local/lib/ray"
-#endif
-#define fixargv0(a0) (a0)
+ #ifdef AMIGA
+ #define NULL_DEVICE "NIL:"
+ #define DIRSEP '/'
+ #define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0])))
+ #define PATHSEP ';'
+ #define CURDIR '.'
+ #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}
+ #define TEMPLATE "/tmp/rtXXXXXX"
+ #define TEMPLEN 13
+ #define ULIBVAR "RAYPATH"
+ #ifndef DEFPATH
+ #define DEFPATH ";/ray/lib"
+ #endif
+ #define fixargv0(a0) (a0)
+
+ #else
+
+ /* posix */
+
+ /* this is defined as _PATH_DEVNULL in /usr/include/paths.h on Linux */
+ #define NULL_DEVICE "/dev/null"
+ #define DIRSEP '/'
+ #define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0])))
+ #define PATHSEP ':'
+ #define CURDIR '.'
+ #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}
+ #define TEMPLATE "/tmp/rtXXXXXX"
+ #define TEMPLEN 17
+ #define ULIBVAR "RAYPATH"
+ #ifndef DEFPATH
+ #define DEFPATH ":/usr/local/lib/ray"
+ #endif
+ #define fixargv0(a0) (a0)
+
+ #endif
#endif
-#endif
#ifndef ISDIRSEP
-#define ISDIRSEP(c) ((c)==DIRSEP)
+ #define ISDIRSEP(c) ((c)==DIRSEP)
#endif
#ifndef CASEDIRSEP
-#define CASEDIRSEP case DIRSEP
+ #define CASEDIRSEP case DIRSEP
#endif
-extern char *mktemp(), *getenv();
+#ifdef __cplusplus
+extern "C" {
+#endif
-#ifdef BSD
-extern char *getwd();
-#else
-extern char *getcwd();
-#define getwd(p) getcwd(p, sizeof(p))
+/* Find a writeable directory for temporary files */
+/* If s is NULL, we return a static string */
+extern char *temp_directory(char *s, size_t len);
+
+/* Compose a *currently* unique name within a temporary directory */
+/* If s is NULL, we return a static string */
+/* If templ is NULL, we take our default template */
+/* WARNING: On Windows, there's a maximum of 27 unique names within
+ one process for the same template. */
+extern char *temp_filename(char *s, size_t len, char *templ);
+
+/* Same as above, but also open the file and return the descriptor */
+/* This one is supposed to protect against race conditions on unix */
+/* WARNING: On Windows, there's no protection against race conditions */
+extern int temp_fd(char *s, size_t len, char *templ);
+
+/* Same as above, but return a file pointer instead of a descriptor */
+extern FILE *temp_fp(char *s, size_t len, char *templ);
+
+/* Concatenate two strings, leaving exactly one DIRSEP in between */
+extern char *append_filepath(char *s1, char *s2, size_t len);
+
+
+#ifdef __cplusplus
+}
#endif
+#endif /* _RAD_PATHS_H_ */
+