2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tpath.c,v 1.11 2006-06-08 20:55:38 adam Exp $
9 * \brief File Path utilities
20 #include <yaz/tpath.h>
22 #include <sys/types.h>
28 FILE *yaz_path_fopen(const char *path, const char *name, const char *mode)
30 return yaz_fopen (path, name, mode, 0);
33 int yaz_fclose (FILE *f)
39 char *yaz_filepath_resolve(const char *fname, const char *path,
40 const char *base, char *fullpath)
45 const char *path_sep = 0;
52 /* somewhat dirty since we have to consider Windows
55 if (path[0] && strchr ("/\\.", *path))
56 path_sep = strchr (path+1, ':');
57 else if (path[0] && path[1])
58 path_sep = strchr (path+2, ':');
63 len = path_sep - path;
66 /* is path is relative and base is to be used */
67 if (!strchr ("/\\", *path) && base)
69 /* yes: make base the first part */
70 strcpy (fullpath, base);
71 slen = strlen(fullpath);
72 fullpath[slen++] = '/';
75 memcpy (fullpath+slen, path, len);
77 if (slen > 0 && !strchr("/\\", fullpath[slen-1]))
78 fullpath[slen++] = '/';
80 strcpy (fullpath+slen, fname);
81 if (stat(fullpath, &stat_buf) == 0)
91 FILE *yaz_fopen(const char *path, const char *fname, const char *mode,
96 if (!yaz_filepath_resolve(fname, path, base, fullpath))
97 return 0; /* failure */
98 return fopen(fullpath, mode);
101 int yaz_is_abspath (const char *p)
108 if (*p && p[1] == ':' && isalpha(*p))
116 * indent-tabs-mode: nil
118 * vim: shiftwidth=4 tabstop=8 expandtab