diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-08-05 17:20:51 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-08-05 17:20:51 +0000 |
commit | 7ebfbe1d702adddb27ccad5051bc40bb96242ebf (patch) | |
tree | 71b3c2b0cccc3cb6ab5e634acb7659b8df8c7434 | |
parent | de5d0f87d443b0fa1e9749532f1b6e75a1b20164 (diff) | |
download | navit-svn-7ebfbe1d702adddb27ccad5051bc40bb96242ebf.tar.gz |
Fix:Build:Better approach for #pragma pack vs __attribute__((packed))
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4673 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | config.h.cmake | 2 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | navit/file.c | 18 | ||||
-rw-r--r-- | navit/maptool/maptool.c | 2 | ||||
-rw-r--r-- | navit/maptool/misc.c | 2 | ||||
-rw-r--r-- | navit/maptool/zip.c | 1 | ||||
-rw-r--r-- | navit/zipfile.h | 88 |
8 files changed, 39 insertions, 78 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e1105fb6..4d8ca16b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,6 +420,7 @@ if(WIN32 OR WINCE) endif(HAVE_WINSOCK) if(MSVC) + set(HAVE_PRAGMA_PACK 1) add_plugin(support/xgetopt "Windows detected" TRUE) set(ENABLE_NLS FALSE) else(MSVC) @@ -430,6 +431,7 @@ if(WIN32 OR WINCE) set(XSLTS "windows;${XSLTS}" CACHE STRING "define a semicolon seperated list of XSLTs to process") endif() if (WIN32 AND NOT WINCE) + set(HAVE_PRAGMA_PACK 1) set(HAVE_API_WIN32 1) set(HAVE_STDINT_H 1) #set(BUILD_MAPTOOL FALSE) @@ -438,6 +440,7 @@ if (WIN32 AND NOT WINCE) endif() if(WINCE) add_plugin(support/libc "wince detected" TRUE) + set(HAVE_PRAGMA_PACK 1) set(HAVE_API_WIN32_CE 1) set(BUILD_MAPTOOL FALSE) set_with_reason(vehicle/file "wince: currently broken" FALSE) diff --git a/config.h.cmake b/config.h.cmake index 924e38ca..1df21a20 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -72,3 +72,5 @@ #cmakedefine HAVE_STPCPY 1 #cmakedefine HAVE_SBRK 1 + +#cmakedefine HAVE_PRAGMA_PACK 1 diff --git a/configure.in b/configure.in index b773e9bb..9c979505 100644 --- a/configure.in +++ b/configure.in @@ -95,6 +95,7 @@ wince|mingw32ce|cegcc) win32ce=yes AC_DEFINE(HAVE_API_WIN32_BASE, 1, [Have Windows Base API]) AC_DEFINE(HAVE_API_WIN32_CE, 1, [Have Windows CE API]) + AC_DEFINE(HAVE_PRAGMA_PACK, 1, [Have pragma pack]) gui_win32=yes; gui_win32_reason="host_os is wince" graphics_win32=yes; graphics_win32_reason="host_os is wince" vehicle_wince=yes; vehcile_wince_reason="host_os is wince" diff --git a/navit/file.c b/navit/file.c index 477cf98e..2ce23580 100644 --- a/navit/file.c +++ b/navit/file.c @@ -45,6 +45,7 @@ #include "item.h" #include "util.h" #include "types.h" +#include "zipfile.h" #ifdef HAVE_SOCKET #include <sys/socket.h> #include <netdb.h> @@ -78,20 +79,21 @@ static GHashTable *file_name_hash; static struct cache *file_cache; -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ +#ifdef HAVE_PRAGMA_PACK +#pragma pack(push) +#pragma pack(1) +#endif + struct file_cache_id { long long offset; int size; int file_name_id; int method; -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; +} ATTRIBUTE_PACKED; + +#ifdef HAVE_PRAGMA_PACK #pragma pack(pop) -#endif /* _MSC_VER */ +#endif #ifdef HAVE_SOCKET static int diff --git a/navit/maptool/maptool.c b/navit/maptool/maptool.c index 065783a9..d8d61bea 100644 --- a/navit/maptool/maptool.c +++ b/navit/maptool/maptool.c @@ -37,9 +37,9 @@ #include "file.h" #include "item.h" #include "map.h" -#include "zipfile.h" #include "main.h" #include "config.h" +#include "zipfile.h" #include "linguistics.h" #include "plugin.h" #include "util.h" diff --git a/navit/maptool/misc.c b/navit/maptool/misc.c index 357bdb9b..5e6c39e7 100644 --- a/navit/maptool/misc.c +++ b/navit/maptool/misc.c @@ -36,9 +36,9 @@ #include "file.h" #include "item.h" #include "map.h" -#include "zipfile.h" #include "main.h" #include "config.h" +#include "zipfile.h" #include "linguistics.h" #include "plugin.h" #include "maptool.h" diff --git a/navit/maptool/zip.c b/navit/maptool/zip.c index c8782a55..578f356e 100644 --- a/navit/maptool/zip.c +++ b/navit/maptool/zip.c @@ -21,6 +21,7 @@ #include <string.h> #include <stdlib.h> #include "maptool.h" +#include "config.h" #include "zipfile.h" #ifdef HAVE_LIBCRYPTO diff --git a/navit/zipfile.h b/navit/zipfile.h index bb08760a..0847dbba 100644 --- a/navit/zipfile.h +++ b/navit/zipfile.h @@ -18,12 +18,19 @@ */ #ifndef __ZIPFILE_H__ -#ifdef HAVE_API_WIN32_CE -/* cegcc doesn't honor the __attribute__(packed) need pragma to work */ +#define __ZIPFILE_H__ + +#ifdef HAVE_PRAGMA_PACK #pragma pack(push) #pragma pack(1) #endif +#ifdef __GNUC__ +#define ATTRIBUTE_PACKED __attribute__ ((packed)) +#else +#define ATTRIBUTE_PACKED +#endif + #define zip_split_sig 0x08074b50 struct zip_split { @@ -32,9 +39,6 @@ struct zip_split { #define zip_lfh_sig 0x04034b50 -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip_lfh { int ziplocsig; short zipver; // 4 @@ -48,18 +52,10 @@ struct zip_lfh { unsigned short zipfnln; // 26 unsigned short zipxtraln; // 30 char zipname[0]; // 34 -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; -#pragma pack(pop) -#endif /* _MSC_VER */ +} ATTRIBUTE_PACKED; #define zip_cd_sig 0x02014b50 -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip_cd { int zipcensig; char zipcver; @@ -81,31 +77,14 @@ struct zip_cd { unsigned int zipext; unsigned int zipofst; char zipcfn[0]; -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; -#pragma pack(pop) -#endif /* _MSC_VER */ - +} ATTRIBUTE_PACKED; -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip_cd_ext { short tag; short size; unsigned long long zipofst; -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; -#pragma pack(pop) -#endif /* _MSC_VER */ +} ATTRIBUTE_PACKED; -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip_enc { short efield_header; short efield_size; @@ -113,18 +92,10 @@ struct zip_enc { char vendor_id1,vendor_id2; char encryption_strength; short compress_method; -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; -#pragma pack(pop) -#endif /* _MSC_VER */ +} ATTRIBUTE_PACKED; #define zip_eoc_sig 0x6054b50 -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip_eoc { int zipesig; /* end of central dir signature */ unsigned short zipedsk; /* number of this disk */ @@ -135,18 +106,10 @@ struct zip_eoc { unsigned int zipeofst; /* offset of start of central directory with respect to the starting disk number */ short zipecoml; /* .ZIP file comment length */ char zipecom[0]; /* .ZIP file comment */ -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; -#pragma pack(pop) -#endif /* _MSC_VER */ +} ATTRIBUTE_PACKED; #define zip64_eoc_sig 0x6064b50 -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip64_eoc { int zip64esig; /* zip64 end of central dir signature */ unsigned long long zip64esize; /* size of zip64 end of central directory record */ @@ -159,33 +122,22 @@ struct zip64_eoc { unsigned long long zip64ecsz; /* size of the central directory */ unsigned long long zip64eofst; /* offset of start of central directory with respect to the starting disk number */ char zip64ecom[0]; /* zip64 extensible data sector */ -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ -}; -#pragma pack(pop) -#endif /* _MSC_VER */ +} ATTRIBUTE_PACKED; #define zip64_eocl_sig 0x07064b50 -#ifdef _MSC_VER -#pragma pack(push,1) -#endif /* _MSC_VER */ struct zip64_eocl { int zip64lsig; int zip64ldsk; long long zip64lofst; int zip74lnum; -#ifndef _MSC_VER -}__attribute__ ((packed)); -#else /* _MSC_VER */ +} ATTRIBUTE_PACKED; + +struct zip_alignment_check { + int x[sizeof(struct zip_cd) == 46 ? 1:-1]; }; -#pragma pack(pop) -#endif /* _MSC_VER */ -#define __ZIPFILE_H__ -#ifdef __CEGCC__ +#ifdef HAVE_PRAGMA_PACK #pragma pack(pop) #endif - #endif |