4 |
|
*/ |
5 |
|
#ifndef _RAD_PATHS_H_ |
6 |
|
#define _RAD_PATHS_H_ |
7 |
– |
#ifdef __cplusplus |
8 |
– |
extern "C" { |
9 |
– |
#endif |
7 |
|
|
8 |
+ |
#include <stdio.h> |
9 |
|
#include <stdlib.h> |
10 |
|
#include <string.h> |
11 |
+ |
#include <fcntl.h> |
12 |
+ |
#include <sys/types.h> |
13 |
+ |
#include <sys/stat.h> |
14 |
+ |
|
15 |
|
#ifdef _WIN32 |
16 |
|
#include <io.h> |
17 |
< |
#else /* _WIN32 */ |
16 |
< |
#include <unistd.h> |
17 |
< |
#include <sys/param.h> |
18 |
< |
#endif /* _WIN32 */ |
17 |
> |
#include <direct.h> /* getcwd(), chdir(), _mkdir(), etc. */ |
18 |
|
|
20 |
– |
#ifdef _WIN32 |
21 |
– |
|
19 |
|
#define access _access |
20 |
+ |
#define mkdir(dirname,perms) _mkdir(dirname) |
21 |
|
#define PATH_MAX _MAX_PATH |
22 |
+ |
#define NULL_DEVICE "NUL" |
23 |
|
#define DIRSEP '/' |
24 |
< |
#define ISDIRSEP(c) ((c)=='/' || (c)=='\\') |
25 |
< |
#define ISABS(s) ((s)!=NULL \ |
26 |
< |
&& (s[0])!='\0' \ |
27 |
< |
&& ( ISDIRSEP(s[0]) \ |
29 |
< |
|| ( (s[1])!='\0' \ |
30 |
< |
&& (isupper(s[0])||islower(s[0])) \ |
31 |
< |
&& (s[1])==':'))) |
24 |
> |
#define ISDIRSEP(c) (((c)=='/') | ((c)=='\\')) |
25 |
> |
#define ISABS(s) ( ISDIRSEP((s)[0]) \ |
26 |
> |
|| ( isupper((s)[0]) | islower((s)[0]) \ |
27 |
> |
&& (s)[1]==':' && ISDIRSEP((s)[2]) ) ) |
28 |
|
#define CASEDIRSEP case '/': case '\\' |
29 |
|
#define PATHSEP ';' |
30 |
|
#define CURDIR '.' |
35 |
– |
#define MAXPATH 512 /* XXX obsoleted by posix PATH_MAX */ |
31 |
|
#define DEFAULT_TEMPDIRS {"C:/TMP", "C:/TEMP", ".", NULL} |
32 |
|
#define TEMPLATE "rtXXXXXX" |
33 |
|
#define TEMPLEN 8 |
38 |
|
/* <io.h> only does half the work for access() */ |
39 |
|
#ifndef F_OK |
40 |
|
#define F_OK 00 |
46 |
– |
#define X_OK 01 |
41 |
|
#define W_OK 02 |
48 |
– |
#define R_OK 04 |
42 |
|
#endif |
43 |
< |
extern char *fixargv0(); |
43 |
> |
#ifndef R_OK |
44 |
> |
#define X_OK 01 |
45 |
> |
#define R_OK 04 |
46 |
> |
#endif |
47 |
> |
/* to make the permissions user specific we'd need to use CreateFile() */ |
48 |
> |
#ifndef S_IRUSR |
49 |
> |
#define S_IRUSR _S_IREAD |
50 |
> |
#define S_IWUSR _S_IWRITE |
51 |
> |
#endif |
52 |
|
|
53 |
< |
#else |
54 |
< |
#ifndef PATH_MAX /* doesn't implement posix? */ |
54 |
< |
#define PATH_MAX 512 /* quite conservative (I think...) */ |
53 |
> |
#ifdef __cplusplus |
54 |
> |
extern "C" { |
55 |
|
#endif |
56 |
+ |
extern char *fixargv0(); |
57 |
+ |
#ifdef __cplusplus |
58 |
+ |
} |
59 |
+ |
#endif |
60 |
|
|
61 |
+ |
#else /* everything but Windows */ |
62 |
+ |
#include <unistd.h> |
63 |
+ |
#include <sys/param.h> |
64 |
+ |
|
65 |
+ |
#define RMAX_PATH_MAX 4096 /* our own maximum */ |
66 |
+ |
#ifndef PATH_MAX |
67 |
+ |
#define PATH_MAX 512 |
68 |
+ |
#elif PATH_MAX > RMAX_PATH_MAX /* the OS is exaggerating */ |
69 |
+ |
#undef PATH_MAX |
70 |
+ |
#define PATH_MAX RMAX_PATH_MAX |
71 |
+ |
#endif |
72 |
+ |
|
73 |
|
#ifdef AMIGA |
74 |
|
|
75 |
+ |
#define NULL_DEVICE "NIL:" |
76 |
|
#define DIRSEP '/' |
77 |
< |
#define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0]))) |
77 |
> |
#define ISABS(s) ISDIRSEP((s)[0]) |
78 |
|
#define PATHSEP ';' |
79 |
|
#define CURDIR '.' |
63 |
– |
#define MAXPATH 128 |
80 |
|
#define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL} |
81 |
|
#define TEMPLATE "/tmp/rtXXXXXX" |
82 |
|
#define TEMPLEN 13 |
88 |
|
|
89 |
|
#else |
90 |
|
|
91 |
+ |
/* posix */ |
92 |
+ |
|
93 |
+ |
/* this is defined as _PATH_DEVNULL in /usr/include/paths.h on Linux */ |
94 |
+ |
#define NULL_DEVICE "/dev/null" |
95 |
|
#define DIRSEP '/' |
96 |
< |
#define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0]))) |
96 |
> |
#define ISABS(s) ISDIRSEP((s)[0]) |
97 |
|
#define PATHSEP ':' |
98 |
|
#define CURDIR '.' |
79 |
– |
#define MAXPATH 256 |
99 |
|
#define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL} |
100 |
< |
#define TEMPLATE "/usr/tmp/rtXXXXXX" |
100 |
> |
#define TEMPLATE "/tmp/rtXXXXXX" |
101 |
|
#define TEMPLEN 17 |
102 |
|
#define ULIBVAR "RAYPATH" |
103 |
|
#ifndef DEFPATH |
115 |
|
#define CASEDIRSEP case DIRSEP |
116 |
|
#endif |
117 |
|
|
118 |
< |
extern char *mktemp(), *getenv(); |
119 |
< |
|
101 |
< |
#ifdef BSD |
102 |
< |
extern char *getwd(); |
103 |
< |
#else |
104 |
< |
extern char *getcwd(); |
105 |
< |
#define getwd(p) getcwd(p, sizeof(p)) |
118 |
> |
#ifdef __cplusplus |
119 |
> |
extern "C" { |
120 |
|
#endif |
121 |
|
|
108 |
– |
|
122 |
|
/* Find a writeable directory for temporary files */ |
123 |
|
/* If s is NULL, we return a static string */ |
124 |
|
extern char *temp_directory(char *s, size_t len); |
133 |
|
/* Same as above, but also open the file and return the descriptor */ |
134 |
|
/* This one is supposed to protect against race conditions on unix */ |
135 |
|
/* WARNING: On Windows, there's no protection against race conditions */ |
136 |
< |
extern int temp_file(char *s, size_t len, char *templ); |
136 |
> |
extern int temp_fd(char *s, size_t len, char *templ); |
137 |
> |
|
138 |
> |
/* Same as above, but return a file pointer instead of a descriptor */ |
139 |
> |
extern FILE *temp_fp(char *s, size_t len, char *templ); |
140 |
|
|
141 |
|
/* Concatenate two strings, leaving exactly one DIRSEP in between */ |
142 |
|
extern char *append_filepath(char *s1, char *s2, size_t len); |