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