+2003-12-22
+ * add AC_C_BIGENDIAN and
+ * move out ZZIP_GET to zzip/fetch.h where we also specify access
+ wrappers to items in the zzip/format.h structures, portably.
+ * add byteswap.h ac_check and put a new file autoconf.h to carry
+ compiletime overrides for the autoconf definitions.
+ * start changing over to use zzip/fetch.h definitions everywhere
+ thereby replacing original ZZIP_GET16/32 usages completely.
+ This is localized to zzip/zip.c
+ * rename struct zzip_root_dirent to struct zzip_disk_entry but
+ retain a compatibility declaration.
+ * introduce zzip_version_t and zzip_dostime_t along with an optional
+ ZZIP_NEED_PACKED def that helps with weird compiler struct packing
+ * struct zzip_file_trailer did not use the char[x] variant, it does now
+ * place even more zzip/fetch.h declarations
+ * place even more defs into zzip/format.h
+ * noting CVS area on webpages
+
2003-12-21
* Nigel Stewart hints on some MSVC 6 issues, thanks.
#! /bin/sh
-# From configure.ac Revision: 0.0.
+# From configure.ac Revision: 1.1.1.2 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.57.
#
-for ac_header in io.h direct.h zlib.h
+
+for ac_header in io.h direct.h zlib.h byteswap.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
_ACEOF
+echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
+echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6
+if test "${ac_cv_c_bigendian+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ # See if sys/param.h defines the BYTE_ORDER macro.
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <sys/param.h>
+
+int
+main ()
+{
+#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+ bogus endian macros
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ # It does; now see whether it defined to BIG_ENDIAN or not.
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <sys/types.h>
+#include <sys/param.h>
+
+int
+main ()
+{
+#if BYTE_ORDER != BIG_ENDIAN
+ not big endian
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_c_bigendian=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_c_bigendian=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+# It does not; compile a test program.
+if test "$cross_compiling" = yes; then
+ # try to guess the endianness by grepping values into an object file
+ ac_cv_c_bigendian=unknown
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
+short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }
+int
+main ()
+{
+ _ascii (); _ebcdic ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
+ ac_cv_c_bigendian=yes
+fi
+if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
+ if test "$ac_cv_c_bigendian" = unknown; then
+ ac_cv_c_bigendian=no
+ else
+ # finding both strings is unlikely to happen, but who knows?
+ ac_cv_c_bigendian=unknown
+ fi
+fi
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+else
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+int
+main ()
+{
+ /* Are we little or big endian? From Harbison&Steele. */
+ union
+ {
+ long l;
+ char c[sizeof (long)];
+ } u;
+ u.l = 1;
+ exit (u.c[sizeof (long) - 1] == 1);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_c_bigendian=no
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_c_bigendian=yes
+fi
+rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5
+echo "${ECHO_T}$ac_cv_c_bigendian" >&6
+case $ac_cv_c_bigendian in
+ yes)
+
+cat >>confdefs.h <<\_ACEOF
+#define WORDS_BIGENDIAN 1
+_ACEOF
+ ;;
+ no)
+ ;;
+ *)
+ { { echo "$as_me:$LINENO: error: unknown endianness
+presetting ac_cv_c_bigendian=no (or yes) will help" >&5
+echo "$as_me: error: unknown endianness
+presetting ac_cv_c_bigendian=no (or yes) will help" >&2;}
+ { (exit 1); exit 1; }; } ;;
+esac
+
# the default is _disabled_!! anyway, result is prefixed in zzip/_config.h!!
# Check whether --enable-largefile or --disable-largefile was given.
if test "${enable_largefile+set}" = set; then
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.2 $)
+AC_REVISION($Revision: 1.2 $)
AC_CONFIG_AUX_DIR(uses)
# =======================================================================
AC_CANONICAL_SYSTEM
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_HEADERS(io.h direct.h zlib.h byteswap.h)
AC_CHECK_FUNCS( strcasecmp )
AC_TYPE_OFF_T
AC_COMPILE_CHECK_SIZEOF(short)
AC_COMPILE_CHECK_SIZEOF(int)
AC_COMPILE_CHECK_SIZEOF(long)
+AC_C_BIGENDIAN
dnl -------------------------------------------------------------
# the default is _disabled_!! anyway, result is prefixed in zzip/_config.h!!
AC_SYS_LARGEFILE_SENSITIVE
<br><b><a alt="Tarballs, RPM-archive and windll-ZIPs can be downloaded from"
href="http://sourceforge.net/project/showfiles.php?group_id=6389">
Download Area *</a></b>
+<br><a alt="Sourceforge Project CVS web access"
+ href="http://sourceforge.net/cvs/?group_id=6389">Sourceforge CVS</a>
<br><a alt="Sourceforge Project Index Page"
href="http://sourceforge.net/projects/zziplib">Sourceforge Project</a>
<br><a alt="the zziplib webpage at sourceforge"
info.c \
err.c \
plugin.c \
- write.c
+ write.c \
+ fetch.c
libzzip_la_headers = \
stdint.h \
file.h \
plugin.h \
lib.h \
zzip.h \
+ fetch.h \
format.h \
info.h \
+ autoconf.h \
conf.h \
_config.h \
_msvc.h
info.c \
err.c \
plugin.c \
- write.c
+ write.c \
+ fetch.c
libzzip_la_headers = \
stdint.h \
plugin.h \
lib.h \
zzip.h \
+ fetch.h \
format.h \
info.h \
+ autoconf.h \
conf.h \
_config.h \
_msvc.h
libzzip_la_DEPENDENCIES =
am_libzzip_la_OBJECTS = zip.lo file.lo dir.lo stat.lo info.lo err.lo \
- plugin.lo write.lo
+ plugin.lo write.lo fetch.lo
libzzip_la_OBJECTS = $(am_libzzip_la_OBJECTS)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
depcomp = $(SHELL) $(top_srcdir)/uses/depcomp
am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/dir.Plo ./$(DEPDIR)/err.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/file.Plo ./$(DEPDIR)/info.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/plugin.Plo ./$(DEPDIR)/stat.Plo \
-@AMDEP_TRUE@ ./$(DEPDIR)/write.Plo ./$(DEPDIR)/zip.Plo
+@AMDEP_TRUE@ ./$(DEPDIR)/fetch.Plo ./$(DEPDIR)/file.Plo \
+@AMDEP_TRUE@ ./$(DEPDIR)/info.Plo ./$(DEPDIR)/plugin.Plo \
+@AMDEP_TRUE@ ./$(DEPDIR)/stat.Plo ./$(DEPDIR)/write.Plo \
+@AMDEP_TRUE@ ./$(DEPDIR)/zip.Plo
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dir.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fetch.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/info.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@
--- /dev/null
+#ifndef _ZZIP_AUTOCONF_H_
+#define _ZZIP_AUTOCONF_H_ 1
+
+/*
+ * This file is trying to override configure time checks of zzip with
+ * definitions at compile time. This is not used by zzip sources themselves
+ * but it may be really helpful with thirdparty software that happens to
+ * include zzip headers from a central place but running on a different host.
+ */
+
+#include "conf.h" /* <zzip/conf.h> : <zzip/_config.h> */
+
+#if defined HAVE_ENDIAN_H || defined ZZIP_HAVE_ENDIAN_H
+#include <endian.h> /* glibc */
+#elif defined HAVE_SYS_PARAM_H || defined ZZIP_HAVE_SYS_PARAM_H
+#include <sys/param.h> /* solaris */
+#endif
+
+#if defined __BYTE_ORDER
+#define ZZIP_BYTE_ORDER __BYTE_ORDER
+#elif defined BYTE_ORDER
+#define ZZIP_BYTE_ORDER BYTE_ORDER
+#elif defined _LITTLE_ENDIAN
+#define ZZIP_BYTE_ORDER 1234
+#elif defined _BIG_ENDIAN
+#define ZZIP_BYTE_ORDER 4321
+#elif defined __i386__
+#define ZZIP_BYTE_ORDER 1234
+#elif defined WORDS_BIGENDIAN || defined ZZIP_WORDS_BIGENDIAN
+#define ZZIP_BYTE_ORDER 4321
+#else
+#define ZZIP_BYTE_ORDER 1234
+#endif
+
+/* override ZZIP_WORDS_BIGENDIAN : macros ZZIP_GET16 / ZZIP_GET32 */
+#ifdef ZZIP_BYTE_ORDER+0 == 1234
+#undef ZZIP_WORDS_BIGENDIAN
+#endif
+#ifdef ZZIP_BYTE_ORDER+0 == 4321
+#ifndef ZZIP_WORDS_BIGENDIAN
+#define ZZIP_WORDS_BIGENDIAN 1
+#endif
+#endif
+
+#endif
--- /dev/null
+#include <zzip/fetch.h>
+
+#if defined ZZIP_WORDS_BIGENDIAN && defined bswap_16 && defined bswap_32
+# define __ZZIP_GET16(__p) bswap_16(*(uint16_t*)(__p))
+# define __ZZIP_GET32(__p) bswap_32(*(uint32_t*)(__p))
+# define __ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = bswap_16((uint16_t)(__x)))
+# define __ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = bswap_32((uint32_t)(__x)))
+#endif
+
+/* ------------------------- fetch helpers --------------------------------- */
+
+/**
+ * Make 32 bit value in host byteorder from little-endian mapped octet-data
+ * (works also on machines which SIGBUS on misaligned data access (eg. 68000))
+ */
+uint32_t __zzip_get32(unsigned char * s)
+{
+#if defined __ZZIP_GET32
+ return __ZZIP_GET32(s);
+#else
+ return ((uint32_t)s[3] << 24) | ((uint32_t)s[2] << 16)
+ | ((uint32_t)s[1] << 8) | (uint32_t)s[0];
+#endif
+}
+
+/** => __zzip_get32
+ * This function does the same for a 16 bit value.
+ */
+uint16_t __zzip_get16(unsigned char * s)
+{
+#if defined __ZZIP_GET16
+ return __ZZIP_GET16(s);
+#else
+ return ((uint16_t)s[1] << 8) | (uint16_t)s[0];
+#endif
+}
+
+/** => zzip_get32
+ * This function pushes a 32bit value at the specified address
+ */
+void __zzip_set32(unsigned char * s, uint32_t v)
+{
+#if defined __ZZIP_SET32
+ return __ZZIP_SET32(s, v);
+#else
+ s[0] = (unsigned char) (v);
+ v >>= 8;
+ s[1] = (unsigned char) (v);
+ v >>= 8;
+ s[2] = (unsigned char) (v);
+ v >>= 8;
+ s[3] = (unsigned char) (v);
+#endif
+}
+
+/** => __zzip_get32
+ * This function does the same for a 16 bit value.
+ */
+void __zzip_set16(unsigned char * s, uint16_t v)
+{
+#if defined __ZZIP_SET16
+ return __ZZIP_SET16(s, v);
+#else
+ s[0] = (unsigned char) (v);
+ v >>= 8;
+ s[1] = (unsigned char) (v);
+#endif
+}
--- /dev/null
+#ifndef _ZZIP_FORMATS_H
+#define _ZZIP_FORMATS_H
+
+#include <zzip/conf.h>
+#include <zzip/format.h>
+
+/* linux knows "byteswap.h" giving us an optimized variant */
+#ifdef ZZIP_HAVE_BYTESWAP_H
+#include <byteswap.h>
+#endif
+
+/* get 16/32 bits from little-endian zip-file to host byteorder */
+extern uint32_t __zzip_get32(unsigned char * s) __attribute__((const));
+extern uint16_t __zzip_get16(unsigned char * s) __attribute__((const));
+extern void __zzip_set32(unsigned char * s, uint32_t v);
+extern void __zzip_set16(unsigned char * s, uint16_t v);
+
+#ifdef ZZIP_WORDS_BIGENDIAN
+# if defined bswap_16 && defined bswap_32 /* a.k.a. linux */
+# define ZZIP_GET16(__p) bswap_16(*(uint16_t*)(__p))
+# define ZZIP_GET32(__p) bswap_32(*(uint32_t*)(__p))
+# define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = bswap_16((uint16_t)(__x)))
+# define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = bswap_32((uint32_t)(__x)))
+# else
+# define ZZIP_GET32(__p) (__zzip_get32((__p)))
+# define ZZIP_GET16(__p) (__zzip_get16((__p)))
+# define ZZIP_SET32(__p,__x) (__zzip_set32((__p),(__x)))
+# define ZZIP_SET16(__p,__x) (__zzip_set16((__p),(__x)))
+# endif
+#else /* little endian is the original zip format byteorder */
+# define ZZIP_GET16(__p) (*(uint16_t*)(__p))
+# define ZZIP_GET32(__p) (*(uint32_t*)(__p))
+# define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = (uint16_t)(__x))
+# define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = (uint32_t)(__x))
+#endif
+
+/* ..................... bitcorrect physical access .................... */
+
+/* zzip_file_header - the local file header */
+#define zzip_file_header_get_magic(__p) ZZIP_GET32((__p)->z_magic)
+#define zzip_file_header_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x))
+#define zzip_file_header_get_flags(__p) ZZIP_GET16((__p)->z_flags)
+#define zzip_file_header_set_flags(__p,__x) ZZIP_SET16((__p)->z_flags,(__x))
+#define zzip_file_header_get_compr(__p) ZZIP_GET16((__p)->z_compr)
+#define zzip_file_header_set_compr(__p,__x) ZZIP_SET16((__p)->z_compr,(__x))
+#define zzip_file_header_get_crc32(__p) ZZIP_GET32((__p)->z_crc32)
+#define zzip_file_header_set_crc32(__p,__x) ZZIP_SET32((__p)->z_crc32,(__x))
+#define zzip_file_header_get_csize(__p) ZZIP_GET32((__p)->z_csize)
+#define zzip_file_header_set_csize(__p,__x) ZZIP_SET32((__p)->z_csize,(__x))
+#define zzip_file_header_get_usize(__p) ZZIP_GET32((__p)->z_usize)
+#define zzip_file_header_set_usize(__p,__x) ZZIP_SET32((__p)->z_usize,(__x))
+#define zzip_file_header_get_namlen(__p) ZZIP_GET16((__p)->z_namlen)
+#define zzip_file_header_set_namlen(__p,__x) ZZIP_SET16((__p)->z_namlen,(__x))
+#define zzip_file_header_get_extras(__p) ZZIP_GET16((__p)->z_extras)
+#define zzip_file_header_set_extras(__p,__x) ZZIP_SET16((__p)->z_extras,(__x))
+#define zzip_file_header_sizeof_tails(__p) (zzip_file_header_get_namlen(__p)+\
+ zzip_file_header_get_extras(__p) )
+#define zzip_file_header_check_magic(__p) ZZIP_FILE_HEADER_CHECKMAGIC((__p))
+
+/* zzip_file_trailer - data descriptor per file block */
+#define zzip_file_trailer_get_magic(__p) ZZIP_GET32((__p)->z_magic)
+#define zzip_file_trailer_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x))
+#define zzip_file_header_get_crc32(__p) ZZIP_GET32((__p)->z_crc32)
+#define zzip_file_trailer_set_crc32(__p,__x) ZZIP_SET32((__p)->z_crc32,(__x))
+#define zzip_file_trailer_get_csize(__p) ZZIP_GET32((__p)->z_csize)
+#define zzip_file_trailer_set_csize(__p,__x) ZZIP_SET32((__p)->z_csize,(__x))
+#define zzip_file_trailer_get_usize(__p) ZZIP_GET32((__p)->z_usize)
+#define zzip_file_trailer_set_usize(__p,__x) ZZIP_SET32((__p)->z_usize,(__x))
+#define zzip_file_trailer_sizeof_tails(__p) 0
+#define zzip_file_trailer_check_magic(__p) ZZIP_FILE_TRAILER_CHECKMAGIC((__p))
+/* zzip_disk_entry (currently named zzip_root_dirent) */
+#define zzip_disk_entry_get_magic(__p) ZZIP_GET32((__p)->z_magic)
+#define zzip_disk_entry_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x))
+#define zzip_disk_entry_get_flags(__p) ZZIP_GET16((__p)->z_flags)
+#define zzip_disk_entry_set_flags(__p,__x) ZZIP_SET16((__p)->z_flags,(__x))
+#define zzip_disk_entry_get_compr(__p) ZZIP_GET16((__p)->z_compr)
+#define zzip_disk_entry_set_compr(__p,__x) ZZIP_SET16((__p)->z_compr,(__x))
+#define zzip_disk_entry_get_crc32(__p) ZZIP_GET32((__p)->z_crc32)
+#define zzip_disk_entry_set_crc32(__p,__x) ZZIP_SET32((__p)->z_crc32,(__x))
+#define zzip_disk_entry_get_csize(__p) ZZIP_GET32((__p)->z_csize)
+#define zzip_disk_entry_set_csize(__p,__x) ZZIP_SET32((__p)->z_csize,(__x))
+#define zzip_disk_entry_get_usize(__p) ZZIP_GET32((__p)->z_usize)
+#define zzip_disk_entry_set_usize(__p,__x) ZZIP_SET32((__p)->z_usize,(__x))
+#define zzip_disk_entry_get_namlen(__p) ZZIP_GET16((__p)->z_namlen)
+#define zzip_disk_entry_set_namlen(__p,__x) ZZIP_SET16((__p)->z_namlen,(__x))
+#define zzip_disk_entry_get_extras(__p) ZZIP_GET16((__p)->z_extras)
+#define zzip_disk_entry_set_extras(__p,__x) ZZIP_SET16((__p)->z_extras,(__x))
+#define zzip_disk_entry_get_comment(__p) ZZIP_GET16((__p)->z_comment)
+#define zzip_disk_entry_set_comment(__p,__x) ZZIP_SET16((__p)->z_comment,(__x))
+#define zzip_disk_entry_get_diskstart(__p) ZZIP_GET16((__p)->z_diskstart)
+#define zzip_disk_entry_set_diskstart(__p,__x) ZZIP_SET16((__p)->z_diskstart,(__x))
+#define zzip_disk_entry_get_filetype(__p) ZZIP_GET16((__p)->z_filetype)
+#define zzip_disk_entry_set_filetype(__p,__x) ZZIP_SET16((__p)->z_filetype,(__x))
+#define zzip_disk_entry_get_filemode(__p) ZZIP_GET32((__p)->z_filemode)
+#define zzip_disk_entry_set_filemode(__p,__x) ZZIP_SET32((__p)->z_filemode,(__x))
+#define zzip_disk_entry_get_offset(__p) ZZIP_GET32((__p)->z_offset)
+#define zzip_disk_entry_set_offset(__p,__x) ZZIP_SET32((__p)->z_offset,(__x))
+#define zzip_disk_entry_sizeof_tails(__p) (zzip_disk_entry_get_namlen(__p) +\
+ zzip_disk_entry_get_extras(__p) +\
+ zzip_disk_entry_get_comment(__p) )
+#define zzip_disk_entry_check_magic(__p) ZZIP_DISK_ENTRY_CHECKMAGIC((__p))
+
+/* zzip_disk_trailer - the zip archive entry point */
+#define zzip_disk_trailer_get_magic(__p) ZZIP_GET32((__p)->z_magic)
+#define zzip_disk_trailer_set_magic(__p,__x) ZZIP_SET32((__p)->z_magic,(__x))
+#define zzip_disk_trailer_get_disk(__p) ZZIP_GET16((__p)->z_disk)
+#define zzip_disk_trailer_set_disk(__p,__x) ZZIP_SET16((__p)->z_disk,(__x))
+#define zzip_disk_trailer_get_finaldisk(__p) ZZIP_GET16((__p)->z_finaldisk)
+#define zzip_disk_trailer_set_finaldisk(__p,__x) ZZIP_SET16((__p)->z_finaldisk,(__x))
+#define zzip_disk_trailer_get_entries(__p) ZZIP_GET16((__p)->z_entries)
+#define zzip_disk_trailer_set_entries(__p,__x) ZZIP_SET16((__p)->z_entries,(__x))
+#define zzip_disk_trailer_get_finalentries(__p) ZZIP_GET16((__p)->z_finalentries)
+#define zzip_disk_trailer_set_finalentries(__p,__x) ZZIP_SET16((__p)->z_finalentries,(__x))
+#define zzip_disk_trailer_get_rootsize(__p) ZZIP_GET32((__p)->z_rootsize)
+#define zzip_disk_trailer_set_rootsize(__p,__x) ZZIP_SET32((__p)->z_rootsize,(__x))
+#define zzip_disk_trailer_get_rootseek(__p) ZZIP_GET32((__p)->z_rootseek)
+#define zzip_disk_trailer_set_rootseek(__p,__x) ZZIP_SET32((__p)->z_rootseek,(__x))
+#define zzip_disk_trailer_get_comment(__p) ZZIP_GET16((__p)->z_comment)
+#define zzip_disk_trailer_set_comment(__p,__x) ZZIP_SET16((__p)->z_comment,(__x))
+#define zzip_disk_trailer_sizeof_tails(__p) ( zzip_disk_entry_get_comment(__p))
+#define zzip_disk_trailer_check_magic(__p) ZZIP_DISK_TRAILER_CHECKMAGIC((__p))
+
+/* extra field should be type + size + data + type + size + data ... */
+#define zzip_extra_block_get_datatype(__p) ZZIP_GET16((char*)(__p))
+#define zzip_extra_block_set_datatype(__p,__x) ZZIP_SET16((char*)(__p),__x)
+#define zzip_extra_block_get_datasize(__p) ZZIP_GET16((char*)(__p)+2)
+#define zzip_extra_block_set_datasize(__p,__x) ZZIP_SET16((char*)(__p)+2,__x)
+
+/* .............. some logical typed access wrappers ....................... */
+
+/* zzip_file_header - the local file header */
+#define zzip_file_header_csize(__p) ((zzip_size_t) \
+ zzip_file_header_get_csize(__p))
+#define zzip_file_header_usize(__p) ((zzip_size_t) \
+ zzip_file_header_get_usize(__p))
+#define zzip_file_header_namlen(__p) ((zzip_size_t) \
+ zzip_file_header_get_namlen(__p))
+#define zzip_file_header_extras(__p) ((zzip_size_t) \
+ zzip_file_header_get_extras(__p))
+#define zzip_file_header_sizeof_tail(__p) ((zzip_size_t) \
+ zzip_file_header_sizeof_tails(__p))
+#define zzip_file_header_skiptoend(__p) ((zzip_size_t) \
+ (zzip_file_header_sizeof_tail(__p) + zzip_file_header_headerlength)
+
+#define zzip_file_header_to_filename(__p) ((char*) \
+ ((char*)(__p) + zzip_file_header_headerlength))
+#define zzip_file_header_to_extras(__p) ((char*) \
+ (zzip_file_header_to_filename(__p) + zzip_file_header_namlen(__p)))
+#define zzip_file_header_to_data(__p) ((char*) \
+ (zzip_file_header_to_extras(__p) + zzip_file_header_extras(__p)))
+#define zzip_file_header_to_trailer(__p) ((struct zzip_file_trailer*) \
+ (zzip_file_header_to_data(__p) + zzip_file_header_csize(__p)))
+
+/* zzip_file_trailer - data descriptor per file block */
+#define zzip_file_trailer_csize(__p) ((zzip_size_t) \
+ zzip_file_trailer_get_csize(__p))
+#define zzip_file_trailer_usize(__p) ((zzip_size_t) \
+ zzip_file_trailer_get_usize(__p))
+#define zzip_file_trailer_sizeof_tail(__p) ((zzip_size_t) \
+ zzip_file_trailer_sizeof_tails(__p))
+#define zzip_file_trailer_skiptoend(__p) ((zzip_size_t) \
+ (zzip_file_trailer_sizeof_tail(__p) + zzip_file_trailer_headerlength)
+
+/* zzip_disk_entry (currently named zzip_root_dirent) */
+#define zzip_disk_entry_csize(__p) ((zzip_size_t) \
+ zzip_disk_entry_get_csize(__p))
+#define zzip_disk_entry_usize(__p) ((zzip_size_t) \
+ zzip_disk_entry_get_usize(__p))
+#define zzip_disk_entry_namlen(__p) ((zzip_size_t) \
+ zzip_disk_entry_get_namlen(__p))
+#define zzip_disk_entry_extras(__p) ((zzip_size_t) \
+ zzip_disk_entry_get_extras(__p))
+#define zzip_disk_entry_comment(__p) ((zzip_size_t) \
+ zzip_disk_entry_get_comment(__p))
+#define zzip_disk_entry_diskstart(__p) ((int) \
+ zzip_disk_entry_get_diskstart(__p))
+#define zzip_disk_entry_filetype(__p) ((int) \
+ zzip_disk_entry_get_filetype(__p))
+#define zzip_disk_entry_filemode(__p) ((int) \
+ zzip_disk_entry_get_filemode(__p))
+#define zzip_disk_entry_fileoffset(__p) ((zzip_off_t) \
+ zzip_disk_entry_get_offset(__p))
+#define zzip_disk_entry_sizeof_tail(__p) ((zzip_size_t) \
+ zzip_disk_entry_sizeof_tails(__p))
+#define zzip_disk_entry_skiptoend(__p) ((zzip_size_t) \
+ (zzip_disk_entry_sizeof_tail(__p) + zzip_disk_entry_headerlength)
+
+#define zzip_disk_entry_to_filename(__p) ((char*) \
+ ((char*)(__p) + zzip_disk_entry_headerlength))
+#define zzip_disk_entry_to_extras(__p) ((char*) \
+ (zzip_disk_entry_to_filename(__p) + zzip_disk_entry_namlen(__p)))
+#define zzip_disk_entry_to_comment(__p) ((char*) \
+ (zzip_disk_entry_to_extras(__p) + zzip_disk_entry_extras(__p)))
+#define zzip_disk_entry_to_next_entry(__p) ((struct zzip_disk_entry*) \
+ (zzip_disk_entry_to_comment(__p) + zzip_disk_entry_comment(__p)))
+
+/* zzip_disk_trailer - the zip archive entry point */
+#define zzip_disk_trailer_localdisk(__p) ((int) \
+ zzip_disk_trailer_get_disk(__p))
+#define zzip_disk_trailer_finaldisk(__p) ((int) \
+ zzip_disk_trailer_get_finaldisk(__p))
+#define zzip_disk_trailer_localentries(__p) ((int) \
+ zzip_disk_trailer_get_entries(__p))
+#define zzip_disk_trailer_finalentries(__p) ((int) \
+ zzip_disk_trailer_get_finalentries(__p))
+#define zzip_disk_trailer_rootsize(__p) ((zzip_off_t) \
+ zzip_disk_trailer_get_rootsize(__p))
+#define zzip_disk_trailer_rootseek(__p) ((zzip_off_t) \
+ zzip_disk_trailer_get_rootseek(__p))
+#define zzip_disk_trailer_comment(__p) ((zzip_size_t) \
+ zzip_disk_trailer_get_comment(__p))
+#define zzip_disk_trailer_sizeof_tail(__p) ((zzip_size_t) \
+ zzip_disk_trailer_sizeof_tails(__p))
+#define zzip_disk_trailer_skiptoend(__p) ((zzip_size_t) \
+ (zzip_disk_trailer_sizeof_tail(__p) + zzip_disk_trailer_headerlength)
+
+#define zzip_disk_trailer_to_comment(__p) ((char*) \
+ ((char*)(__p) + zzip_disk_trailer_headerlength))
+#define zzip_disk_trailer_to_endoffile(__p) ((char*) \
+ (zzip_disk_trailer_to_comment(__p) + zzip_disk_trailer_comment(__p)))
+
+/* extra field should be type + size + data + type + size + data ... */
+#define zzip_extra_block_sizeof_tail(__p) ((zzip_size_t) \
+ (zzip_extra_block_get_datasize(__p))
+#define zzip_extra_block_skiptoend(__p) ((zzip_size_t) \
+ (zzip_extra_block_sizeof_tail(__p) + zzip_extra_block_headerlength)
+
+/* ................... and put these to the next level ................ */
+
+#define zzip_file_header_data_encrypted(__p) \
+ ZZIP_IS_ENCRYPTED( zzip_file_header_get_flags(__p) )
+#define zzip_file_header_data_comprlevel(__p) \
+ ZZIP_IS_COMPRLEVEL( zzip_file_header_get_flags(__p) )
+#define zzip_file_header_data_streamed(__p) \
+ ZZIP_IS_STREAMED( zzip_file_header_get_flags(__p) )
+#define zzip_file_header_data_stored(__p) \
+ ( ZZIP_IS_STORED == zzip_file_header_get_compr(__p) )
+#define zzip_file_header_data_deflated(__p) \
+ ( ZZIP_IS_DEFLATED == zzip_file_header_get_compr(__p) )
+
+#define zzip_disk_entry_data_encrypted(__p) \
+ ZZIP_IS_ENCRYPTED( zzip_disk_entry_get_flags(__p) )
+#define zzip_disk_entry_data_comprlevel(__p) \
+ ZZIP_IS_COMPRLEVEL( zzip_disk_entry_get_flags(__p) )
+#define zzip_disk_entry_data_streamed(__p) \
+ ZZIP_IS_STREAMED( zzip_disk_entry_get_flags(__p) )
+#define zzip_disk_entry_data_stored(__p) \
+ ( ZZIP_IS_STORED == zzip_disk_entry_get_compr(__p) )
+#define zzip_disk_entry_data_deflated(__p) \
+ ( ZZIP_IS_DEFLATED == zzip_disk_entry_get_compr(__p) )
+#define zzip_disk_entry_data_ascii(__p) \
+ ( zzip_disk_entry_get_filetype(__p) & 1)
+
+#define zzip_file_header_data_not_deflated(__p) \
+ (zzip_file_header_data_stored(__p))
+#define zzip_file_header_data_std_deflated(__p) \
+ (zzip_file_header_data_deflated(__p) && \
+ zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_STD_COMPR)
+#define zzip_file_header_data_max_deflated(__p) \
+ (zzip_file_header_data_deflated(__p) && \
+ zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_MAX_COMPR)
+#define zzip_file_header_data_low_deflated(__p) \
+ (zzip_file_header_data_deflated(__p) && \
+ zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_LOW_COMPR)
+#define zzip_file_header_data_min_deflated(__p) \
+ (zzip_file_header_data_deflated(__p) && \
+ zzip_file_header_data_comprlevel(__p) == ZZIP_DEFLATED_MIN_COMPR)
+
+#define zzip_disk_entry_data_not_deflated(__p) \
+ (zzip_disk_entry_data_stored(__p))
+#define zzip_disk_entry_data_std_deflated(__p) \
+ (zzip_disk_entry_data_deflated(__p) && \
+ zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_STD_COMPR)
+#define zzip_disk_entry_data_max_deflated(__p) \
+ (zzip_disk_entry_data_deflated(__p) && \
+ zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_MAX_COMPR)
+#define zzip_disk_entry_data_low_deflated(__p) \
+ (zzip_disk_entry_data_deflated(__p) && \
+ zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_LOW_COMPR)
+#define zzip_disk_entry_data_min_deflated(__p) \
+ (zzip_disk_entry_data_deflated(__p) && \
+ zzip_disk_entry_data_comprlevel(__p) == ZZIP_DEFLATED_MIN_COMPR)
+
+#endif
#include <ctype.h>
#include <zzip/format.h>
+#include <zzip/fetch.h>
#include <zzip/__debug.h>
#if 0
dataoff = dir->io->fd.read(dir->fd, (void*)p, sizeof(*p));
if (dataoff < (zzip_ssize_t)sizeof(*p))
{ err = ZZIP_DIR_READ; goto error; }
- if (! ZZIP_FILE_HEADER_CHECKMAGIC(p)) /* PK\3\4 */
+ if (! zzip_file_header_check_magic(p)) /* PK\3\4 */
{ err = ZZIP_CORRUPTED; goto error; }
- dataoff = ZZIP_GET16(p->z_namlen) + ZZIP_GET16(p->z_extras);
+ dataoff = zzip_file_header_sizeof_tail(p);
if (dir->io->fd.seeks(dir->fd, dataoff, SEEK_CUR) < 0)
{ err = ZZIP_DIR_SEEK; goto error; }
* The information was taken from appnote-981119-iz.zip
* at http://www.freesoftware.com/pub/infozip/doc/
* which in turn is based on PKWARE's appnote.txt
+ * (newer link: ftp://ftp.info-zip.org/pub/infozip/doc/)
*/
#ifndef _ZZIP_FORMAT_H /* zzipformat.h */
#define _ZZIP_FORMAT_H
/*
* Overall zipfile format
- * [local file header + file data + data descriptr] ... [central directory] [EOD record]
+ * [local file header + file data stream + checksum descriptor] ...
+ * ... [disk central directory] [disk trailer record]
*/
# ifdef _MSC_VER
char date[2];
} __attribute__((packed));
+#ifdef ZZIP_NEED_PACKED
+/* if your compiler does interesting things about struct packing... */
+typedef char zzip_version_t[2];
+typedef char zzip_dostime_t[4];
+#else
+typedef struct zzip_version zzip_version_t;
+typedef struct zzip_dostime zzip_dostime_t;
+#endif
+
#define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \
( (((char*)(__p))[0]==(__A)) && \
(((char*)(__p))[1]==(__B)) && \
# define ZZIP_FILE_HEADER_MAGIC 0x04034b50
# define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4')
char z_magic[4]; /* local file header signature (0x04034b50) */
- struct zzip_version z_extract; /* version needed to extract */
+ zzip_version_t z_extract; /* version needed to extract */
char z_flags[2]; /* general purpose bit flag */
char z_compr[2]; /* compression method */
- struct zzip_dostime z_dostime; /* last mod file time (dos format) */
+ zzip_dostime_t z_dostime; /* last mod file time (dos format) */
char z_crc32[4]; /* crc-32 */
char z_csize[4]; /* compressed size */
char z_usize[4]; /* uncompressed size */
/* followed by filename (of variable size) */
/* followed by extra field (of variable size) */
} __attribute__((packed));
+#define zzip_file_header_headerlength (4+2+2+2+4+4+4+4+2+2)
/* B. data descriptor
* the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
{
# define ZZIP_FILE_TRAILER_MAGIC 0x08074B50
# define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8')
- uint32_t z_magic; /* data descriptor signature (0x08074b50) */
- uint32_t z_crc32; /* crc-32 */
- uint32_t z_csize; /* compressed size */
- uint32_t z_usize; /* uncompressed size */
+ char z_magic[4]; /* data descriptor signature (0x08074b50) */
+ char z_crc32[4]; /* crc-32 */
+ char z_csize[4]; /* compressed size */
+ char z_usize[4]; /* uncompressed size */
} __attribute__((packed));
+#define zzip_file_trailer_headerlength (4+4+4+4)
/* C. central directory structure:
[file header] . . . end of central dir record
* - a single entry including filename, extras and comment may not exceed 64k.
*/
-struct zzip_root_dirent
+struct zzip_disk_entry
{
-# define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
-# define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
+# define ZZIP_DISK_ENTRY_MAGIC 0x02014b50
+# define ZZIP_DISK_ENTRY_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
char z_magic[4]; /* central file header signature (0x02014b50) */
- struct zzip_version z_encoder; /* version made by */
- struct zzip_version z_extract; /* version need to extract */
+ zzip_version_t z_encoder; /* version made by */
+ zzip_version_t z_extract; /* version need to extract */
char z_flags[2]; /* general purpose bit flag */
char z_compr[2]; /* compression method */
- struct zzip_dostime z_dostime; /* last mod file time&date (dos format) */
+ zzip_dostime_t z_dostime; /* last mod file time&date (dos format) */
char z_crc32[4]; /* crc-32 */
char z_csize[4]; /* compressed size */
char z_usize[4]; /* uncompressed size */
char z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */
char z_filetype[2]; /* internal file attributes, bit0 = ascii */
char z_filemode[4]; /* extrnal file attributes, eg. msdos attrib byte */
- char z_off[4]; /* relative offset of local file header, seekval if singledisk */
+ char z_offset[4]; /* relative offset of local file header, seekval if singledisk */
/* followed by filename (of variable size) */
/* followed by extra field (of variable size) */
/* followed by file comment (of variable size) */
} __attribute__((packed));
+#define zzip_disk_entry_headerlength (4+2+2++2+2+4+4+4+4+2+2+2+2+2+4+4)
+
+
+struct zzip_root_dirent
+{ /* the old name of the structure above */
+# define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
+# define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_DISK_ENTRY_CHECKMAGIC(__p)
+ char z_magic[4];
+ zzip_version_t z_encoder; zzip_version_t z_extract;
+ char z_flags[2]; char z_compr[2]; zzip_dostime_t z_dostime;
+ char z_crc32[4]; char z_csize[4]; char z_usize[4];
+ char z_namlen[2]; char z_extras[2]; char z_comment[2];
+ char z_diskstart[2]; char z_filetype[2]; char z_filemode[4];
+ char z_off[4];
+} __attribute__((packed));
+
/* end of central dir record */
struct zzip_disk_trailer
char z_comment[2]; /* zipfile comment length */
/* followed by zipfile comment (of variable size) */
} __attribute__((packed));
+#define zzip_disk_trailer_headerlength (4+2+2+2+2+4+4+2)
+
+/* extra field should be type + size + data + type + size + data ... */
+struct zzip_extra_block
+{ /* fetch.h macros do not need this struct */
+ char z_datatype[2]; /* as input type - a mere <char*> is okay */
+ char z_datasize[2]; /* being returned by xx_to_extras usually */
+} __attribute__((packed));
+#define zzip_extra_block_headerlength (2+2)
/* z_flags */
#define ZZIP_IS_ENCRYPTED(p) ((*(unsigned char*)p)&1)
#define ZZIP_IS_COMPRLEVEL(p) (((*(unsigned char*)p)>>1)&3)
#define ZZIP_IS_STREAMED(p) (((*(unsigned char*)p)>>3)&1)
+#define ZZIP_IS_PATCHED(p) (((*(unsigned char*)p)>>5)&1)
/* z_compr */
#define ZZIP_IS_STORED 0
#define ZZIP_IS_DEFLATED_BETTER 9
#define ZZIP_IS_IMPLODED_BETTER 10
+/* deflated comprlevel */
+#define ZZIP_DEFLATED_STD_COMPR 0
+#define ZZIP_DEFLATED_MAX_COMPR 1
+#define ZZIP_DEFLATED_LOW_COMPR 2
+#define ZZIP_DEFLATED_MIN_COMPR 3
+
# ifdef _MSC_VER
# pragma pack(pop)
# endif
ZZIP_DIR* /*depracated*/
zzip_dir_alloc_ext_io (zzip_strings_t* ext, const zzip_plugin_io_t io);
-/* get 16/32 bits from little-endian zip-file to host byteorder */
-uint32_t __zzip_get32(unsigned char * s);
-uint16_t __zzip_get16(unsigned char * s);
-
-#ifdef __i386__
-#define ZZIP_GET32(x) (*(uint32_t*)(x))
-#define ZZIP_GET16(x) (*(uint16_t*)(x))
-#else
-#define ZZIP_GET32(x) (__zzip_get32(x))
-#define ZZIP_GET16(x) (__zzip_get16(x))
-#endif
-
#endif /* _ZZIP_H */
#include <zzip/lib.h> /* archive handling */
#include <zzip/file.h>
#include <zzip/format.h>
+#include <zzip/fetch.h>
#include <ctype.h>
#include <errno.h>
/* per default, we use a little hack to correct bad z_rootseek parts */
#define ZZIP_CORRECT_ROOTSEEK 1
-/* ------------------------- fetch helpers --------------------------------- */
-
-/**
- * Make 32 bit value in host byteorder from little-endian mapped octet-data
- * (works also on machines which SIGBUS on misaligned data access (eg. 68000))
- */
-uint32_t __zzip_get32(unsigned char * s)
-{
- return ((uint32_t)s[3] << 24) | ((uint32_t)s[2] << 16)
- | ((uint32_t)s[1] << 8) | (uint32_t)s[0];
-}
-
-/** => __zzip_get32
- * This function does the same for a 16 bit value.
- */
-uint16_t __zzip_get16(unsigned char * s)
-{
- return ((uint16_t)s[1] << 8) | (uint16_t)s[0];
-}
/* --------------------------- internals -------------------------------- */
/* internal functions of zziplib, avoid at all cost, changes w/o warning.
zzip_off_t offset_of_trailer,
struct zzip_disk_trailer* trailer)
{
- if ( (zzip_off_t) ZZIP_GET32(trailer->z_rootseek) >
- offset_of_trailer - (zzip_off_t) ZZIP_GET32(trailer->z_rootsize) &&
- offset_of_trailer > (zzip_off_t) ZZIP_GET32(trailer->z_rootsize))
+ if ( zzip_disk_trailer_rootseek (trailer) >
+ offset_of_trailer - zzip_disk_trailer_rootsize (trailer) &&
+ offset_of_trailer > zzip_disk_trailer_rootsize (trailer))
{
register zzip_off_t offset;
- offset = offset_of_trailer - ZZIP_GET32(trailer->z_rootsize);
- trailer->z_rootseek[0] = offset & 0xff;
- trailer->z_rootseek[1] = offset >> 8 & 0xff;
- trailer->z_rootseek[2] = offset >> 16 & 0xff;
- trailer->z_rootseek[3] = offset >> 24 & 0xff;
- HINT2("new rootseek=%li",
- (long) ZZIP_GET32(trailer->z_rootseek));
+ offset = offset_of_trailer - zzip_disk_trailer_rootsize (trailer);
+ zzip_disk_trailer_set_rootseek (trailer, offset);
+ HINT2("new rootseek=%li", (long) zzip_disk_trailer_rootseek (trailer));
}
}
#define __correct_rootseek(A,B,C)
#ifdef DEBUG
_zzip_inline static void __debug_dir_hdr (struct zzip_dir_hdr* hdr)
{
- if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_root_dirent))
+ if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_disk_entry))
{ WARN1("internal sizeof-mismatch may break wreakage"); }
/* the internal directory structure is never bigger than the
* external zip central directory space had been beforehand
struct zzip_dir_hdr ** hdr_return,
zzip_plugin_io_t io)
{
- auto struct zzip_root_dirent dirent;
+ auto struct zzip_disk_entry dirent;
struct zzip_dir_hdr * hdr;
struct zzip_dir_hdr * hdr0;
uint16_t * p_reclen = 0;
long offset; /* offset from start of root directory */
char* fd_map = 0;
int32_t fd_gap = 0;
- uint16_t u_entries = ZZIP_GET16(trailer->z_entries);
- uint32_t u_rootsize = ZZIP_GET32(trailer->z_rootsize);
- uint32_t u_rootseek = ZZIP_GET32(trailer->z_rootseek);
+ uint16_t u_entries = zzip_disk_trailer_get_entries (trailer);
+ uint32_t u_rootsize = zzip_disk_trailer_get_rootsize (trailer);
+ uint32_t u_rootseek = zzip_disk_trailer_get_rootseek (trailer);
__correct_rootseek (u_rootseek, u_rootsize, trailer);
hdr0 = (struct zzip_dir_hdr*) malloc(u_rootsize);
for (entries=u_entries, offset=0; entries > 0; entries--)
{
- register struct zzip_root_dirent * d;
+ register struct zzip_disk_entry * d;
uint16_t u_extras, u_comment, u_namlen;
if (fd_map)
zzip_debug_xbuf ((unsigned char*) d, sizeof(*d) + 8);
# endif
- u_extras = ZZIP_GET16(d->z_extras);
- u_comment = ZZIP_GET16(d->z_comment);
- u_namlen = ZZIP_GET16(d->z_namlen);
+ u_extras = zzip_disk_entry_get_extras (d);
+ u_comment = zzip_disk_entry_get_comment (d);
+ u_namlen = zzip_disk_entry_get_namlen (d);
HINT5("offset=0x%lx, size %ld, dirent *%p, hdr %p\n",
offset+u_rootseek, (long)u_rootsize, d, hdr);
first structure read.
at the end the whole copied list of structures is copied into
newly allocated buffer */
- hdr->d_crc32 = ZZIP_GET32(d->z_crc32);
- hdr->d_csize = ZZIP_GET32(d->z_csize);
- hdr->d_usize = ZZIP_GET32(d->z_usize);
- hdr->d_off = ZZIP_GET32(d->z_off);
- hdr->d_compr = (uint8_t)ZZIP_GET16(d->z_compr);
+ hdr->d_crc32 = zzip_disk_entry_get_crc32 (d);
+ hdr->d_csize = zzip_disk_entry_get_csize (d);
+ hdr->d_usize = zzip_disk_entry_get_usize (d);
+ hdr->d_off = zzip_disk_entry_get_offset (d);
+ hdr->d_compr = zzip_disk_entry_get_compr (d);
if (hdr->d_compr > 255) hdr->d_compr = 255;
if (offset+sizeof(*d) + u_namlen > u_rootsize)
{ FAIL2("%i's name stretches beyond root directory", entries); break;}
if (fd_map)
- { memcpy(hdr->d_name, fd_map+fd_gap+offset+sizeof(*d), u_namlen); }
+ { memcpy(hdr->d_name, fd_map+fd_gap + offset+sizeof(*d), u_namlen); }
else { io->fd.read(fd, hdr->d_name, u_namlen); }
hdr->d_name[u_namlen] = '\0';
hdr->d_namlen = u_namlen;
dir->io)) != 0)
{ goto error; }
- HINT5("directory = { entries= %d/%d, size= %d, seek= %d } ",
- ZZIP_GET16(trailer.z_entries), ZZIP_GET16(trailer.z_finalentries),
- ZZIP_GET32(trailer.z_rootsize), ZZIP_GET32(trailer.z_rootseek));
+ HINT5("directory = { entries= %ld/%ld, size= %ld, seek= %ld } ",
+ (long) zzip_disk_trailer_localentries (&trailer),
+ (long) zzip_disk_trailer_finalentries (&trailer),
+ (long) zzip_disk_trailer_rootsize (&trailer),
+ (long) zzip_disk_trailer_rootseek (&trailer));
if ( (rv = __zzip_parse_root_directory(dir->fd, &trailer, &dir->hdr0,
dir->io)) != 0)
%define lib lib010
Summary: ZZipLib - libZ-based ZIP-access Library
Name: zziplib
-Version: 0.13.24
+Version: 0.13.26
Release: 1mdk
Serial: 1
Copyright: LGPL