Back to index

radiance  4R0+20100331
Defines | Functions
paths.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/param.h>

Go to the source code of this file.

Defines

#define RMAX_PATH_MAX   4096 /* our own maximum */
#define PATH_MAX   512
#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"
#define DEFPATH   ":/usr/local/lib/ray"
#define fixargv0(a0)   (a0)
#define ISDIRSEP(c)   ((c)==DIRSEP)
#define CASEDIRSEP   case DIRSEP

Functions

char * temp_directory (char *s, size_t len)
char * temp_filename (char *s, size_t len, char *templ)
int temp_fd (char *s, size_t len, char *templ)
FILE * temp_fp (char *s, size_t len, char *templ)
char * append_filepath (char *s1, char *s2, size_t len)

Define Documentation

#define CASEDIRSEP   case DIRSEP

Definition at line 116 of file paths.h.

#define CURDIR   '.'

Definition at line 99 of file paths.h.

#define DEFAULT_TEMPDIRS   {"/var/tmp", "/usr/tmp", "/tmp", ".", NULL}

Definition at line 100 of file paths.h.

#define DEFPATH   ":/usr/local/lib/ray"

Definition at line 105 of file paths.h.

#define DIRSEP   '/'

Definition at line 96 of file paths.h.

#define fixargv0 (   a0)    (a0)

Definition at line 107 of file paths.h.

#define ISABS (   s)    ((s)!=NULL && (ISDIRSEP(s[0])))

Definition at line 97 of file paths.h.

#define ISDIRSEP (   c)    ((c)==DIRSEP)

Definition at line 113 of file paths.h.

#define NULL_DEVICE   "/dev/null"

Definition at line 95 of file paths.h.

#define PATH_MAX   512

Definition at line 68 of file paths.h.

#define PATHSEP   ':'

Definition at line 98 of file paths.h.

#define RMAX_PATH_MAX   4096 /* our own maximum */

Definition at line 66 of file paths.h.

#define TEMPLATE   "/tmp/rtXXXXXX"

Definition at line 101 of file paths.h.

#define TEMPLEN   17

Definition at line 102 of file paths.h.

#define ULIBVAR   "RAYPATH"

Definition at line 103 of file paths.h.


Function Documentation

char* append_filepath ( char *  s1,
char *  s2,
size_t  len 
)

Definition at line 72 of file paths.c.

{
       size_t siz;
       char *s;

       siz = strlen(s1);
       if (siz > 0) {
              /* XXX siz > len is an error */
              while (siz > 1 && ISDIRSEP(s1[siz-1])) {
                     s1[siz-1] = '\0';
                     siz--;
              }
              if (siz+1 <= len) {
                     s1[siz] = DIRSEP;
                     siz++;
              }
       } else if (len >= 2) { /* first path empty */
              s1[0] = CURDIR;
              s1[1] = DIRSEP;
              siz = 2;
       } else {
              return NULL;
       }
       while (ISDIRSEP(s2[0])) {
              s2++;
       }
       s = strncat(s1, s2, len-siz);
       return s;
}

Here is the caller graph for this function:

char* temp_directory ( char *  s,
size_t  len 
)

Definition at line 22 of file paths.c.

{
       static char td[PATH_MAX]; /* remember */
       char * ts = NULL;
       int i = 0;
       
       if (td[0] != '\0') { /* we already have one */
              if (s == NULL) { return td; }
              strncpy(s, td, len);
              s[len-1] = '\0';
              return s;
       }
       /* check where TMP and TEMP point to */
       ts = getenv("TMP");
       if (ts != NULL && access(ts, W_OK) == 0) {
              strncpy(td, ts, sizeof(td));
              td[sizeof(td)-1] = '\0';
       }
       if (ts == NULL) {
              ts = getenv("TEMP");
              if (ts != NULL && access(ts, W_OK) == 0) {
                     strncpy(td, ts, sizeof(td));
                     td[sizeof(td)-1] = '\0';
              }
       }
       /* check the platform specific default paths in order */
       while (ts == NULL) {
              if (defaultpaths[i] == NULL) {
                     break;
              }
              if (access(defaultpaths[i], W_OK) == 0) {
                     ts = strncpy(td, defaultpaths[i], sizeof(td));
                     td[sizeof(td)-1] = '\0';
                     break;
              }
              i++;
       }
       /* we found something */
       if (ts != NULL) {
              if (s == NULL) { return td; }
              strncpy(s, ts, len);
              s[len-1] = '\0';
              return s;
       }
       return NULL;
}

Here is the caller graph for this function:

int temp_fd ( char *  s,
size_t  len,
char *  templ 
)

Definition at line 146 of file paths.c.

{
       char *ts = NULL;

       ts = prepare_tmpname(s, len, templ);
       if (ts == NULL) return -1;
#ifdef _WIN32
       ts = mktemp(ts);
       if (ts == NULL) return -1;
       return open(ts, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
#else
       return mkstemp(ts);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* temp_filename ( char *  s,
size_t  len,
char *  templ 
)

Definition at line 128 of file paths.c.

{
       char *ts = NULL;

       ts = prepare_tmpname(s, len, templ);
       if (ts == NULL) { return NULL; }
       return mktemp(ts);
}

Here is the call graph for this function:

FILE* temp_fp ( char *  s,
size_t  len,
char *  templ 
)

Definition at line 163 of file paths.c.

{
       int fd = temp_fd(s, len, templ);
       if (fd < 0) return NULL;
       return fdopen(fd, "w+");
}

Here is the call graph for this function: