Back to index

radiance  4R0+20100331
fropen.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: fropen.c,v 2.14 2003/08/26 04:24:26 greg Exp $";
00003 #endif
00004 /*
00005  * Find and open a Radiance library file.
00006  *
00007  *  External symbols declared in rtio.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include <stdio.h>
00013 
00014 #include "rtio.h"
00015 #include "paths.h"
00016 
00017 
00018 FILE *
00019 frlibopen(fname)            /* find file and open for reading */
00020 register char  *fname;
00021 {
00022        FILE  *fp;
00023        char  pname[PATH_MAX];
00024        register char  *sp, *cp;
00025 
00026        if (fname == NULL)
00027               return(NULL);
00028 
00029        if (ISDIRSEP(fname[0]) || fname[0] == '.')       /* absolute path */
00030               return(fopen(fname, "r"));
00031                                           /* check search path */
00032        sp = getrlibpath();
00033        do {
00034               cp = pname;
00035               while (*sp && (*cp = *sp++) != PATHSEP)
00036                      cp++;
00037               if (cp > pname && !ISDIRSEP(cp[-1]))
00038                      *cp++ = DIRSEP;
00039               strcpy(cp, fname);
00040               if ((fp = fopen(pname, "r")) != NULL)
00041                      return(fp);                 /* got it! */
00042        } while (*sp);
00043                                           /* not found */
00044        return(NULL);
00045 }