Making data1 look for tables in data1_tabpath
[yaz-moved-to-github.git] / util / tpath.c
diff --git a/util/tpath.c b/util/tpath.c
new file mode 100644 (file)
index 0000000..ec4e981
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1995, Index Data.
+ * See the file LICENSE for details.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: tpath.c,v $
+ * Revision 1.1  1995-11-01 16:35:00  quinn
+ * Making data1 look for tables in data1_tabpath
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+FILE *yaz_path_fopen(char *path, char *name, char *mode)
+{
+    char spath[512] = "";
+
+    if (!path)
+       return fopen(name, mode);
+
+    do
+    {
+       FILE *f;
+
+       if (sscanf(path, "%511[^:]", spath) < 1)
+           return 0;
+       sprintf(spath + strlen(spath), "/%s", name);
+       if ((f = fopen(spath, mode)))
+           return f;
+       if ((path = strchr(path, ':')))
+           path++;
+    }
+    while (path);
+    return 0;
+}