From 68db5d6050f959bd126eec404447019b6176d2a1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 26 Apr 2006 09:40:42 +0000 Subject: [PATCH] Bump version to 2.1.19. Added function yaz_filepath_resolve. --- configure.ac | 4 ++-- debian/rules | 2 +- include/yaz/tpath.h | 17 ++++++++++++++- include/yaz/yaz-version.h | 6 +++--- src/tpath.c | 50 ++++++++++++++++++++++++++++++--------------- test/Makefile.am | 6 ++++-- test/tst_filepath.c | 43 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 26 deletions(-) create mode 100644 test/tst_filepath.c diff --git a/configure.ac b/configure.ac index 5fc6787..4397a81 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ 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]) diff --git a/debian/rules b/debian/rules index 6f00984..74f09f9 100755 --- a/debian/rules +++ b/debian/rules @@ -98,7 +98,7 @@ binary-arch: build install 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 diff --git a/include/yaz/tpath.h b/include/yaz/tpath.h index 726f3eb..e4cac88 100644 --- a/include/yaz/tpath.h +++ b/include/yaz/tpath.h @@ -23,7 +23,7 @@ * 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 $ * */ /** @@ -35,6 +35,7 @@ #define TPATH_H #include +#include YAZ_BEGIN_CDECL @@ -47,6 +48,20 @@ YAZ_EXPORT int yaz_fclose(FILE *f); 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 diff --git a/include/yaz/yaz-version.h b/include/yaz/yaz-version.h index 4c57509..58a4df5 100644 --- a/include/yaz/yaz-version.h +++ b/include/yaz/yaz-version.h @@ -2,7 +2,7 @@ * 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 $ */ /** @@ -13,8 +13,8 @@ #include -#define YAZ_VERSION "2.1.18" -#define YAZ_VERSIONL 0x020112 +#define YAZ_VERSION "2.1.19" +#define YAZ_VERSIONL 0x020113 #define YAZ_DATE 1 diff --git a/src/tpath.c b/src/tpath.c index 38d66ef..5200380 100644 --- a/src/tpath.c +++ b/src/tpath.c @@ -2,7 +2,7 @@ * 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 @@ -19,6 +19,13 @@ #include #include #include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif FILE *yaz_path_fopen(const char *path, const char *name, const char *mode) { @@ -30,20 +37,18 @@ int yaz_fclose (FILE *f) 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 @@ -61,18 +66,19 @@ FILE *yaz_fopen(const char *path, const char *name, const char *mode, 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; @@ -81,6 +87,16 @@ FILE *yaz_fopen(const char *path, const char *name, const char *mode, 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 == '/') diff --git a/test/Makefile.am b/test/Makefile.am index 7a1e037..78756d6 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,9 +1,10 @@ ## 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) @@ -48,4 +49,5 @@ tstsoap2_SOURCES = tstsoap2.c tstlogthread_SOURCES = tstlogthread.c tstxmlquery_SOURCES = tstxmlquery.c tstpquery_SOURCES = tstpquery.c +tst_filepath_SOURCES = tst_filepath.c diff --git a/test/tst_filepath.c b/test/tst_filepath.c new file mode 100644 index 0000000..58c37d0 --- /dev/null +++ b/test/tst_filepath.c @@ -0,0 +1,43 @@ +/* + * 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 +#endif + +#include +#include +#include +#include + +#include +#include + +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 + */ + -- 1.7.10.4