summaryrefslogtreecommitdiff
path: root/graphics/pstex/fopenp.org
blob: 46e082b409705a9b422fc3aa4adf99c1aa468b76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Fopenp function.
 *
 * Neil Hunt (Neil%Teleos.com@ai.sri.com)
 *
 * Copyright (c) 1989 Teleos Research, Inc 1989.
 * Copyright (c) 1988 Schlumberger Technologies, Inc 1988.
 *
 * Anyone can use this software in any manner they choose,
 * including modification and redistribution, provided they make
 * no charge for it, and these conditions remain unchanged.
 *
 * This program is distributed as is, with all faults (if any), and
 * without any warranty. No author or distributor accepts responsibility
 * to anyone for the consequences of using it, or for whether it serves any
 * particular purpose at all, or any other reason.
 *
 * $Log:	fopenp.c,v $
 * Revision 1.1  89/02/10  18:40:39  neil
 * Initial revision
 * 
 * Copied from newlib.
 * Revision 1.2  88/09/19  18:29:53  hunt
 * Fixed typo.
 * 
 * Revision 1.1  88/09/19  15:52:47  hunt
 * Initial revision
 */

static char rcsid[] = "$Revision: 1.1 $";

#include <stdio.h>
#include "std.h"

FILE *
fopenp(path, name, fullname, mode)
char *path;
char *name;
char *fullname;
char *mode;
{
	register char *p;
	register FILE *f;

	if(*name == '/')
	{
		strcpy(fullname, name);
		return fopen(fullname, mode);
	}

	while(*path)
	{
		/*
		 * Copy first/next path prefix to fullname.
		 * Skip over the ':'.
		 * Add the '/'.
		 * Concat the filename.
		 */
		for(p = fullname; *path != '\0'; )
		{
			if(*path == ':' || *path == ';')
			{
				path++;
				break;
			}
			else
				*p++ = *path++;
		}
		*p++ = '/';
		strcpy(p, name);

		/*
		 * Try to open the file.
		 */
		if((f = fopen(fullname, mode)) != (FILE *)NULL)
			return f;
	}

	return (FILE *)NULL;
}