ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/paths.h
Revision: 2.27
Committed: Sun Mar 6 01:13:17 2016 UTC (8 years, 2 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.26: +5 -3 lines
Log Message:
Prepare for SCons build on Win32 and Win64

File Contents

# User Rev Content
1 schorsch 2.27 /* RCSid $Id: paths.h,v 2.26 2016/02/03 22:41:35 greg Exp $ */
2 greg 2.1 /*
3     * Definitions for paths on different machines
4 greg 2.9 */
5 schorsch 2.12 #ifndef _RAD_PATHS_H_
6     #define _RAD_PATHS_H_
7 greg 2.1
8 schorsch 2.16 #include <stdio.h>
9 schorsch 2.13 #include <stdlib.h>
10     #include <string.h>
11 schorsch 2.17 #include <fcntl.h>
12     #include <sys/types.h>
13     #include <sys/stat.h>
14 schorsch 2.16
15 schorsch 2.27 #if defined(_WIN32) || defined(_WIN64)
16 schorsch 2.14 #include <io.h>
17 schorsch 2.22 #include <direct.h> /* getcwd(), chdir(), _mkdir(), etc. */
18 schorsch 2.27 #define getcwd _getcwd
19     #define chdir _chdir
20 greg 2.1
21 greg 2.25 #define access _access
22     #define mkdir(dirname,perms) _mkdir(dirname)
23     #ifdef _MSC_VER
24     #define popen(cmd,mode) _popen(cmd,mode)
25     #define pclose(p) _pclose(p)
26     #else
27     #define popen(cmd,mode) win_popen(cmd,mode)
28     #define pclose(p) win_pclose(p)
29     #endif
30     #define kill(pid,sig) win_kill(pid,sig)
31     #define nice(inc) win_nice(inc)
32 greg 2.26 #define PATH_MAX _MAX_PATH
33 greg 2.25 #define NULL_DEVICE "NUL"
34 schorsch 2.14 #define DIRSEP '/'
35 greg 2.25 #define ISDIRSEP(c) (((c)=='/') | ((c)=='\\'))
36     #define ISABS(s) ( ISDIRSEP((s)[0]) \
37 greg 2.24 || ( isupper((s)[0]) | islower((s)[0]) \
38     && (s)[1]==':' && ISDIRSEP((s)[2]) ) )
39 greg 2.25 #define CASEDIRSEP case '/': case '\\'
40 schorsch 2.14 #define PATHSEP ';'
41     #define CURDIR '.'
42 greg 2.25 #define DEFAULT_TEMPDIRS {"C:/TMP", "C:/TEMP", ".", NULL}
43     #define TEMPLATE "rtXXXXXX"
44 schorsch 2.14 #define TEMPLEN 8
45     #define ULIBVAR "RAYPATH"
46     #ifndef DEFPATH
47     #define DEFPATH ";c:/ray/lib"
48     #endif
49 greg 2.25 #define SPECIALS " \t\"$*?|"
50     #define QUOTCHAR '"'
51 schorsch 2.14 /* <io.h> only does half the work for access() */
52     #ifndef F_OK
53     #define F_OK 00
54     #define W_OK 02
55 greg 2.23 #endif
56     #ifndef R_OK
57     #define X_OK 01
58     #define R_OK 04
59 schorsch 2.14 #endif
60 schorsch 2.17 /* to make the permissions user specific we'd need to use CreateFile() */
61     #ifndef S_IRUSR
62     #define S_IRUSR _S_IREAD
63     #define S_IWUSR _S_IWRITE
64     #endif
65 schorsch 2.19
66 schorsch 2.16 #else /* everything but Windows */
67     #include <unistd.h>
68     #include <sys/param.h>
69    
70     #define RMAX_PATH_MAX 4096 /* our own maximum */
71     #ifndef PATH_MAX
72     #define PATH_MAX 512
73     #elif PATH_MAX > RMAX_PATH_MAX /* the OS is exaggerating */
74     #undef PATH_MAX
75     #define PATH_MAX RMAX_PATH_MAX
76 schorsch 2.14 #endif
77    
78     #ifdef AMIGA
79    
80 schorsch 2.20 #define NULL_DEVICE "NIL:"
81 schorsch 2.14 #define DIRSEP '/'
82 greg 2.24 #define ISABS(s) ISDIRSEP((s)[0])
83 schorsch 2.14 #define PATHSEP ';'
84     #define CURDIR '.'
85 greg 2.25 #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}
86     #define TEMPLATE "/tmp/rtXXXXXX"
87 schorsch 2.14 #define TEMPLEN 13
88     #define ULIBVAR "RAYPATH"
89     #ifndef DEFPATH
90     #define DEFPATH ";/ray/lib"
91     #endif
92     #define fixargv0(a0) (a0)
93    
94     #else
95    
96 schorsch 2.16 /* posix */
97    
98     /* this is defined as _PATH_DEVNULL in /usr/include/paths.h on Linux */
99     #define NULL_DEVICE "/dev/null"
100 schorsch 2.14 #define DIRSEP '/'
101 greg 2.24 #define ISABS(s) ISDIRSEP((s)[0])
102 schorsch 2.14 #define PATHSEP ':'
103     #define CURDIR '.'
104 greg 2.25 #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}
105     #define TEMPLATE "/tmp/rtXXXXXX"
106 schorsch 2.14 #define TEMPLEN 17
107     #define ULIBVAR "RAYPATH"
108     #ifndef DEFPATH
109     #define DEFPATH ":/usr/local/lib/ray"
110     #endif
111 greg 2.25 #define SPECIALS " \t\n'\"()${}*?[];|&"
112     #define QUOTCHAR '\''
113     #define ALTQUOT '"'
114 schorsch 2.14 #define fixargv0(a0) (a0)
115 greg 2.1
116 schorsch 2.14 #endif
117 greg 2.2 #endif
118    
119     #ifndef ISDIRSEP
120 schorsch 2.14 #define ISDIRSEP(c) ((c)==DIRSEP)
121 greg 2.2 #endif
122     #ifndef CASEDIRSEP
123 schorsch 2.14 #define CASEDIRSEP case DIRSEP
124 greg 2.1 #endif
125    
126 schorsch 2.19 #ifdef __cplusplus
127     extern "C" {
128     #endif
129 schorsch 2.13
130 schorsch 2.27 #if defined(_WIN32) || defined(_WIN64)
131 greg 2.25 extern FILE *win_popen(char *command, char *type);
132     extern int win_pclose(FILE *p);
133     extern char *fixargv0();
134     #endif
135    
136     /* Check if any of the characters in str2 are found in str1 */
137     extern int matchany(const char *str1, const char *str2);
138    
139     /* Convert a set of arguments into a command line for pipe() or system() */
140     extern char *convert_commandline(char *cmd, const int len, char *av[]);
141    
142 schorsch 2.13 /* Find a writeable directory for temporary files */
143     /* If s is NULL, we return a static string */
144     extern char *temp_directory(char *s, size_t len);
145    
146     /* Compose a *currently* unique name within a temporary directory */
147     /* If s is NULL, we return a static string */
148     /* If templ is NULL, we take our default template */
149     /* WARNING: On Windows, there's a maximum of 27 unique names within
150     one process for the same template. */
151     extern char *temp_filename(char *s, size_t len, char *templ);
152    
153     /* Same as above, but also open the file and return the descriptor */
154     /* This one is supposed to protect against race conditions on unix */
155     /* WARNING: On Windows, there's no protection against race conditions */
156 schorsch 2.16 extern int temp_fd(char *s, size_t len, char *templ);
157    
158     /* Same as above, but return a file pointer instead of a descriptor */
159     extern FILE *temp_fp(char *s, size_t len, char *templ);
160 schorsch 2.13
161     /* Concatenate two strings, leaving exactly one DIRSEP in between */
162     extern char *append_filepath(char *s1, char *s2, size_t len);
163 schorsch 2.12
164    
165     #ifdef __cplusplus
166     }
167     #endif
168     #endif /* _RAD_PATHS_H_ */
169