ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fropen.c
Revision: 2.14
Committed: Tue Aug 26 04:24:26 2003 UTC (20 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 2.13: +2 -3 lines
Log Message:
Minor improvements

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.14 static const char RCSid[] = "$Id: fropen.c,v 2.13 2003/07/17 09:21:29 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * Find and open a Radiance library file.
6 greg 2.8 *
7 greg 2.14 * External symbols declared in rtio.h
8 greg 2.8 */
9    
10 greg 2.9 #include "copyright.h"
11 greg 1.1
12     #include <stdio.h>
13    
14 schorsch 2.13 #include "rtio.h"
15 greg 2.4 #include "paths.h"
16 greg 1.1
17    
18     FILE *
19 greg 2.7 frlibopen(fname) /* find file and open for reading */
20 greg 1.1 register char *fname;
21     {
22     FILE *fp;
23 schorsch 2.11 char pname[PATH_MAX];
24 greg 1.1 register char *sp, *cp;
25    
26     if (fname == NULL)
27     return(NULL);
28    
29 greg 2.5 if (ISDIRSEP(fname[0]) || fname[0] == '.') /* absolute path */
30 greg 1.1 return(fopen(fname, "r"));
31     /* check search path */
32 greg 2.10 sp = getrlibpath();
33 greg 1.1 do {
34     cp = pname;
35 greg 2.3 while (*sp && (*cp = *sp++) != PATHSEP)
36     cp++;
37 greg 2.5 if (cp > pname && !ISDIRSEP(cp[-1]))
38 greg 2.3 *cp++ = DIRSEP;
39 greg 1.1 strcpy(cp, fname);
40     if ((fp = fopen(pname, "r")) != NULL)
41     return(fp); /* got it! */
42     } while (*sp);
43     /* not found */
44     return(NULL);
45     }