X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Ftpath.c;h=1f3751476c03842b4413d99044131b9d94e420df;hp=ec4e981d70741145951f76bb7a838312da594e39;hb=e437c49e5b848a38b8dd0913da4c79828c60af18;hpb=3ffa5dbc563e15bccb012f3d3d00a993f87ace82 diff --git a/util/tpath.c b/util/tpath.c index ec4e981..1f37514 100644 --- a/util/tpath.c +++ b/util/tpath.c @@ -1,37 +1,76 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-2000, 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 + * Revision 1.5 2000-12-05 19:03:19 adam + * WIN32 fixes for drive specifications. + * + * Revision 1.4 2000/02/29 13:44:55 adam + * Check for config.h (currently not generated). + * + * Revision 1.3 1999/11/30 13:47:12 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.2 1996/10/29 13:36:26 adam + * Added header. + * + * Revision 1.1 1995/11/01 16:35:00 quinn * Making data1 look for tables in data1_tabpath * * */ +#if HAVE_CONFIG_H +#include +#endif #include #include +#include -FILE *yaz_path_fopen(char *path, char *name, char *mode) +FILE *yaz_path_fopen(const char *path, const char *name, const char *mode) { - char spath[512] = ""; - - if (!path) - return fopen(name, mode); + char spath[512]; - do + for(;;) { FILE *f; - if (sscanf(path, "%511[^:]", spath) < 1) - return 0; - sprintf(spath + strlen(spath), "/%s", name); + const char *path_sep = 0; + size_t len = 0; + + if (path) + { + /* somewhat dirty since we have to consider Windows + * drive letters.. + */ + if (strchr ("/\\.", *path)) + { + path_sep = strchr (path+1, ':'); + } + else if (path[0] && path[1]) + path_sep = strchr (path+2, ':'); + if (path_sep) + len = path_sep - path; + else + len = strlen(path); + if (len > 255) + len = 255; + memcpy (spath, path, len); + if (!strchr("/\\", spath[len-1])) + { + strcpy (spath+len, "/"); + len++; + } + } + sprintf (spath+len, "%.255s", name); if ((f = fopen(spath, mode))) return f; - if ((path = strchr(path, ':'))) - path++; + + if (!path_sep) + break; + path = path_sep+1; } - while (path); return 0; }