From 336b22d18abb9f550553ca843e60b19b952e37d8 Mon Sep 17 00:00:00 2001 From: Guido Draheim Date: Thu, 21 May 2009 17:07:39 +0000 Subject: [PATCH] guard against misaligned memory access + replace _zzip_attribute with defines. --- ChangeLog | 12 +- zzip/__hints.h | 10 +- zzip/conf.h | 534 ++++++++++++++++++++++++------------------------- zzip/fetch.h | 75 ++++--- zzip/format.h | 74 +++---- 5 files changed, 366 insertions(+), 339 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9903765..118feaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-05-21 guidod + * zzip/fetch.h: ensure that either direct-bswap or direc-deref is only used + on platforms that do not require aligned memory access. The + latest report from Sylvain Beucler has shown an error a MIPS + platform (named http://www.freedink.org/ running on PSP). + * zzip/fetch.h: replace _zzip_attribute(const) with defines from zzip/__hints.h + * zzip/__hints.h: introduced ZZIP_GNUC_PACKED for __attribute__((packed)) + * zzip/format.h: replace _zzip_attribute(packed) with defines from zzip/__hints.h + * zzip/conf.h: remove _zzip_attribute - not needed anymore. + 2008-12-27 guidod * ax_create_pkgconfig_info needs a definition for datarootdir (introduced in latest autoconf/automake making for an error in ogre3d configuration @@ -12,7 +22,7 @@ 2008-11-24 guidod * BuildRequires: python (for %package doc) - + 2008-03-22 guidod * zzip/fetch.h: honor ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED for the Linux bswap diff --git a/zzip/__hints.h b/zzip/__hints.h index ed5b2ad..94e3910 100644 --- a/zzip/__hints.h +++ b/zzip/__hints.h @@ -18,7 +18,7 @@ # if ZZIP_GNUC_ATLEAST(2,8) # define ZZIP_GNUC_EXTENSION __extension__ # else -# define ZZIP_GNUC_EXTENSION +# define ZZIP_GNUC_EXTENSION # endif #endif @@ -146,6 +146,10 @@ # endif #endif +#ifdef __GNUC__ +#define ZZIP_GNUC_PACKED __attribute__((packed)) +#endif + #ifndef ZZIP_FUNCTION # if ZZIP_GNUC_ATLEAST(2,6) # define ZZIP_FUNC __FUNCTION__ @@ -153,10 +157,10 @@ # elif defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L # define ZZIP_FUNC __func__ # define ZZIP_FUNCTION "" -# else +# else # define ZZIP_FUNC 0 # define ZZIP_FUNCTION "" -# endif +# endif #endif #ifndef ZZIP_STRING diff --git a/zzip/conf.h b/zzip/conf.h index dc197db..52b33e2 100644 --- a/zzip/conf.h +++ b/zzip/conf.h @@ -1,270 +1,264 @@ -/* - * Here we postprocess autoconf generated prefix-config.h entries. - * This is generally for things like "off_t" which is left undefined - * in plain config.h if the host system does already have it but we do - * need the prefix variant - so we add here a #define _zzip_off_t off_t - * - * This file is supposed to only carry '#define's. - * See for definitions that might be seen by the compiler. - * - * Author: - * Guido Draheim - * - * Copyright (c) 2001,2002,2003,2004 Guido Draheim - * All rights reserved, - * use under the restrictions of the - * Lesser GNU General Public License - * or alternatively the restrictions - * of the Mozilla Public License 1.1 - */ - -#ifndef _ZZIP_CONF_H -#define _ZZIP_CONF_H 1 - -#if !defined ZZIP_OMIT_CONFIG_H -# if defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ -# include -# elif defined ZZIP_1_H -# include "zzip-1.h" -# elif defined ZZIP_2_H -# include "zzip-2.h" -# elif defined ZZIP_3_H -# include "zzip-3.h" -# elif defined ZZIP_4_H -# include "zzip-4.h" -# elif defined ZZIP_5_H -# include "zzip-5.h" -# else /* autoconf generated */ -# include -# endif -#endif - -/* especially win32 platforms do not declare off_t so far - see zzip-msvc.h */ -#ifndef _zzip_off_t -#ifdef ZZIP_off_t -#define _zzip_off_t ZZIP_off_t -#else -#define _zzip_off_t off_t -#endif -#endif - -#ifndef _zzip_off64_t -#ifdef ZZIP_off64_t -#define _zzip_off64_t ZZIP_off64_t -#else -#define _zzip_off64_t off64_t -#endif -#endif - -/* currently unused, all current zziplib-users do have ansi-C94 compilers. */ -#ifndef _zzip_const -#ifdef ZZIP_const -#define _zzip_const ZZIP_const -#else -#define _zzip_const const -#endif -#endif -#ifndef _zzip_inline -#ifdef ZZIP_inline -#define _zzip_inline ZZIP_inline -#else -#define _zzip_inline inline -#endif -#endif -#ifndef _zzip_restrict -#ifdef ZZIP_restrict -#define _zzip_restrict ZZIP_restrict -#else -#define _zzip_restrict restrict -#endif -#endif -#if defined __linux__ && __GNUC__+0 >= 4 -#define zzip__new__ __attribute__((malloc)) -#elif defined __linux__ && __GNUC__+0 >= 3 && __GNUC_MINOR_+0 >= 3 -#define zzip__new__ __attribute__((malloc)) -#else -#define zzip__new__ -#endif - -#ifndef _zzip_size_t -#ifdef ZZIP_size_t -#define _zzip_size_t ZZIP_size_t -#else -#define _zzip_size_t size_t -#endif -#endif -#ifndef _zzip_ssize_t -#ifdef ZZIP_ssize_t -#define _zzip_ssize_t ZZIP_ssize_t -#else -#define _zzip_ssize_t ssize_t -#endif -#endif -#ifndef _zzip___int64 -#ifdef ZZIP___int64 -#define _zzip___int64 ZZIP___int64 -#else -#define _zzip___int64 long long -#endif -#endif - -/* whether this library shall use a 64bit off_t largefile variant in 64on32: */ -/* (some exported names must be renamed to avoid bad calls after linking) */ -#if defined ZZIP_LARGEFILE_SENSITIVE -# if _FILE_OFFSET_BITS+0 == 64 -# define ZZIP_LARGEFILE_RENAME -# elif defined _LARGE_FILES /* used on older AIX to get at 64bit off_t */ -# define ZZIP_LARGEFILE_RENAME -# elif defined _ZZIP_LARGEFILE /* or simply use this one for zzip64 runs */ -# define ZZIP_LARGEFILE_RENAME -# endif -#endif - -/* if the environment did not setup these for 64bit off_t largefile... */ -#ifdef ZZIP_LARGEFILE_RENAME -# ifndef _FILE_OFFSET_BITS -# ifdef ZZIP__FILE_OFFSET_BITS /* == 64 */ -# define _FILE_OFFSET_BITS ZZIP__FILE_OFFSET_BITS -# endif -# endif -# ifndef _LARGE_FILES -# ifdef ZZIP__LARGE_FILES /* == 1 */ -# define _LARGE_FILES ZZIP__LARGE_FILES -# endif -# endif -# ifndef _LARGEFILE_SOURCE -# ifdef ZZIP__LARGEFILE_SOURCE /* == 1 */ -# define _LARGEFILE_SOURCE ZZIP__LARGEFILE_SOURCE -# endif -# endif -#endif - -#include - -/* mingw32msvc errno : would be in winsock.h */ -#ifndef EREMOTE -#define EREMOTE ESPIPE -#endif - -#ifndef ELOOP -#if defined EILSEQ -#define ELOOP EILSEQ -#else -#define ELOOP ENOEXEC -#endif -#endif - -#if defined __WATCOMC__ -#undef _zzip_inline -#define _zzip_inline static -#endif - -#if defined _MSC_VER || defined __WATCOMC__ -#include -#endif - -#ifdef _MSC_VER -# if !__STDC__ -# ifndef _zzip_lseek -# define _zzip_lseek _lseek -# endif -# ifndef _zzip_read -# define _zzip_read _read -# endif -# ifndef _zzip_write -# define _zzip_write _write -# endif -# if 0 -# ifndef _zzip_stat -# define _zzip_stat _stat -# endif -# endif -# endif /* !__STDC__ */ -#endif - /*MSVC*/ - -#if defined _MSC_VER || defined __WATCOMC__ -# ifndef strcasecmp -# define strcasecmp _stricmp -# endif -#endif - -# ifndef _zzip_lseek -# define _zzip_lseek lseek -# endif - -# ifndef _zzip_read -# define _zzip_read read -# endif - -# ifndef _zzip_write -# define _zzip_write write -# endif - -# if 0 -# ifndef _zzip_stat -# define _zzip_stat stat -# endif -# endif - - -#if defined __GNUC__ || defined __attribute__ -#define __zzip_attribute__(X) __attribute__(X) -#else -#define __zzip_attribute__(X) -#endif - -#if defined ZZIP_EXPORTS || defined ZZIPLIB_EXPORTS -# undef ZZIP_DLL -#define ZZIP_DLL 1 -#endif - -/* based on zconf.h : */ -/* compile with -DZZIP_DLL for Windows DLL support */ -#if defined ZZIP_DLL -# if defined _WINDOWS || defined WINDOWS || defined _WIN32 -/*# include */ -# endif -# if !defined _zzip_export && defined _MSC_VER && (defined WIN32 || defined _WIN32) -# define _zzip_export __declspec(dllexport) /*WINAPI*/ -# endif -# if !defined _zzip_export && defined __BORLANDC__ -# if __BORLANDC__ >= 0x0500 && defined WIN32 -# include -# define _zzip_export __declspec(dllexport) /*WINAPI*/ -# else -# if defined _Windows && defined __DLL__ -# define _zzip_export _export -# endif -# endif -# endif -# if !defined _zzip_export && defined __GNUC__ -# if defined __declspec -# define _zzip_export extern __declspec(dllexport) -# else -# define _zzip_export extern -# endif -# endif -# if !defined _zzip_export && defined __BEOS__ -# define _zzip_export extern __declspec(export) -# endif -# if !defined _zzip_export && defined __WATCOMC__ -# define _zzip_export extern __declspec(dllexport) -# define ZEXPORT __syscall -# define ZEXTERN extern -# endif -#endif - -#if !defined _zzip_export -# if defined __GNUC__ /* || !defined HAVE_LIBZZIP */ -# define _zzip_export extern -# elif defined __declspec || (defined _MSC_VER && defined ZZIP_DLL) -# define _zzip_export extern __declspec(dllimport) -# else -# define _zzip_export extern -# endif -#endif - -#endif - - +/* + * Here we postprocess autoconf generated prefix-config.h entries. + * This is generally for things like "off_t" which is left undefined + * in plain config.h if the host system does already have it but we do + * need the prefix variant - so we add here a #define _zzip_off_t off_t + * + * This file is supposed to only carry '#define's. + * See for definitions that might be seen by the compiler. + * + * Author: + * Guido Draheim + * + * Copyright (c) 2001,2002,2003,2004 Guido Draheim + * All rights reserved, + * use under the restrictions of the + * Lesser GNU General Public License + * or alternatively the restrictions + * of the Mozilla Public License 1.1 + */ + +#ifndef _ZZIP_CONF_H +#define _ZZIP_CONF_H 1 + +#if !defined ZZIP_OMIT_CONFIG_H +# if defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ +# include +# elif defined ZZIP_1_H +# include "zzip-1.h" +# elif defined ZZIP_2_H +# include "zzip-2.h" +# elif defined ZZIP_3_H +# include "zzip-3.h" +# elif defined ZZIP_4_H +# include "zzip-4.h" +# elif defined ZZIP_5_H +# include "zzip-5.h" +# else /* autoconf generated */ +# include +# endif +#endif + +/* especially win32 platforms do not declare off_t so far - see zzip-msvc.h */ +#ifndef _zzip_off_t +#ifdef ZZIP_off_t +#define _zzip_off_t ZZIP_off_t +#else +#define _zzip_off_t off_t +#endif +#endif + +#ifndef _zzip_off64_t +#ifdef ZZIP_off64_t +#define _zzip_off64_t ZZIP_off64_t +#else +#define _zzip_off64_t off64_t +#endif +#endif + +/* currently unused, all current zziplib-users do have ansi-C94 compilers. */ +#ifndef _zzip_const +#ifdef ZZIP_const +#define _zzip_const ZZIP_const +#else +#define _zzip_const const +#endif +#endif +#ifndef _zzip_inline +#ifdef ZZIP_inline +#define _zzip_inline ZZIP_inline +#else +#define _zzip_inline inline +#endif +#endif +#ifndef _zzip_restrict +#ifdef ZZIP_restrict +#define _zzip_restrict ZZIP_restrict +#else +#define _zzip_restrict restrict +#endif +#endif +#if defined __linux__ && __GNUC__+0 >= 4 +#define zzip__new__ __attribute__((malloc)) +#elif defined __linux__ && __GNUC__+0 >= 3 && __GNUC_MINOR_+0 >= 3 +#define zzip__new__ __attribute__((malloc)) +#else +#define zzip__new__ +#endif + +#ifndef _zzip_size_t +#ifdef ZZIP_size_t +#define _zzip_size_t ZZIP_size_t +#else +#define _zzip_size_t size_t +#endif +#endif +#ifndef _zzip_ssize_t +#ifdef ZZIP_ssize_t +#define _zzip_ssize_t ZZIP_ssize_t +#else +#define _zzip_ssize_t ssize_t +#endif +#endif +#ifndef _zzip___int64 +#ifdef ZZIP___int64 +#define _zzip___int64 ZZIP___int64 +#else +#define _zzip___int64 long long +#endif +#endif + +/* whether this library shall use a 64bit off_t largefile variant in 64on32: */ +/* (some exported names must be renamed to avoid bad calls after linking) */ +#if defined ZZIP_LARGEFILE_SENSITIVE +# if _FILE_OFFSET_BITS+0 == 64 +# define ZZIP_LARGEFILE_RENAME +# elif defined _LARGE_FILES /* used on older AIX to get at 64bit off_t */ +# define ZZIP_LARGEFILE_RENAME +# elif defined _ZZIP_LARGEFILE /* or simply use this one for zzip64 runs */ +# define ZZIP_LARGEFILE_RENAME +# endif +#endif + +/* if the environment did not setup these for 64bit off_t largefile... */ +#ifdef ZZIP_LARGEFILE_RENAME +# ifndef _FILE_OFFSET_BITS +# ifdef ZZIP__FILE_OFFSET_BITS /* == 64 */ +# define _FILE_OFFSET_BITS ZZIP__FILE_OFFSET_BITS +# endif +# endif +# ifndef _LARGE_FILES +# ifdef ZZIP__LARGE_FILES /* == 1 */ +# define _LARGE_FILES ZZIP__LARGE_FILES +# endif +# endif +# ifndef _LARGEFILE_SOURCE +# ifdef ZZIP__LARGEFILE_SOURCE /* == 1 */ +# define _LARGEFILE_SOURCE ZZIP__LARGEFILE_SOURCE +# endif +# endif +#endif + +#include + +/* mingw32msvc errno : would be in winsock.h */ +#ifndef EREMOTE +#define EREMOTE ESPIPE +#endif + +#ifndef ELOOP +#if defined EILSEQ +#define ELOOP EILSEQ +#else +#define ELOOP ENOEXEC +#endif +#endif + +#if defined __WATCOMC__ +#undef _zzip_inline +#define _zzip_inline static +#endif + +#if defined _MSC_VER || defined __WATCOMC__ +#include +#endif + +#ifdef _MSC_VER +# if !__STDC__ +# ifndef _zzip_lseek +# define _zzip_lseek _lseek +# endif +# ifndef _zzip_read +# define _zzip_read _read +# endif +# ifndef _zzip_write +# define _zzip_write _write +# endif +# if 0 +# ifndef _zzip_stat +# define _zzip_stat _stat +# endif +# endif +# endif /* !__STDC__ */ +#endif + /*MSVC*/ + +#if defined _MSC_VER || defined __WATCOMC__ +# ifndef strcasecmp +# define strcasecmp _stricmp +# endif +#endif + +# ifndef _zzip_lseek +# define _zzip_lseek lseek +# endif + +# ifndef _zzip_read +# define _zzip_read read +# endif + +# ifndef _zzip_write +# define _zzip_write write +# endif + +# if 0 +# ifndef _zzip_stat +# define _zzip_stat stat +# endif +# endif + + +#if defined ZZIP_EXPORTS || defined ZZIPLIB_EXPORTS +# undef ZZIP_DLL +#define ZZIP_DLL 1 +#endif + +/* based on zconf.h : */ +/* compile with -DZZIP_DLL for Windows DLL support */ +#if defined ZZIP_DLL +# if defined _WINDOWS || defined WINDOWS || defined _WIN32 +/*# include */ +# endif +# if !defined _zzip_export && defined _MSC_VER && (defined WIN32 || defined _WIN32) +# define _zzip_export __declspec(dllexport) /*WINAPI*/ +# endif +# if !defined _zzip_export && defined __BORLANDC__ +# if __BORLANDC__ >= 0x0500 && defined WIN32 +# include +# define _zzip_export __declspec(dllexport) /*WINAPI*/ +# else +# if defined _Windows && defined __DLL__ +# define _zzip_export _export +# endif +# endif +# endif +# if !defined _zzip_export && defined __GNUC__ +# if defined __declspec +# define _zzip_export extern __declspec(dllexport) +# else +# define _zzip_export extern +# endif +# endif +# if !defined _zzip_export && defined __BEOS__ +# define _zzip_export extern __declspec(export) +# endif +# if !defined _zzip_export && defined __WATCOMC__ +# define _zzip_export extern __declspec(dllexport) +# define ZEXPORT __syscall +# define ZEXTERN extern +# endif +#endif + +#if !defined _zzip_export +# if defined __GNUC__ /* || !defined HAVE_LIBZZIP */ +# define _zzip_export extern +# elif defined __declspec || (defined _MSC_VER && defined ZZIP_DLL) +# define _zzip_export extern __declspec(dllimport) +# else +# define _zzip_export extern +# endif +#endif + +#endif + + diff --git a/zzip/fetch.h b/zzip/fetch.h index 860260a..de64594 100644 --- a/zzip/fetch.h +++ b/zzip/fetch.h @@ -2,8 +2,9 @@ #define _ZZIP_FORMATS_H #include -#include +#include #include +#include /* linux knows "byteswap.h" giving us an optimized variant */ #ifdef ZZIP_HAVE_BYTESWAP_H @@ -15,42 +16,60 @@ extern "C" { #endif /* get 16/32 bits from little-endian zip-file to host byteorder */ -extern uint32_t __zzip_get32(zzip_byte_t * s) __zzip_attribute__((const)); -extern uint16_t __zzip_get16(zzip_byte_t * s) __zzip_attribute__((const)); +extern uint32_t __zzip_get32(zzip_byte_t * s) ZZIP_GNUC_CONST; +extern uint16_t __zzip_get16(zzip_byte_t * s) ZZIP_GNUC_CONST; extern void __zzip_set32(zzip_byte_t * s, uint32_t v); extern void __zzip_set16(zzip_byte_t * s, uint16_t v); -extern uint64_t __zzip_get64(zzip_byte_t * s) __zzip_attribute__((const)); +extern uint64_t __zzip_get64(zzip_byte_t * s) ZZIP_GNUC_CONST; extern void __zzip_set64(zzip_byte_t * s, uint64_t v); +/* just in case that you use a non-configure-d setup (e.g. MSVC) */ +#ifndef ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED +# if defined __mips__ || defined __sparc__ || defined __powerpc__ || defined __arm__ || defined __ia64__ +# define ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED 11 +# endif +#endif + +/* on linux with a cisc processor we can use the bswap for some extra speed */ #ifdef ZZIP_WORDS_BIGENDIAN -# if defined bswap_16 && defined bswap_32 && defined bswap_64 /* i.e. linux */ # ifndef ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED -# define _ZZIP_USE_BSWAP +# if defined bswap_16 && defined bswap_32 && defined bswap_64 /* i.e. linux */ +# define _ZZIP_USE_BSWAP +# endif # endif +#endif + +/* little endian on intel cisc processors is the original zip format byteorder */ +#ifndef ZZIP_WORDS_BIGENDIAN +# ifndef ZZIP_HAVE_ALIGNED_ACCESS_REQUIRED +# if defined __i386__ || defined __x86_64__ +# define _ZZIP_USE_DEREF # endif -# ifdef _ZZIP_USE_BSWAP -# define ZZIP_GET16(__p) bswap_16(*(uint16_t*)(__p)) -# define ZZIP_GET32(__p) bswap_32(*(uint32_t*)(__p)) -# define ZZIP_GET64(__p) bswap_64(*(uint64_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))) -# define ZZIP_SET64(__p,__x) (*(uint64_t*)(__p) = bswap_64((uint64_t)(__x))) -# else -# define ZZIP_GET64(__p) (__zzip_get64((__p))) -# define ZZIP_GET32(__p) (__zzip_get32((__p))) -# define ZZIP_GET16(__p) (__zzip_get16((__p))) -# define ZZIP_SET64(__p,__x) (__zzip_set64((__p),(__x))) -# 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_GET64(__p) (*(uint64_t*)(__p)) -# define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = (uint16_t)(__x)) -# define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = (uint32_t)(__x)) -# define ZZIP_SET64(__p,__x) (*(uint64_t*)(__p) = (uint64_t)(__x)) +#endif + +#ifdef _ZZIP_USE_BSWAP +#define ZZIP_GET16(__p) bswap_16(*(uint16_t*)(__p)) +#define ZZIP_GET32(__p) bswap_32(*(uint32_t*)(__p)) +#define ZZIP_GET64(__p) bswap_64(*(uint64_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))) +#define ZZIP_SET64(__p,__x) (*(uint64_t*)(__p) = bswap_64((uint64_t)(__x))) +#elif defined _ZZIP_USE_DEREF +#define ZZIP_GET16(__p) (*(uint16_t*)(__p)) +#define ZZIP_GET32(__p) (*(uint32_t*)(__p)) +#define ZZIP_GET64(__p) (*(uint64_t*)(__p)) +#define ZZIP_SET16(__p,__x) (*(uint16_t*)(__p) = (uint16_t)(__x)) +#define ZZIP_SET32(__p,__x) (*(uint32_t*)(__p) = (uint32_t)(__x)) +#define ZZIP_SET64(__p,__x) (*(uint64_t*)(__p) = (uint64_t)(__x)) +#else +#define ZZIP_GET64(__p) (__zzip_get64((__p))) +#define ZZIP_GET32(__p) (__zzip_get32((__p))) +#define ZZIP_GET16(__p) (__zzip_get16((__p))) +#define ZZIP_SET64(__p,__x) (__zzip_set64((__p),(__x))) +#define ZZIP_SET32(__p,__x) (__zzip_set32((__p),(__x))) +#define ZZIP_SET16(__p,__x) (__zzip_set16((__p),(__x))) +#endif #endif /* ..................... bitcorrect physical access .................... */ diff --git a/zzip/format.h b/zzip/format.h index fba4000..1a7ad14 100644 --- a/zzip/format.h +++ b/zzip/format.h @@ -1,12 +1,12 @@ /* - * Author: + * Author: * Guido Draheim * * Copyright (c) 2000,2001,2002,2003 Guido Draheim * All rights reserved * use under the restrictions of the * Lesser GNU General Public License - * or alternatively the restrictions + * or alternatively the restrictions * of the Mozilla Public License 1.1 * * The information was taken from appnote-981119-iz.zip @@ -16,31 +16,31 @@ */ #ifndef _ZZIP_FORMAT_H /* zzipformat.h */ #define _ZZIP_FORMAT_H - + #include /* we have ICO C 9X types defined */ -/* - * Overall zipfile format - * [local file header + file data stream + checksum descriptor] ... +/* + * Overall zipfile format + * [local file header + file data stream + checksum descriptor] ... * ... [disk central directory] [disk trailer record] */ - + # ifdef _MSC_VER # pragma pack(push, 1) # endif -struct zzip_version -{ - zzip_byte_t version[1]; - zzip_byte_t ostype[1]; -} __zzip_attribute__((packed)); +struct zzip_version +{ + zzip_byte_t version[1]; + zzip_byte_t ostype[1]; +} ZZIP_GNUC_PACKED; -struct zzip_dostime -{ - zzip_byte_t time[2]; - zzip_byte_t date[2]; -} __zzip_attribute__((packed)); +struct zzip_dostime +{ + zzip_byte_t time[2]; + zzip_byte_t date[2]; +} ZZIP_GNUC_PACKED; #ifdef ZZIP_NEED_PACKED /* if your compiler does interesting things about struct packing... */ @@ -74,10 +74,10 @@ struct zzip_file_header zzip_byte_t z_extras[2]; /* extra field length */ /* followed by filename (of variable size) */ /* followed by extra field (of variable size) */ -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; #define zzip_file_header_headerlength (4+2+2+2+4+4+4+4+2+2) -/* B. data descriptor +/* B. data descriptor * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned * and immediately follows the last byte of compressed data. It is only used if * the output media of the compressor was not seekable, eg. standard output. @@ -90,14 +90,14 @@ struct zzip_file_trailer zzip_byte_t z_crc32[4]; /* crc-32 */ zzip_byte_t z_csize[4]; /* compressed size */ zzip_byte_t z_usize[4]; /* uncompressed size */ -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; #define zzip_file_trailer_headerlength (4+4+4+4) /* C. central directory structure: - [file header] . . . end of central dir record + [file header] . . . end of central dir record */ -/* directory file header +/* directory file header * - a single entry including filename, extras and comment may not exceed 64k. */ @@ -124,7 +124,7 @@ struct zzip_disk_entry /* followed by filename (of variable size) */ /* followed by extra field (of variable size) */ /* followed by file comment (of variable size) */ -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; #define zzip_disk_entry_headerlength (4+2+2+2+2+4+4+4+4+2+2+2+2+2+4+4) @@ -133,22 +133,22 @@ struct zzip_root_dirent # define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50 # define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_DISK_ENTRY_CHECKMAGIC(__p) zzip_byte_t z_magic[4]; - zzip_version_t z_encoder; + zzip_version_t z_encoder; zzip_version_t z_extract; - zzip_byte_t z_flags[2]; - zzip_byte_t z_compr[2]; + zzip_byte_t z_flags[2]; + zzip_byte_t z_compr[2]; zzip_dostime_t z_dostime; - zzip_byte_t z_crc32[4]; - zzip_byte_t z_csize[4]; + zzip_byte_t z_crc32[4]; + zzip_byte_t z_csize[4]; zzip_byte_t z_usize[4]; - zzip_byte_t z_namlen[2]; - zzip_byte_t z_extras[2]; - zzip_byte_t z_comment[2]; - zzip_byte_t z_diskstart[2]; - zzip_byte_t z_filetype[2]; + zzip_byte_t z_namlen[2]; + zzip_byte_t z_extras[2]; + zzip_byte_t z_comment[2]; + zzip_byte_t z_diskstart[2]; + zzip_byte_t z_filetype[2]; zzip_byte_t z_filemode[4]; zzip_byte_t z_off[4]; -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; /* end of central dir record */ @@ -166,7 +166,7 @@ struct zzip_disk_trailer * the starting disk number */ zzip_byte_t z_comment[2]; /* zipfile comment length */ /* followed by zipfile comment (of variable size) */ -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; #define zzip_disk_trailer_headerlength (4+2+2+2+2+4+4+2) /* extra field should be type + size + data + type + size + data ... */ @@ -174,7 +174,7 @@ struct zzip_extra_block { /* fetch.h macros do not need this struct */ zzip_byte_t z_datatype[2]; /* as input type - a mere is okay */ zzip_byte_t z_datasize[2]; /* being returned by xx_to_extras usually */ -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; #define zzip_extra_block_headerlength (2+2) /* Zip64 end of central dir record */ @@ -194,7 +194,7 @@ struct zzip_disk64_trailer zzip_byte_t z_rootseek[8]; /* offset of start of central directory with respect to * * the starting disk number */ /* followed by zip64 extensible data sector (of variable size) */ -} __zzip_attribute__((packed)); +} ZZIP_GNUC_PACKED; #define zzip_disk64_trailer_headerlength (4+8+2+2+4+4+8+8+8+8) /* z_flags */ -- 2.40.0