2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tpath.c,v 1.8 2006-04-26 10:01:31 adam Exp $
9 * \brief File Path utilities
20 #include <yaz/tpath.h>
22 #include <sys/types.h>
30 FILE *yaz_path_fopen(const char *path, const char *name, const char *mode)
32 return yaz_fopen (path, name, mode, 0);
35 int yaz_fclose (FILE *f)
41 char *yaz_filepath_resolve(const char *fname, const char *path,
42 const char *base, char *fullpath)
47 const char *path_sep = 0;
54 /* somewhat dirty since we have to consider Windows
57 if (strchr ("/\\.", *path))
59 path_sep = strchr (path+1, ':');
61 else if (path[0] && path[1])
62 path_sep = strchr (path+2, ':');
64 len = path_sep - path;
67 if (!strchr ("/\\", *path) && base)
69 strcpy (fullpath, base);
70 slen = strlen(fullpath);
71 fullpath[slen++] = '/';
73 memcpy (fullpath+slen, path, len);
75 if (!strchr("/\\", fullpath[slen-1]))
76 fullpath[slen++] = '/';
78 strcpy (fullpath+slen, fname);
80 if (stat(fullpath, &stat_buf) == 0)
90 FILE *yaz_fopen(const char *path, const char *fname, const char *mode,
95 if (!yaz_filepath_resolve(fname, path, base, fullpath))
96 return 0; /* failure */
97 return fopen(fullpath, mode);
100 int yaz_is_abspath (const char *p)
107 if (*p && p[1] == ':' && isalpha(*p))
115 * indent-tabs-mode: nil
117 * vim: shiftwidth=4 tabstop=8 expandtab