tizen 2.4 release
[external/xdelta3.git] / m4 / ax_check_aligned_access_required.m4
1 # ====================================================================================
2 #  http://www.gnu.org/software/autoconf-archive/ax_check_aligned_access_required.html
3 # ====================================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AC_CHECK_ALIGNED_ACCESS_REQUIRED
8 #
9 # DESCRIPTION
10 #
11 #   While the x86 CPUs allow access to memory objects to be unaligned it
12 #   happens that most of the modern designs require objects to be aligned -
13 #   or they will fail with a buserror. That mode is quite known by
14 #   big-endian machines (sparc, etc) however the alpha cpu is little-
15 #   endian.
16 #
17 #   The following function will test for aligned access to be required and
18 #   set a config.h define HAVE_ALIGNED_ACCESS_REQUIRED (name derived by
19 #   standard usage). Structures loaded from a file (or mmapped to memory)
20 #   should be accessed per-byte in that case to avoid segfault type errors.
21 #
22 # LICENSE
23 #
24 #   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
25 #
26 #   This program is free software; you can redistribute it and/or modify it
27 #   under the terms of the GNU General Public License as published by the
28 #   Free Software Foundation; either version 3 of the License, or (at your
29 #   option) any later version.
30 #
31 #   This program is distributed in the hope that it will be useful, but
32 #   WITHOUT ANY WARRANTY; without even the implied warranty of
33 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
34 #   Public License for more details.
35 #
36 #   You should have received a copy of the GNU General Public License along
37 #   with this program. If not, see <http://www.gnu.org/licenses/>.
38 #
39 #   As a special exception, the respective Autoconf Macro's copyright owner
40 #   gives unlimited permission to copy, distribute and modify the configure
41 #   scripts that are the output of Autoconf when processing the Macro. You
42 #   need not follow the terms of the GNU General Public License when using
43 #   or distributing such scripts, even though portions of the text of the
44 #   Macro appear in them. The GNU General Public License (GPL) does govern
45 #   all other use of the material that constitutes the Autoconf Macro.
46 #
47 #   This special exception to the GPL applies to versions of the Autoconf
48 #   Macro released by the Autoconf Archive. When you make and distribute a
49 #   modified version of the Autoconf Macro, you may extend this special
50 #   exception to the GPL to apply to your modified version as well.
51
52 #serial 7
53
54 AC_DEFUN([AX_CHECK_ALIGNED_ACCESS_REQUIRED],
55 [AC_CACHE_CHECK([if pointers to integers require aligned access],
56   [ax_cv_have_aligned_access_required],
57   [AC_TRY_RUN([
58 #include <stdio.h>
59 #include <stdlib.h>
60
61 int main()
62 {
63   char* string = malloc(40);
64   int i;
65   for (i=0; i < 40; i++) string[[i]] = i;
66   {
67      void* s = string;
68      int* p = s+1;
69      int* q = s+2;
70
71      if (*p == *q) { return 1; }
72   }
73   return 0;
74 }
75               ],
76      [ax_cv_have_aligned_access_required=yes],
77      [ax_cv_have_aligned_access_required=no],
78      [ax_cv_have_aligned_access_required=no])
79   ])
80 if test "$ax_cv_have_aligned_access_required" = yes ; then
81   AC_DEFINE([HAVE_ALIGNED_ACCESS_REQUIRED], [1],
82     [Define if pointers to integers require aligned access])
83 fi
84 ])