--- /dev/null
+AC_INIT(zziplib.spec)
+AC_PREREQ(2.49)
+AC_COPYRIGHT([Guido Draheim <guido@gmx.de> for ZZipLib.SF.net])
+AC_REVISION($Revision: 1.1.1.1 $)
+AC_CONFIG_AUX_DIR(uses)
+# =======================================================================
+AC_CANONICAL_SYSTEM
+dnl AM_ENABLE_MULTILIB([Makefile],[$host])
+AX_ENABLE_BUILDDIR
+AC_SET_DEFAULT_PATHS_SYSTEM
+# -----------------------------------------------------------------------
+AC_ARG_ENABLE(thread-safe,AC_HELP_STRING(
+ [--disable-thread-safe],[disable thread-safe libtool option])
+ ,,[ enable_thread_safe="yes"])
+THREAD_SAFE=""
+test "$enable_thread_safe" = "yes" && THREAD_SAFE="-thread-safe"
+test "$enable_thread_safe" = "$host_os" && THREAD_SAFE="-thread-safe"
+AC_SUBST(THREAD_SAFE)
+if test -n "$THREAD_SAFE" ; then
+ AC_MSG_RESULT(...using thread-safe linkage)
+else
+ AC_MSG_RESULT(disabled thread-safe linkage)
+fi
+# ----------------------------------------------------------------
+AC_MSG_CHECKING(zlib install prefix)
+AC_ARG_WITH(zlib, AC_HELP_STRING(
+ [--with-zlib],[zlib prefix (e.g. '$HOME/software')])
+ ,,[with_zlib="no"])
+if test "${with_zlib}" = yes ; then # choose --prefix paths
+ if test "${prefix}" = NONE ; then
+ AC_MSG_RESULT(oops, but only itself...)
+ AC_MSG_ERROR(--with-zlib requires a path argument or a --prefix path set)
+ fi
+ with_zlib="$prefix"
+fi
+
+case ".$with_zlib" in
+ .no|.no,*)
+ AC_MSG_RESULT(none)
+ with_zlib="no, not configured" ;;
+ ./usr)
+ AC_MSG_RESULT([oops, ignored (may try --with-zlib=/usr/.)])
+ with_zlib="no, /usr ignored" ;;
+ *) if test ! -d "$with_zlib/include" ; then
+ AC_MSG_RESULT(oops, given but...)
+ AC_MSG_ERROR("$with_zlib/include" is not a directory)
+ fi
+ if test ! -d "$with_zlib/lib" ; then
+ AC_MSG_RESULT(oops, given but...)
+ AC_MSG_ERROR("$with_zlib/lib" is not a directory)
+ fi
+ AC_MSG_RESULT($with_zlib)
+ ZLIB_INCL="-I$with_zlib/include"
+ ZLIB_LDIR="-L$with_zlib/lib"
+ AC_MSG_RESULT(..adding CPPFLAGS $ZLIB_INCL)
+ AC_MSG_RESULT(..adding LDFLAGS $ZLIB_LDIR)
+ CPPFLAGS="$CPPFLAGS $ZLIB_INCL"
+ LDFLAGS="$LDFLAGS $ZLIB_LDIR"
+ ;;
+esac
+AC_SUBST(ZLIB_INCL)
+AC_SUBST(ZLIB_LDIR)
+# -----------------------------------------------------------------------
+AX_SPEC_DEFAULTS
+AM_INIT_AUTOMAKE($PACKAGE,$VERSION)
+dnl test ".$CFLAGS" = "." && CFLAGS=""
+AC_PROG_CC
+dnl test ".$CFLAGS" = "." && test "$GCC" = "yes" && CFLAGS="-O3"
+AC_PROG_INSTALL
+AC_LIBTOOL_WIN32_DLL
+AM_PROG_LIBTOOL
+AX_SET_VERSION_INFO
+
+# -----------------------------------------------------------------------
+AC_MSG_RESULT([creating zzip/_msvc.in via zzip/_msvc.sed of config.h.in])
+test -d zzip || mkdir zzip
+sed -f $srcdir/zzip/_msvc.sed $srcdir/config.h.in >zzip/_msvc.in
+AM_CONFIG_HEADER(config.h)
+AX_PREFIX_CONFIG_H([zzip/_config.h],[zzip],[config.h])
+AX_PREFIX_CONFIG_H([zzip/_msvc.h],[zzip],[zzip/_msvc.in])
+AM_MAINTAINER_MODE
+
+AX_CREATE_PKGCONFIG_INFO(dnl
+[zzip/zziplib.pc], [zzip-zlib-config],[-lzzip])
+# -----------------------------------------------------------------------
+AC_PATH_PROGS(PERL, perl5 perl, echo no perl found for)
+AC_PATH_PROGS(PYTHON, python2.2 python2.3 python, echo no python found for)
+AC_PATH_PROGS(MKZIP, zip pkzip, :)
+AC_PATH_PROGS(XMLTO, xmlto, :)
+
+AC_C_INLINE
+AC_C_CONST
+AC_STDC_HEADERS
+AC_HEADER_DIRENT
+AC_CHECK_HEADERS(stdint.h unistd.h windows.h winnt.h winbase.h sys/int_types.h)
+AC_CHECK_HEADERS(sys/types.h sys/mman.h sys/stat.h sys/param.h) dnl posix'ish
+AC_CHECK_HEADERS(io.h direct.h zlib.h)
+AC_CHECK_FUNCS( strcasecmp )
+
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+dnl AC_TYPE_SSIZE_T
+AC_CHECK_TYPE(ssize_t,int)
+AC_COMPILE_CHECK_SIZEOF(short)
+AC_COMPILE_CHECK_SIZEOF(int)
+AC_COMPILE_CHECK_SIZEOF(long)
+dnl -------------------------------------------------------------
+# the default is _disabled_!! anyway, result is prefixed in zzip/_config.h!!
+AC_SYS_LARGEFILE_SENSITIVE
+test ".$LARGEFILE_CFLAGS" = "." && LARGEFILE_CFLAGS=""
+AC_ARG_WITH(largefile,AC_HELP_STRING(
+ [--with-largefile],[compile as off64_t instead of 32bit off_t])
+ ,,[with_largefile="no"])
+if test ".$ac_cv_sys_largefile_sensitive" = ".no" ; then
+ AC_MSG_RESULT(compiles library with the only off_t seen)
+elif test ".$with_largefile" != ".no" ; then
+ AC_MSG_RESULT(compiles library as 64bit off_t variant dnl
+- and renaming some function names)
+ LARGEFILE_CFLAGS="$LARGEFILE_CFLAGS -D_LARGEFILE_SOURCE"
+ AC_MSG_RESULT(..adding CFLAGS $LARGEFILE_CFLAGS)
+ CFLAGS="$CFLAGS $LARGEFILE_CFLAGS"
+ AC_MSG_RESULT(..adding 64 into RELEASE_INFO for the libraries)
+ RELEASE_INFO="$RELEASE_INFO-64"
+else
+ AC_MSG_RESULT(compiles library as 32bit off_t variant dnl
+- largefile is not the default here)
+fi
+AC_SUBST(LARGEFILE_CFLAGS)
+dnl -------------------------------------------------------------
+AC_MSG_CHECKING(for zlib being found)
+if test "_$ac_cv_header_zlib_h" != "_yes" ; then
+ AC_MSG_RESULT(dnl
+...oops: zlib.h not found - try adding some CPPFLAGS to configure call)
+ AC_MSG_RESULT(dnl
+...note: and when linkage fails you might also need to set some LDFLAGS)
+ case "$prefix" in
+ NONE|/usr)
+ AC_MSG_RESULT(dnl
+...note: both can be set by specifying the install prefix of the zlib library)
+ AC_MSG_RESULT(dnl
+...note: via --with-zlib=path ... it will test for -Ipath/include -Lpath/lib)
+ ;;
+ *) if test -d $prefix/include ; then
+ AC_MSG_RESULT(dnl
+...note: -I$prefix/include is not added to CPPFLAGS automatically and)
+ AC_MSG_RESULT(dnl
+...note: neither is -L$prefix/lib for LDFLAGS .. both will be if you specify)
+ AC_MSG_RESULT(dnl
+...note: --with-zlib to configure call, or use --with-zlib=installprefix)
+ fi
+ ;;
+ esac
+ AC_MSG_ERROR(zlib.h not found: "zlib" is required to build "$PACKAGE")
+ exit 1
+fi
+cat >conftest.c <<EOF
+#include <zlib.h>
+const char* zlib_VeRsIoN = ZLIB_VERSION "dEtEcT";
+EOF
+ZLIB_VERSION=`(eval "$ac_cpp conftest.c") 2>/dev/null \
+| grep zlib_VeRsIoN | sed -e 's,.*= *.,,' -e 's,. *.dEtEcT.*,,'`
+rm conftest.c
+AC_SUBST(ZLIB_VERSION)
+AC_MSG_RESULT(yes - $ZLIB_VERSION)
+# ----------------------------------------------------------------
+AC_MSG_CHECKING(docdir default)
+AC_ARG_WITH(docdir, AC_HELP_STRING(
+ [--with-docdir],[docdir prefix (prefix/share/doc)])
+ ,,[with_docdir="no"])
+case "${with_docdir}" in
+ prefix/*) docdir=` echo "$withval" | sed 's/^prefix/${prefix}'` ;;
+ datadir/*) docdir=` echo "$withval" | sed 's/^datadir/${datadir}'` ;;
+ yes) docdir='${prefix}/doc' ;;
+ no) docdir='${datadir}/doc' ;;
+ /*|\\*|[a-zA-Z]:*) docdir="$with_docdir" ;;
+ *) AC_MSG_RESULT(oops)
+ AC_MSG_ERROR(bad value ${withval} for --with-docdir)
+ ;;
+esac
+AC_SUBST(docdir)
+AC_MSG_RESULT($docdir)
+# ----------------------------------------------------------------
+AC_MSG_CHECKING(whether using debugging messages in libraries)
+AC_ARG_WITH(debug, AC_HELP_STRING(
+ [--with-debug],[debug messages in library])
+ , [case "${withval}" in
+ yes|no) with_debug="$withval" ;;
+ *) AC_MSG_RESULT(oops)
+ AC_MSG_ERROR(bad value ${withval} for --with-debug) ;;
+ esac], [with_debug="no"])
+test "$with_debug" != "yes" && with_debug="no" # yes or no
+test "$with_debug" = "yes" && export CFLAGS="$CFLAGS -DDEBUG"
+result="$with_debug" ; test "$result" = "yes" && result="yes, added -DDEBUG"
+AC_MSG_RESULT($result)
+if test "$with_debug" = "yes" ; then if test -n "$RELEASE_INFO" ; then
+ RELEASE_INFO="$RELEASE_INFO-dbg"
+ AC_MSG_RESULT(modified release, $RELEASE_INFO)
+fi fi
+# ----------------------------------------------------------------
+AC_MSG_CHECKING(whether thread stack is too small for bufsiz buffers)
+ # many embedded platforms, superthreaded systems and kernel usage
+ # will severely limit the stackspace for its threads. Use _LOWSTK
+ # compile-define on those platforms.
+AC_ARG_WITH(lowstk, AC_HELP_STRING(
+ [--with-lowstk], [limited thread stack])
+ , [case "${withval}" in
+ yes|no|auto) with_lowstk="$withval" ;;
+ *) AC_MSG_ERROR(bad value ${withval} for --with-lowstk) ;;
+ esac], [with_lowstk="auto"])
+if test "$with_lowstk" = "auto"; then
+ case $target in
+ *-palmos-*) $with_lowstk="yes" ;;
+ esac
+fi
+test "$with_lowstk" != "yes" && with_lowstk="no" # yes or no
+test "$with_lowstk" = "yes" && CFLAGS="$CFLAGS -D_LOWSTK"
+result="$with_lowstk" ; test "$result" = "yes" && result="yes, added -D_LOWSTK"
+AC_MSG_RESULT($with_lowstk)
+# ---------------------------------------------------------------
+AC_MSG_CHECKING(whether can use mmap for file scanning)
+ # system with mmap are probably better performing an searching
+ # and parsing - atleast memory consumption is far better
+AC_ARG_ENABLE(mmap, AC_HELP_STRING(
+ [--disable-mmap],[disable mmap usage])
+ , [case "${enableval}" in
+ yes|no|auto) enable_mmap="${enableval}" ;;
+ *) AC_MSG_RESULT(oops)
+ AC_MSG_ERROR(bad value ${enableval} for --disable-mmap) ;;
+ esac], [enable_mmap="auto"])
+if test "$enable_mmap" = "auto"
+then
+ test "$ac_cv_header_winbase_h" && enable_mmap="yes, winbase.h"
+ test "$ac_cv_header_sys_mman_h" && enable_mmap="yes, sys/mman.h"
+fi
+case "$enable_mmap" in
+ yes|yes,*) CFLAGS="$CFLAGS -D_USE_MMAP"
+ AC_MSG_RESULT($enable_mmap, added -D_USE_MMAP) ;;
+ *) enable_mmap="no"
+ AC_MSG_RESULT(no (just a bit slower)) ;;
+esac
+# ---------------------------------------------------------------
+AC_MSG_CHECKING(whether making SDL parts)
+SDL=""
+AC_ARG_ENABLE(sdl, AC_HELP_STRING(
+ [--enable-sdl],[enable SDL usage (if present)])
+ ,,[enable_sdl="no"])
+if test "$enable_sdl" = "no" ; then
+ AC_MSG_RESULT([no, disabled])
+else
+ enable_sdl=`sdl-config --version 2>/dev/null`
+ case ".$enable_sdl" in
+ .1.*) AC_MSG_RESULT([yes, for SDL $enable_sdl])
+ SDL="SDL" ;;
+ .2.*) AC_MSG_RESULT([yes, untested $enable_sdl])
+ SDL="SDL" ;;
+ *) AC_MSG_RESULT([no, $enable_sdl]) ;;
+ esac
+fi
+AC_SUBST(SDL)
+# ---------------------------------------------------------------
+AC_MSG_CHECKING(running extra tests on make check)
+if test "MKZIP" != ":" ; then
+ AC_MSG_RESULT(yes)
+ ZIPTESTS=""
+else
+ AC_MSG_RESULT(no)
+ ZIPTESTS="#"
+fi
+AC_SUBST(ZIPTESTS)
+# ---------------------------------------------------------------
+AC_MSG_CHECKING(link options)
+case "$host_os" in
+ mingw*)
+ ZZIPLIB_LDFLAGS="-no-undefined -export-all-symbols -mconsole"
+ RESOLVES=' '
+ ;;
+ *)
+ ZZIPLIB_LDFLAGS="--export-dynamic"
+ RESOLVES=' # '
+ ;;
+esac
+AC_MSG_RESULT([$ZZIPLIB_LDFLAGS $RESOLVES])
+AC_SUBST([ZZIPLIB_LDFLAGS])
+AC_SUBST([RESOLVES])
+# ---------------------------------------------------------------
+AX_MAINTAINER_MODE_AUTO_SILENT
+AX_NOT_ENABLE_FRAME_POINTER
+AX_CFLAGS_WARN_ALL
+AX_CFLAGS_NO_WRITABLE_STRINGS
+AX_CFLAGS_STRICT_PROTOTYPES
+AX_CFLAGS_GCC_OPTION(,-Wpointer-arith,)
+AX_CFLAGS_GCC_OPTION(,-Wsign-compare,)
+AX_CFLAGS_GCC_OPTION(,-Wmissing-declarations,)
+# ---------------------------------------------------------------
+AX_WARNING_DEFAULT_PKGCONFIGDIR
+AX_WARNING_DEFAULT_ACLOCALDIR
+AC_SUBST([CONFIG_FILES])
+AC_OUTPUT([Makefile zzip/Makefile zzipwrap/Makefile SDL/Makefile
+ docs/Makefile test/Makefile bins/Makefile])
+dnl -------------------------------------------------------------
+PATCH_LIBTOOL_ON_DARWIN_ZSH_OVERQUOTING
+PATCH_LIBTOOL_SYS_LIB_SEARCH_PATH_SPEC
+PATCH_LIBTOOL_TO_ADD_HOST_CC
+# ---------------------------------------------------------------
+echo '-----' $PACKAGE $VERSION $prefix
+$SHELL libtool --features || true
+echo "CFLAGS=$CFLAGS"
+test "$enable_mmap" != "no" && echo "enable mmap ($enable_mmap)"
+test "$enable_mmap" = "no" && echo "disable mmap ($enable_mmap)"
+test "$with_lowstk" != "no" && echo "with lowstk ($with_lowstk)"
+test "$with_lowstk" = "no" && echo "without lowstk ($with_lowstk)"
+test "$with_debug" != "no" && echo "with debug ($with_debug)"
+test "$with_debug" = "no" && echo "without debug ($with_debug)"
+# test -f ./zziplib.spec && echo warning - do not build in the source dirs
+echo '# make && make check && make install'
--- /dev/null
+/*\r
+ * Author: \r
+ * Guido Draheim <guidod@gmx.de>\r
+ *\r
+ * Copyright (c) 2001,2002,2003 Guido Draheim\r
+ * All rights reserved,\r
+ * use under the restrictions of the\r
+ * Lesser GNU General Public License\r
+ * or alternatively the restrictions \r
+ * of the Mozilla Public License 1.1\r
+ */\r
+\r
+#ifndef _ZZIP_CONF_H\r
+#define _ZZIP_CONF_H 1\r
+\r
+#if !defined ZZIP_OMIT_CONFIG_H\r
+# if defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__\r
+# include <zzip/_msvc.h>\r
+# elif defined ZZIP_1_H\r
+# include "zzip-1.h"\r
+# elif defined ZZIP_2_H\r
+# include "zzip-2.h"\r
+# elif defined ZZIP_3_H\r
+# include "zzip-3.h"\r
+# elif defined ZZIP_4_H\r
+# include "zzip-4.h"\r
+# elif defined ZZIP_5_H\r
+# include "zzip-5.h"\r
+# else /* autoconf generated */\r
+# include <zzip/_config.h>\r
+# endif\r
+#endif\r
+\r
+/* especially win32 platforms do not declare off_t so far - see zzip-msvc.h */\r
+#ifndef _zzip_off_t\r
+#ifdef ZZIP_off_t\r
+#define _zzip_off_t ZZIP_off_t\r
+#else\r
+#define _zzip_off_t off_t\r
+#endif\r
+#endif\r
+\r
+/* currently unused, all current zziplib-users do have ansi-C94 compilers. */\r
+#ifndef _zzip_const\r
+#ifdef ZZIP_const\r
+#define _zzip_const ZZIP_const\r
+#else\r
+#define _zzip_const const\r
+#endif\r
+#endif\r
+#ifndef _zzip_inline\r
+#ifdef ZZIP_inline\r
+#define _zzip_inline ZZIP_inline\r
+#else\r
+#define _zzip_inline inline\r
+#endif\r
+#endif\r
+#ifndef _zzip_size_t\r
+#ifdef ZZIP_size_t\r
+#define _zzip_size_t ZZIP_size_t\r
+#else\r
+#define _zzip_size_t size_t\r
+#endif\r
+#endif\r
+#ifndef _zzip_ssize_t\r
+#ifdef ZZIP_ssize_t\r
+#define _zzip_ssize_t ZZIP_ssize_t\r
+#else\r
+#define _zzip_ssize_t ssize_t\r
+#endif\r
+#endif\r
+\r
+/* whether this library shall use a 64bit off_t largefile variant in 64on32: */\r
+/* (some exported names must be renamed to avoid bad calls after linking) */\r
+#if defined ZZIP_LARGEFILE_SENSITIVE \r
+# if _FILE_OFFSET_BITS+0 == 64\r
+# define ZZIP_LARGEFILE_RENAME\r
+# elif defined _LARGE_FILES /* used on older AIX to get at 64bit off_t */\r
+# define ZZIP_LARGEFILE_RENAME\r
+# elif defined _ZZIP_LARGEFILE /* or simply use this one for zzip64 runs */\r
+# define ZZIP_LARGEFILE_RENAME\r
+# endif\r
+#endif\r
+\r
+/* if the environment did not setup these for 64bit off_t largefile... */\r
+#ifdef ZZIP_LARGEFILE_RENAME\r
+# ifndef _FILE_OFFSET_BITS\r
+# ifdef ZZIP__FILE_OFFSET_BITS /* == 64 */\r
+# define _FILE_OFFSET_BITS ZZIP__FILE_OFFSET_BITS\r
+# endif\r
+# endif\r
+# ifndef _LARGE_FILES\r
+# ifdef ZZIP__LARGE_FILES /* == 1 */\r
+# define _LARGE_FILES ZZIP__LARGE_FILES\r
+# endif\r
+# endif\r
+# ifndef _LARGEFILE_SOURCE\r
+# ifdef ZZIP__LARGEFILE_SOURCE /* == 1 */\r
+# define _LARGEFILE_SOURCE ZZIP__LARGEFILE_SOURCE\r
+# endif\r
+# endif\r
+#endif\r
+\r
+#include <errno.h>\r
+\r
+/* mingw32msvc errno : would be in winsock.h */\r
+#ifndef EREMOTE\r
+#define EREMOTE ESPIPE\r
+#endif\r
+\r
+#ifndef ELOOP\r
+#if defined EILSEQ\r
+#define ELOOP EILSEQ\r
+#else\r
+#define ELOOP ENOEXEC\r
+#endif\r
+#endif\r
+\r
+#if defined __WATCOMC__\r
+#undef _zzip_inline\r
+#define _zzip_inline static\r
+#endif\r
+\r
+#if defined _MSC_VER || defined __WATCOMC__\r
+#include <io.h>\r
+#endif\r
+\r
+#ifdef _MSC_VER\r
+# if !__STDC__\r
+# ifndef _zzip_lseek\r
+# define _zzip_lseek _lseek\r
+# endif\r
+# ifndef _zzip_read\r
+# define _zzip_read _read\r
+# endif\r
+# ifndef _zzip_write\r
+# define _zzip_write _write\r
+# endif\r
+/*\r
+# ifndef _zzip_stat\r
+# define _zzip_stat _stat\r
+# endif\r
+*/\r
+# endif /* !__STDC__ */\r
+#endif\r
+ /*MSVC*/\r
+\r
+#if defined _MSC_VER || defined __WATCOMC__\r
+# ifndef strcasecmp\r
+# define strcasecmp _stricmp\r
+# endif\r
+#endif\r
+\r
+# ifndef _zzip_lseek\r
+# define _zzip_lseek lseek\r
+# endif\r
+\r
+# ifndef _zzip_read\r
+# define _zzip_read read\r
+# endif\r
+\r
+# ifndef _zzip_write\r
+# define _zzip_write write\r
+# endif\r
+\r
+/*\r
+# ifndef _zzip_stat\r
+# define _zzip_stat stat\r
+# endif\r
+*/\r
+\r
+\r
+#if !defined __GNUC__ && !defined __attribute__\r
+#define __attribute__(X) \r
+#endif\r
+\r
+#if defined ZZIP_EXPORTS || defined ZZIPLIB_EXPORTS\r
+# undef ZZIP_DLL\r
+#define ZZIP_DLL 1\r
+#endif\r
+\r
+/* based on zconf.h : */\r
+/* compile with -DZZIP_DLL for Windows DLL support */\r
+#if defined ZZIP_DLL\r
+# if defined _WINDOWS || defined WINDOWS || defined _WIN32\r
+/*# include <windows.h>*/\r
+# endif\r
+# if !defined _zzip_export && defined _MSC_VER && (defined WIN32 || defined _WIN32)\r
+# define _zzip_export __declspec(dllexport) /*WINAPI*/\r
+# endif\r
+# if !defined _zzip_export && defined __BORLANDC__\r
+# if __BORLANDC__ >= 0x0500 && defined WIN32\r
+# include <windows.h>\r
+# define _zzip_export __declspec(dllexport) /*WINAPI*/\r
+# else\r
+# if defined _Windows && defined __DLL__\r
+# define _zzip_export _export\r
+# endif\r
+# endif\r
+# endif\r
+# if !defined _zzip_export && defined __GNUC__\r
+# if defined __declspec\r
+# define _zzip_export extern __declspec(dllexport)\r
+# else\r
+# define _zzip_export extern\r
+# endif\r
+# endif\r
+# if !defined _zzip_export && defined __BEOS__\r
+# define _zzip_export extern __declspec(export)\r
+# endif\r
+# if !defined _zzip_export && defined __WATCOMC__\r
+# define _zzip_export extern __declspec(dllexport)\r
+# define ZEXPORT __syscall\r
+# define ZEXTERN extern\r
+# endif\r
+#endif\r
+\r
+#if !defined _zzip_export\r
+# if defined __GNUC__ /* || !defined HAVE_LIBZZIP */\r
+# define _zzip_export extern\r
+# elif defined __declspec || (defined _MSC_VER && defined ZZIP_DLL)\r
+# define _zzip_export extern __declspec(dllimport)\r
+# else\r
+# define _zzip_export extern\r
+# endif\r
+#endif\r
+\r
+#endif\r
+\r
+\r
--- /dev/null
+
+/* Wrapper interface for zziplib's file IO functions.
+ *
+ * -- In memory-access IO function --
+ * Provides default fileio functions open/read/lseek/close and functions
+ * that enable blocked, memory buffered IO.
+ *
+ * (c) A. Schiffler, aschiffler@home.com
+ * Released under same license as zziplib (LGPL), Oct 2001
+ *
+ * modified 2002 to use new plugin_io interface by Guido Draheim
+ */
+
+#include <zzip/conf.h>
+#include <zzip/plugin.h>
+/* #incl <zzip/wrap.h> */
+#include "wrap.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef ZZIP_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/* Some globals that we use for operation */
+
+static int zzip_memory_blocksize=0;
+static zzipwrap_pfn_t zzip_memory_callback=NULL;
+static void *zzip_memory_callbackdata=NULL;
+static char *zzip_memory_buffer=NULL;
+static int zzip_memory_bufferblock=0;
+static int zzip_memory_fd=-1;
+static int zzip_memory_pos=0;
+static int zzip_memory_size=0;
+
+/* at the moment, we do not export the five handlers of zzip_memry plugin_io */
+#define ZZIP_memory static
+
+ZZIP_memory void zzip_memory_reset(void)
+{
+ zzip_memory_buffer=NULL;
+ zzip_memory_bufferblock=0;
+ zzip_memory_pos=0;
+ zzip_memory_size=0;
+ zzip_memory_fd=-1;
+}
+
+ZZIP_memory int zzip_memory_read(int fd, char *buf, size_t count)
+{
+ int requested_block;
+ int transfer_start;
+ int transfer_bytes;
+ int bytes_read;
+ int bytes_to_write;
+ int bytes_written;
+
+ /* Check file descriptor */
+ if (fd!=zzip_memory_fd) {
+ return(-1);
+ }
+
+ if ((int)count<0)
+ return -1;
+
+ /* Work out how many bytes we have to read based */
+ /* on filepos and requested buffersize. */
+ bytes_to_write=zzip_memory_size-zzip_memory_pos;
+ if (bytes_to_write>=(int)count) {
+ bytes_to_write=(int)count;
+ }
+
+ /* Read/transfer loop */
+ bytes_written=0;
+ while (bytes_to_write>0) {
+ /* Check which block we are reading from */
+ requested_block=zzip_memory_pos/zzip_memory_blocksize;
+ /* Check if we have this block available */
+ if (zzip_memory_bufferblock!=requested_block) {
+ /* Read this block */
+ lseek(fd,requested_block*zzip_memory_blocksize,SEEK_SET);
+ bytes_read=read(fd,zzip_memory_buffer,zzip_memory_blocksize);
+ /* Clear unused bytes */
+ if ((bytes_read>=0) && (bytes_read<zzip_memory_blocksize)) {
+ memset(&zzip_memory_buffer[bytes_read],0,zzip_memory_blocksize-bytes_read);
+ }
+ /* Set current block pos */
+ zzip_memory_bufferblock=requested_block;
+ /* Process buffer if callback is set */
+ if (zzip_memory_callback) {
+ zzip_memory_callback(zzip_memory_buffer,zzip_memory_blocksize,zzip_memory_callbackdata);
+ }
+ } else {
+ bytes_read=zzip_memory_blocksize;
+ }
+ /* Check if we have read any data */
+ if (bytes_read > 0) {
+ /* Copy data to output buffer */
+ transfer_start=zzip_memory_pos-zzip_memory_bufferblock*zzip_memory_blocksize;
+ transfer_bytes=zzip_memory_blocksize-transfer_start;
+ if (transfer_bytes>bytes_to_write) {
+ transfer_bytes=bytes_to_write;
+ }
+ memcpy (&buf[bytes_written], &zzip_memory_buffer[transfer_start],transfer_bytes);
+ zzip_memory_pos += transfer_bytes;
+ bytes_written += transfer_bytes;
+ bytes_to_write -= transfer_bytes;
+ } else {
+ /* Exit on error during read */
+ bytes_to_write=0;
+ }
+ }
+ return(bytes_written);
+}
+
+ZZIP_memory int zzip_memory_open(const char *pathname, int flags)
+{
+ int fd;
+ struct stat stat_buffer;
+
+ /* Deallocate any memory buffer laying around */
+ if (zzip_memory_buffer) {
+ free(zzip_memory_buffer);
+ }
+ /* Reset variables */
+ zzip_memory_reset();
+ /* Open file */
+ fd=open(pathname, flags);
+ if (fd<0) {
+ return(-1);
+ } else {
+ /* Get filesize */
+ if (fstat(fd, &stat_buffer)<0) {
+ return(-1);
+ }
+ if (stat_buffer.st_size<1) {
+ return(-1);
+ }
+ /* Store filesize */
+ zzip_memory_size = stat_buffer.st_size;
+ /* Allocate readbuffer */
+ zzip_memory_buffer = malloc(zzip_memory_blocksize);
+ /* Invalidate buffer block */
+ zzip_memory_bufferblock = -1;
+ /* Store file descriptor */
+ zzip_memory_fd=fd;
+ /* Return file descriptor */
+ return(fd);
+ }
+}
+
+ZZIP_memory int zzip_memory_close(int fd)
+{
+ /* Check file descriptor */
+ if (fd!=zzip_memory_fd) {
+ return(-1);
+ }
+ /* Clear any memory buffer that might be laying around */
+ if (zzip_memory_buffer) {
+ free(zzip_memory_buffer);
+ }
+ /* Reset variables */
+ zzip_memory_reset();
+ /* Close file */
+ return(close(fd));
+}
+
+ZZIP_memory off_t zzip_memory_lseek(int fildes, off_t offset, int whence)
+{
+ /* Check file descriptor */
+ if (fildes!=zzip_memory_fd) {
+ return(-1);
+ }
+ /* Change position pointer */
+ switch (whence) {
+ case SEEK_SET:
+ zzip_memory_pos=offset;
+ break;
+ case SEEK_CUR:
+ zzip_memory_pos += offset;
+ break;
+ case SEEK_END:
+ zzip_memory_pos = zzip_memory_size-1;
+ break;
+ }
+ /* Limit position to the last byte of the file */
+ if (zzip_memory_pos>(zzip_memory_size-1)) {
+ zzip_memory_pos=zzip_memory_size-1;
+ }
+ /* Return current position */
+ return(zzip_memory_pos);
+}
+
+/* -------- Control wrapper usage */
+
+
+zzip_plugin_io_t
+zzipwrap_use_memory_io(int blocksize,
+ zzipwrap_pfn_t callback, void *callbackdata)
+{
+ static const struct zzip_plugin_io zzip_memory_io =
+ {
+ (void *) zzip_memory_open,
+ (void *) zzip_memory_close,
+ (void *) zzip_memory_read,
+ (void *) zzip_memory_lseek,
+ (void *) zzip_filesize,
+ 0
+ };
+
+ /* Store blocksize and block-processing callback data */
+
+ zzip_memory_blocksize = blocksize;
+ zzip_memory_callback = callback;
+ zzip_memory_callbackdata = callbackdata;
+
+ return (zzip_plugin_io_t) &zzip_memory_io;
+}
+