Back to index

radiance  4R0+20100331
paths.h
Go to the documentation of this file.
00001 /* RCSid $Id: paths.h,v 2.22 2005/09/19 11:30:10 schorsch Exp $ */
00002 /*
00003  * Definitions for paths on different machines
00004  */
00005 #ifndef _RAD_PATHS_H_
00006 #define _RAD_PATHS_H_
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include <fcntl.h>
00012 #include <sys/types.h>
00013 #include <sys/stat.h>
00014 
00015 #ifdef _WIN32
00016   #include <io.h>
00017   #include <direct.h> /* getcwd(), chdir(), _mkdir(), etc. */
00018 
00019   #define access _access
00020   #define mkdir(dirname,perms) _mkdir(dirname)
00021   #define PATH_MAX _MAX_PATH
00022   #define NULL_DEVICE       "NUL"
00023   #define DIRSEP            '/'
00024   #define ISDIRSEP(c)       ((c)=='/' || (c)=='\\')
00025   #define ISABS(s)   ((s)!=NULL \
00026                 && (s[0])!='\0' \
00027           && (   ISDIRSEP(s[0]) \
00028               || (   (s[1])!='\0' \
00029                   && (isupper(s[0])||islower(s[0])) \
00030                   && (s[1])==':')))
00031   #define CASEDIRSEP case '/': case '\\'
00032   #define PATHSEP           ';'
00033   #define CURDIR            '.'
00034   #define DEFAULT_TEMPDIRS {"C:/TMP", "C:/TEMP", ".", NULL}
00035   #define TEMPLATE   "rtXXXXXX"
00036   #define TEMPLEN           8
00037   #define ULIBVAR           "RAYPATH"
00038   #ifndef DEFPATH
00039     #define DEFPATH         ";c:/ray/lib"
00040   #endif
00041   /* <io.h> only does half the work for access() */
00042   #ifndef F_OK
00043     #define  F_OK 00
00044     #define  X_OK 01
00045     #define  W_OK 02
00046     #define  R_OK 04
00047   #endif
00048   /* to make the permissions user specific we'd need to use CreateFile() */
00049   #ifndef S_IRUSR
00050     #define S_IRUSR _S_IREAD
00051     #define S_IWUSR _S_IWRITE
00052   #endif
00053 
00054   #ifdef __cplusplus
00055     extern "C" {
00056   #endif
00057   extern char  *fixargv0();
00058   #ifdef __cplusplus
00059     }
00060   #endif
00061 
00062 #else /* everything but Windows */
00063   #include <unistd.h>
00064   #include <sys/param.h>
00065 
00066   #define RMAX_PATH_MAX 4096 /* our own maximum */
00067   #ifndef PATH_MAX
00068     #define PATH_MAX 512
00069   #elif PATH_MAX > RMAX_PATH_MAX /* the OS is exaggerating */
00070     #undef PATH_MAX
00071     #define PATH_MAX RMAX_PATH_MAX
00072   #endif
00073 
00074   #ifdef AMIGA
00075 
00076        #define NULL_DEVICE  "NIL:"
00077     #define DIRSEP          '/'
00078     #define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0])))
00079     #define PATHSEP         ';'
00080        #define CURDIR              '.'
00081     #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}
00082     #define TEMPLATE "/tmp/rtXXXXXX"
00083     #define TEMPLEN         13
00084     #define ULIBVAR         "RAYPATH"
00085     #ifndef DEFPATH
00086       #define DEFPATH              ";/ray/lib"
00087     #endif
00088     #define    fixargv0(a0) (a0)
00089 
00090   #else
00091 
00092     /* posix */
00093 
00094        /* this is defined as _PATH_DEVNULL in /usr/include/paths.h on Linux */
00095        #define NULL_DEVICE  "/dev/null"
00096     #define DIRSEP          '/'
00097     #define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0])))
00098     #define PATHSEP         ':'
00099        #define CURDIR              '.'
00100     #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}
00101     #define TEMPLATE "/tmp/rtXXXXXX"
00102     #define TEMPLEN         17
00103     #define ULIBVAR         "RAYPATH"
00104     #ifndef DEFPATH
00105       #define DEFPATH              ":/usr/local/lib/ray"
00106     #endif
00107     #define    fixargv0(a0) (a0)
00108 
00109   #endif
00110 #endif
00111 
00112 #ifndef ISDIRSEP
00113   #define ISDIRSEP(c)       ((c)==DIRSEP)
00114 #endif
00115 #ifndef CASEDIRSEP
00116   #define CASEDIRSEP case DIRSEP
00117 #endif
00118 
00119 #ifdef __cplusplus
00120 extern "C" {
00121 #endif
00122 
00123 /* Find a writeable directory for temporary files */
00124 /* If s is NULL, we return a static string */
00125 extern char *temp_directory(char *s, size_t len);
00126 
00127 /* Compose a *currently* unique name within a temporary directory */
00128 /* If s is NULL, we return a static string */
00129 /* If templ is NULL, we take our default template */
00130 /* WARNING: On Windows, there's a maximum of 27 unique names within
00131             one process for the same template. */
00132 extern char *temp_filename(char *s, size_t len, char *templ);
00133 
00134 /* Same as above, but also open the file and return the descriptor */
00135 /* This one is supposed to protect against race conditions on unix */
00136 /* WARNING: On Windows, there's no protection against race conditions */
00137 extern int temp_fd(char *s, size_t len, char *templ);
00138 
00139 /* Same as above, but return a file pointer instead of a descriptor */
00140 extern FILE *temp_fp(char *s, size_t len, char *templ);
00141 
00142 /* Concatenate two strings, leaving exactly one DIRSEP in between */
00143 extern char *append_filepath(char *s1, char *s2, size_t len);
00144 
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif
00149 #endif /* _RAD_PATHS_H_ */
00150