summaryrefslogtreecommitdiffstats
path: root/m4/vararg.m4
blob: 6bc8dcc0fbe171ca566e7e8d99f783fb53c1860b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
AC_DEFUN([DOVECOT_VA_COPY], [
  AC_CACHE_CHECK([for an implementation of va_copy()],lib_cv_va_copy,[
          AC_RUN_IFELSE([AC_LANG_SOURCE([[
          #include <stdarg.h>
          #include <stdlib.h>
          void f (int i, ...) {
          va_list args1, args2;
          va_start (args1, i);
          va_copy (args2, args1);
          if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
            exit (1);
          va_end (args1); va_end (args2);
          }
          int main() {
            f (0, 42);
            return 0;
          }]])],
          [lib_cv_va_copy=yes],
          [lib_cv_va_copy=no],[])
  ])
  AC_CACHE_CHECK([for an implementation of __va_copy()],lib_cv___va_copy,[
          AC_RUN_IFELSE([AC_LANG_SOURCE([[
          #include <stdarg.h>
          #include <stdlib.h>
          void f (int i, ...) {
          va_list args1, args2;
          va_start (args1, i);
          __va_copy (args2, args1);
          if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
            exit (1);
          va_end (args1); va_end (args2);
          }
          int main() {
            f (0, 42);
            return 0;
          }]])],
          [lib_cv___va_copy=yes],
          [lib_cv___va_copy=no],[])
  ])
  
  if test "x$lib_cv_va_copy" = "xyes"; then
    va_copy_func=va_copy
  else if test "x$lib_cv___va_copy" = "xyes"; then
    va_copy_func=__va_copy
  fi
  fi
  
  if test -n "$va_copy_func"; then
    AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,[A 'va_copy' style function])
  fi
])

AC_DEFUN([DOVECOT_VA_COPY_BYVAL], [
  AC_CACHE_CHECK([whether va_lists can be copied by value],lib_cv_va_val_copy,[
          AC_RUN_IFELSE([AC_LANG_SOURCE([[
          #include <stdarg.h>
          #include <stdlib.h>
          void f (int i, ...) {
          va_list args1, args2;
          va_start (args1, i);
          args2 = args1;
          if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
            exit (1);
          va_end (args1); va_end (args2);
          }
          int main() {
            f (0, 42);
            return 0;
          }]])],
          [lib_cv_va_val_copy=yes],
          [lib_cv_va_val_copy=no],[])
  ])
  
  if test "x$lib_cv_va_val_copy" = "xno"; then
    AC_DEFINE(VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copied as values])
  fi
])