--- ray/src/common/paths.h 2003/06/26 00:58:09 2.14 +++ ray/src/common/paths.h 2012/06/29 23:09:06 2.24 @@ -1,40 +1,33 @@ -/* RCSid $Id: paths.h,v 2.14 2003/06/26 00:58:09 schorsch Exp $ */ +/* RCSid $Id: paths.h,v 2.24 2012/06/29 23:09:06 greg Exp $ */ /* * Definitions for paths on different machines */ #ifndef _RAD_PATHS_H_ #define _RAD_PATHS_H_ -#ifdef __cplusplus -extern "C" { -#endif -#include "copyright.h" - +#include #include #include +#include +#include +#include + #ifdef _WIN32 #include -#else /* _WIN32 */ - #include - #include -#endif /* _WIN32 */ + #include /* getcwd(), chdir(), _mkdir(), etc. */ -#ifdef _WIN32 - #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 ISDIRSEP(c) (((c)=='/') | ((c)=='\\')) + #define ISABS(s) ( ISDIRSEP((s)[0]) \ + || ( isupper((s)[0]) | islower((s)[0]) \ + && (s)[1]==':' && ISDIRSEP((s)[2]) ) ) #define CASEDIRSEP case '/': case '\\' #define PATHSEP ';' #define CURDIR '.' - #define MAXPATH 512 /* XXX obsoleted by posix PATH_MAX */ #define DEFAULT_TEMPDIRS {"C:/TMP", "C:/TEMP", ".", NULL} #define TEMPLATE "rtXXXXXX" #define TEMPLEN 8 @@ -45,24 +38,45 @@ extern "C" { /* 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 -extern char *fixargv0(); + #ifndef R_OK + #define X_OK 01 + #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 - #ifndef PATH_MAX /* doesn't implement posix? */ - #define PATH_MAX 512 /* quite conservative (I think...) */ + #ifdef __cplusplus + extern "C" { #endif + extern char *fixargv0(); + #ifdef __cplusplus + } + #endif +#else /* everything but Windows */ + #include + #include + + #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 + #ifdef AMIGA + #define NULL_DEVICE "NIL:" #define DIRSEP '/' - #define ISABS(s) ((s)!=NULL && (ISDIRSEP(s[0]))) + #define ISABS(s) ISDIRSEP((s)[0]) #define PATHSEP ';' #define CURDIR '.' - #define MAXPATH 128 #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL} #define TEMPLATE "/tmp/rtXXXXXX" #define TEMPLEN 13 @@ -74,13 +88,16 @@ extern char *fixargv0(); #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 ISABS(s) ISDIRSEP((s)[0]) #define PATHSEP ':' #define CURDIR '.' - #define MAXPATH 256 #define DEFAULT_TEMPDIRS {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL} - #define TEMPLATE "/usr/tmp/rtXXXXXX" + #define TEMPLATE "/tmp/rtXXXXXX" #define TEMPLEN 17 #define ULIBVAR "RAYPATH" #ifndef DEFPATH @@ -98,16 +115,10 @@ extern char *fixargv0(); #define CASEDIRSEP case DIRSEP #endif -extern char *mktemp(), *getenv(); - -#ifdef BSD -extern char *getwd(); -#else -extern char *getcwd(); -#define getwd(p) getcwd(p, sizeof(p)) +#ifdef __cplusplus +extern "C" { #endif - /* 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); @@ -122,7 +133,10 @@ extern char *temp_filename(char *s, size_t len, char * /* 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_file(char *s, size_t len, char *templ); +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);