dnl YAZ Toolkit, Index Data 1994-2006
dnl See the file LICENSE for details.
-dnl $Id: configure.ac,v 1.8 2006-04-20 11:56:20 adam Exp $
+dnl $Id: configure.ac,v 1.9 2006-04-26 09:40:42 adam Exp $
AC_PREREQ(2.59)
-AC_INIT([yaz],[2.1.18],[adam@indexdata.dk])
+AC_INIT([yaz],[2.1.19],[adam@indexdata.dk])
AC_CONFIG_SRCDIR(configure.ac)
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE([1.8])
dh_fixperms
# dh_perl
# dh_python
- dh_makeshlibs -V 'libyaz (>= 2.1.18)'
+ dh_makeshlibs -V 'libyaz (>= 2.1.19)'
dh_installdeb
dh_shlibdeps -l debian/libyaz/usr/lib
dh_gencontrol
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
- * $Id: tpath.h,v 1.8 2005-06-25 15:46:03 adam Exp $
+ * $Id: tpath.h,v 1.9 2006-04-26 09:40:43 adam Exp $
*
*/
/**
#define TPATH_H
#include <yaz/yconfig.h>
+#include <stdio.h>
YAZ_BEGIN_CDECL
YAZ_EXPORT int yaz_is_abspath (const char *p);
+/** \brief resolve file on path
+ \param fname "short" filename (without path)
+ \param path the path (dir1:dir2,..) - ala Unix
+ \param base can be added to relative paths (NULL for no append)
+ \param fullpath the full path to filename (if succesful)
+
+ Returns 0/NULL if no fname could be found in path;
+ pointer to fullpath if fname could be found.
+ We assume fullpath is 1024 bytes in length!
+*/
+YAZ_EXPORT char *yaz_filepath_resolve(const char *fname, const char *path,
+ const char *base, char *fullpath);
+
+
YAZ_END_CDECL
#endif
* Copyright (C) 1995-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: yaz-version.h,v 1.80 2006-04-20 08:38:01 marc Exp $
+ * $Id: yaz-version.h,v 1.81 2006-04-26 09:40:43 adam Exp $
*/
/**
#include <yaz/yconfig.h>
-#define YAZ_VERSION "2.1.18"
-#define YAZ_VERSIONL 0x020112
+#define YAZ_VERSION "2.1.19"
+#define YAZ_VERSIONL 0x020113
#define YAZ_DATE 1
* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tpath.c,v 1.6 2005-06-25 15:46:06 adam Exp $
+ * $Id: tpath.c,v 1.7 2006-04-26 09:40:43 adam Exp $
*/
/**
* \file tpath.c
#include <ctype.h>
#include <yaz/tpath.h>
#include <yaz/log.h>
+#include <sys/types.h>
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
FILE *yaz_path_fopen(const char *path, const char *name, const char *mode)
{
return fclose (f);
}
-FILE *yaz_fopen(const char *path, const char *name, const char *mode,
- const char *base)
-{
- char spath[1024];
+char *yaz_filepath_resolve(const char *fname, const char *path,
+ const char *base, char *fullpath)
+{
for(;;)
{
- FILE *f;
-
+ struct stat stat_buf;
const char *path_sep = 0;
size_t len = 0;
size_t slen = 0;
- *spath = '\0';
+ *fullpath = '\0';
if (path)
{
/* somewhat dirty since we have to consider Windows
len = strlen(path);
if (!strchr ("/\\", *path) && base)
{
- strcpy (spath, base);
- slen = strlen(spath);
- spath[slen++] = '/';
+ strcpy (fullpath, base);
+ slen = strlen(fullpath);
+ fullpath[slen++] = '/';
}
- memcpy (spath+slen, path, len);
+ memcpy (fullpath+slen, path, len);
slen += len;
- if (!strchr("/\\", spath[slen-1]))
- spath[slen++] = '/';
+ if (!strchr("/\\", fullpath[slen-1]))
+ fullpath[slen++] = '/';
}
- strcpy (spath+slen, name);
- if ((f = fopen(spath, mode)))
- return f;
+ strcpy (fullpath+slen, fname);
+
+ if (stat(fullpath, &stat_buf) == 0)
+ return fullpath;
if (!path_sep)
break;
return 0;
}
+FILE *yaz_fopen(const char *path, const char *fname, const char *mode,
+ const char *base)
+{
+ char fullpath[1024];
+
+ if (!yaz_filepath_resolve(fname, path, base, fullpath))
+ return 0; /* failure */
+ return fopen(fullpath, mode);
+}
+
int yaz_is_abspath (const char *p)
{
if (*p == '/')
## Copyright (C) 1994-2006, Index Data
## All rights reserved.
-## $Id: Makefile.am,v 1.13 2006-04-19 10:05:04 adam Exp $
+## $Id: Makefile.am,v 1.14 2006-04-26 09:40:43 adam Exp $
check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \
- tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery
+ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \
+ tst_filepath
check_SCRIPTS = tstcql.sh tstmarciso.sh tstmarcxml.sh
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
tstlogthread_SOURCES = tstlogthread.c
tstxmlquery_SOURCES = tstxmlquery.c
tstpquery_SOURCES = tstpquery.c
+tst_filepath_SOURCES = tst_filepath.c
--- /dev/null
+/*
+ * Copyright (C) 1995-2006, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: tst_filepath.c,v 1.1 2006-04-26 09:40:43 adam Exp $
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <yaz/tpath.h>
+#include <yaz/test.h>
+
+void tst(void)
+{
+ char fullpath[1024];
+ YAZ_CHECK(yaz_filepath_resolve("tst_filepath", ".", 0, fullpath));
+ YAZ_CHECK(strcmp(fullpath, "./tst_filepath") == 0);
+ YAZ_CHECK(!yaz_filepath_resolve("tst_filepath1", ".", 0, fullpath));
+ YAZ_CHECK(!yaz_filepath_resolve("tst_filepath", "bogus", 0, fullpath));
+ YAZ_CHECK(yaz_filepath_resolve("tst_filepath", "bogus:.", 0, fullpath));
+}
+
+int main (int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ tst();
+ YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+