1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.16 |
static const char RCSid[] = "$Id: fropen.c,v 2.15 2012/06/29 23:09:06 greg 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.16 |
frlibopen( /* find file and open for reading */ |
20 |
|
|
char *fname |
21 |
|
|
) |
22 |
greg |
1.1 |
{ |
23 |
|
|
FILE *fp; |
24 |
schorsch |
2.11 |
char pname[PATH_MAX]; |
25 |
greg |
2.16 |
char *sp, *cp; |
26 |
greg |
1.1 |
|
27 |
|
|
if (fname == NULL) |
28 |
|
|
return(NULL); |
29 |
|
|
|
30 |
greg |
2.15 |
if (ISABS(fname) || fname[0] == '.') /* absolute path */ |
31 |
greg |
1.1 |
return(fopen(fname, "r")); |
32 |
|
|
/* check search path */ |
33 |
greg |
2.10 |
sp = getrlibpath(); |
34 |
greg |
1.1 |
do { |
35 |
|
|
cp = pname; |
36 |
greg |
2.3 |
while (*sp && (*cp = *sp++) != PATHSEP) |
37 |
|
|
cp++; |
38 |
greg |
2.5 |
if (cp > pname && !ISDIRSEP(cp[-1])) |
39 |
greg |
2.3 |
*cp++ = DIRSEP; |
40 |
greg |
1.1 |
strcpy(cp, fname); |
41 |
|
|
if ((fp = fopen(pname, "r")) != NULL) |
42 |
|
|
return(fp); /* got it! */ |
43 |
|
|
} while (*sp); |
44 |
|
|
/* not found */ |
45 |
|
|
return(NULL); |
46 |
|
|
} |