2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tpath.c,v 1.9 2006-04-27 08:39:05 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 (strchr ("/\\.", *path))
57 path_sep = strchr (path+1, ':');
59 else if (path[0] && path[1])
60 path_sep = strchr (path+2, ':');
62 len = path_sep - path;
65 if (!strchr ("/\\", *path) && base)
67 strcpy (fullpath, base);
68 slen = strlen(fullpath);
69 fullpath[slen++] = '/';
71 memcpy (fullpath+slen, path, len);
73 if (!strchr("/\\", fullpath[slen-1]))
74 fullpath[slen++] = '/';
76 strcpy (fullpath+slen, fname);
78 if (stat(fullpath, &stat_buf) == 0)
88 FILE *yaz_fopen(const char *path, const char *fname, const char *mode,
93 if (!yaz_filepath_resolve(fname, path, base, fullpath))
94 return 0; /* failure */
95 return fopen(fullpath, mode);
98 int yaz_is_abspath (const char *p)
105 if (*p && p[1] == ':' && isalpha(*p))
113 * indent-tabs-mode: nil
115 * vim: shiftwidth=4 tabstop=8 expandtab