aboutsummaryrefslogtreecommitdiff
path: root/am
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-06-19 14:56:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-06-19 14:56:28 +0300
commit8e7537ce0e443bb757c10854a8a04110ca8ebe3d (patch)
tree6d8ba46f0015e8ceb60dcf0535524acd5fda445b /am
parent1034f14aafe2074d3d3fc6240f32291d85f76e37 (diff)
downloadcpio-8e7537ce0e443bb757c10854a8a04110ca8ebe3d.tar.gz
cpio-8e7537ce0e443bb757c10854a8a04110ca8ebe3d.tar.bz2
Make sure the structs used for I/O mapping are not padded.
* am/flushleft.m4, am/pack.m4: New files. * Makefile.am (ACLOCAL_AMFLAGS): Add -I am. * bootstrap: Fix arguments to aclocal. * configure.ac: Call CPIO_PACKED_STRUCTS. * src/cpiohdr.h: Ensure old_cpio_header, old_ascii_header and new_ascii_header are packed.
Diffstat (limited to 'am')
-rw-r--r--am/flushleft.m428
-rw-r--r--am/pack.m467
2 files changed, 95 insertions, 0 deletions
diff --git a/am/flushleft.m4 b/am/flushleft.m4
new file mode 100644
index 0000000..d1cc11d
--- /dev/null
+++ b/am/flushleft.m4
@@ -0,0 +1,28 @@
+# This file is part of GNU cpio
+# Copyright (C) 2009 Free Software Foundation
+#
+# GNU cpio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU cpio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU cpio. If not, see <http://www.gnu.org/licenses/>.
+
+dnl CPIO_FLUSHLEFT -- remove all whitespace at the beginning of lines
+dnl This is useful for c-code which may include cpp statements
+dnl
+dnl WARNING: When editing this macro, make sure your editor does not
+dnl clobber the regexp argument to m4_bpatsubst: it must contain one
+dnl space and one tab (ASCII 9) character.
+dnl
+AC_DEFUN([CPIO_FLUSHLEFT],
+ [m4_changequote(`,')dnl
+ m4_bpatsubst(`$1', `^[ ]+')
+ m4_changequote([,])])dnl
+
diff --git a/am/pack.m4 b/am/pack.m4
new file mode 100644
index 0000000..c03c948
--- /dev/null
+++ b/am/pack.m4
@@ -0,0 +1,67 @@
+# This file is part of GNU cpio
+# Copyright (C) 2009 Free Software Foundation
+#
+# GNU cpio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU cpio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU cpio. If not, see <http://www.gnu.org/licenses/>.
+
+# CPIO_PACKED_STRUCTS is based on code from ClamAV
+AC_DEFUN([CPIO_PACKED_STRUCTS],[
+ dnl check for __attribute__((packed))
+ AC_MSG_CHECKING([for structure packing via __attribute__((packed))])
+ AC_CACHE_VAL(cpio_cv_have_attrib_packed,[
+ AC_TRY_COMPILE(,
+ [struct { int i __attribute__((packed)); } s; ],
+ [have_attrib_packed=yes],
+ [have_attrib_packed=no])
+ ])
+ AC_MSG_RESULT($have_attrib_packed)
+
+ if test "$have_attrib_packed" = no; then
+ AC_MSG_CHECKING(for structure packing via pragma)
+ AC_CACHE_VAL(cpio_cv_have_pragma_pack,[
+ AC_TRY_RUN(CPIO_FLUSHLEFT([
+ int main(int argc, char **argv) {
+ #pragma pack(1)
+ struct { char c; long l; } s;
+ return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ]),
+ [have_pragma_pack=yes],
+ [have_pragma_pack=no])
+ ])
+ AC_MSG_RESULT($have_pragma_pack)
+ if test "$have_pragma_pack" = yes; then
+ AC_DEFINE(HAVE_PRAGMA_PACK, 1, "pragma pack")
+ else
+ AC_MSG_CHECKING(for structure packing via hppa/hp-ux pragma)
+ AC_CACHE_VAL(cpio_cv_have_pragma_pack_hpux,[
+ AC_TRY_RUN(CPIO_FLUSHLEFT([
+ /* hppa/hp-ux wants pragma outside of function */
+ #pragma pack 1
+ struct { char c; long l; } s;
+ int main(int argc, char **argv) {
+ return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ]),
+ [have_pragma_pack_hpux=yes],
+ [have_pragma_pack_hpux=no])
+ ])
+ AC_MSG_RESULT($have_pragma_pack_hpux)
+ AC_DEFINE(HAVE_PRAGMA_PACK_HPPA, 1, "pragma pack hppa/hp-ux style")
+ fi
+ fi
+
+ if test "${have_attrib_packed}${have_pragma_pack}$have_pragma_pack_hpux" = "nonono"; then
+ AC_MSG_ERROR(Need to know how to pack structures with this compiler)
+ fi
+
+ if test "$have_attrib_packed" = yes; then
+ AC_DEFINE(HAVE_ATTRIB_PACKED, 1, [attrib packed])
+ fi
+])

Return to:

Send suggestions and report system problems to the System administrator.