2 * align32 - determine if 32 bit accesses must be aligned
4 * Copyright (C) 1999 Landon Curt Noll
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.1 $
21 * @(#) $Id: align32.c,v 30.1 2007/03/16 11:09:46 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/align32.c,v $
24 * Under source code control: 1995/11/23 05:18:06
25 * File existed as early as: 1995
27 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
28 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
36 #include "have_unistd.h"
37 #if defined(HAVE_UNISTD_H)
41 static void buserr(void); /* catch alignment errors */
47 char byte
[2*sizeof(USB32
)]; /* mis-alignment buffer */
48 USB32
*p
; /* mis-alignment pointer */
51 #if defined(MUST_ALIGN32)
53 printf("#define MUST_ALIGN32\t%c* forced to align 32 bit values *%c\n",
56 /* setup to catch alignment bus errors */
57 signal(SIGBUS
, buserr
);
58 signal(SIGSEGV
, buserr
); /* some systems will generate SEGV instead! */
60 /* mis-align our long fetches */
61 for (i
=0; i
< sizeof(USB32
); ++i
) {
62 p
= (USB32
*)(byte
+i
);
67 /* if we got here, then we can mis-align longs */
68 printf("#undef MUST_ALIGN32\t%c* can mis-align 32 bit values *%c\n",
78 * buserr - catch an alignment error
81 * arg to keep ANSI C happy
87 /* alignment is required */
88 printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n",