>From 9ad02f1a789a74678d429085199e19b04e8b844a Mon Sep 17 00:00:00 2001 From: Peter O'Gorman Date: Mon, 6 Sep 2010 17:20:44 -0500 Subject: [PATCH 3/3] Check if struct packing is required. * am/pack.m4: Check if naturally aligned structs are the correct size. * src/cpiohdr.h: define ATTRIB_PACKED to be empty if not using the attribute. --- am/pack.m4 | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cpiohdr.h | 2 + 2 files changed, 60 insertions(+), 0 deletions(-) diff --git a/am/pack.m4 b/am/pack.m4 index c03c948..85ee6ea 100644 --- a/am/pack.m4 +++ b/am/pack.m4 @@ -16,6 +16,63 @@ # CPIO_PACKED_STRUCTS is based on code from ClamAV AC_DEFUN([CPIO_PACKED_STRUCTS],[ + AC_MSG_CHECKING([if we need to explicitly pack some cpio structs]) + AC_CACHE_VAL([cpio_cv_explicit_pack],[ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +struct old_cpio_header +{ + unsigned short c_magic; + unsigned short c_dev; + unsigned short c_ino; + unsigned short c_mode; + unsigned short c_uid; + unsigned short c_gid; + unsigned short c_nlink; + unsigned short c_rdev; + unsigned short c_mtimes[2]; + unsigned short c_namesize; + unsigned short c_filesizes[2]; +}; +struct old_ascii_header +{ + char c_magic[6]; + char c_dev[6]; + char c_ino[6]; + char c_mode[6]; + char c_uid[6]; + char c_gid[6]; + char c_nlink[6]; + char c_rdev[6]; + char c_mtime[11]; + char c_namesize[6]; + char c_filesize[11]; +}; +struct new_ascii_header +{ + char c_magic[6]; + char c_ino[8]; + char c_mode[8]; + char c_uid[8]; + char c_gid[8]; + char c_nlink[8]; + char c_mtime[8]; + char c_filesize[8]; + char c_dev_maj[8]; + char c_dev_min[8]; + char c_rdev_maj[8]; + char c_rdev_min[8]; + char c_namesize[8]; + char c_chksum[8]; +}; +]],[[ +char a[sizeof(struct new_ascii_header)==110?1:-1]; +char b[sizeof(struct old_ascii_header)==76?1:-1]; +char c[sizeof(struct old_cpio_header)==26?1:-1]; +return sizeof(a) + sizeof(b) + sizeof(c) == 3?0:1; +]])],[cpio_cv_explicit_pack=no],[cpio_cv_explicit_pack=yes])]) +AC_MSG_RESULT($cpio_cv_explicit_pack) + +if test "$cpio_cv_explicit_pack" = yes; then dnl check for __attribute__((packed)) AC_MSG_CHECKING([for structure packing via __attribute__((packed))]) AC_CACHE_VAL(cpio_cv_have_attrib_packed,[ @@ -64,4 +121,5 @@ AC_DEFUN([CPIO_PACKED_STRUCTS],[ if test "$have_attrib_packed" = yes; then AC_DEFINE(HAVE_ATTRIB_PACKED, 1, [attrib packed]) fi +fi ]) diff --git a/src/cpiohdr.h b/src/cpiohdr.h index 86ec988..5367fe9 100644 --- a/src/cpiohdr.h +++ b/src/cpiohdr.h @@ -24,6 +24,8 @@ # ifdef HAVE_ATTRIB_PACKED # define ATTRIB_PACKED __attribute__((packed)) +# else +# define ATTRIB_PACKED # endif # ifdef HAVE_PRAGMA_PACK -- 1.7.0.1