X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftpath.c;h=9dd863727b2b96878e47b57848e9dc9e2e2af7d5;hb=83800da8ab73064cd1031adb7f44d07691f95d55;hp=7aa41ccbd747f3f939e35f02c4c43d613bd7b152;hpb=e4060b606fade264168221db5e3782d321f6918a;p=yaz-moved-to-github.git diff --git a/src/tpath.c b/src/tpath.c index 7aa41cc..9dd8637 100644 --- a/src/tpath.c +++ b/src/tpath.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: tpath.c,v 1.8 2006-04-26 10:01:31 adam Exp $ + * $Id: tpath.c,v 1.11 2006-06-08 20:55:38 adam Exp $ */ /** * \file tpath.c @@ -20,9 +20,7 @@ #include #include #include -#if HAVE_SYS_STAT_H #include -#endif #if HAVE_UNISTD_H #include #endif @@ -47,36 +45,39 @@ char *yaz_filepath_resolve(const char *fname, const char *path, const char *path_sep = 0; size_t len = 0; size_t slen = 0; - + *fullpath = '\0'; if (path) { /* somewhat dirty since we have to consider Windows * drive letters.. */ - if (strchr ("/\\.", *path)) - { + if (path[0] && strchr ("/\\.", *path)) path_sep = strchr (path+1, ':'); - } else if (path[0] && path[1]) path_sep = strchr (path+2, ':'); + else + path_sep = 0; + if (path_sep) len = path_sep - path; else len = strlen(path); + /* is path is relative and base is to be used */ if (!strchr ("/\\", *path) && base) { + /* yes: make base the first part */ strcpy (fullpath, base); slen = strlen(fullpath); fullpath[slen++] = '/'; } - memcpy (fullpath+slen, path, len); + if (len) + memcpy (fullpath+slen, path, len); slen += len; - if (!strchr("/\\", fullpath[slen-1])) + if (slen > 0 && !strchr("/\\", fullpath[slen-1])) fullpath[slen++] = '/'; } strcpy (fullpath+slen, fname); - if (stat(fullpath, &stat_buf) == 0) return fullpath;