03dd264eafdaa2f8d226d4b44db5751b9201f357
[yaz-moved-to-github.git] / util / tpath.c
1 /*
2  * Copyright (c) 1995, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: tpath.c,v $
7  * Revision 1.3  1999-11-30 13:47:12  adam
8  * Improved installation. Moved header files to include/yaz.
9  *
10  * Revision 1.2  1996/10/29 13:36:26  adam
11  * Added header.
12  *
13  * Revision 1.1  1995/11/01 16:35:00  quinn
14  * Making data1 look for tables in data1_tabpath
15  *
16  *
17  */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <yaz/tpath.h>
22
23 FILE *yaz_path_fopen(const char *path, const char *name, const char *mode)
24 {
25     char spath[512] = "";
26
27     if (!path)
28         return fopen(name, mode);
29
30     do
31     {
32         FILE *f;
33
34         if (sscanf(path, "%511[^:]", spath) < 1)
35             return 0;
36         sprintf(spath + strlen(spath), "/%s", name);
37         if ((f = fopen(spath, mode)))
38             return f;
39         if ((path = strchr(path, ':')))
40             path++;
41     }
42     while (path);
43     return 0;
44 }