From d3a6e1e7f5f661593507deecd86bc72c869d19c8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 5 Dec 2000 19:03:19 +0000 Subject: [PATCH] WIN32 fixes for drive specifications. --- util/tpath.c | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/util/tpath.c b/util/tpath.c index 380ed25..1f37514 100644 --- a/util/tpath.c +++ b/util/tpath.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: tpath.c,v $ - * Revision 1.4 2000-02-29 13:44:55 adam + * 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 @@ -28,23 +31,46 @@ 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; } -- 1.7.10.4