Guard inclusion of <stdlib.h> with `#if STDC_HEADERS',
[gnulib.git] / m4 / check-decl.m4
1 #serial 6
2
3 dnl This is just a wrapper function to encapsulate this kludge.
4 dnl Putting it in a separate file like this helps share it between
5 dnl different packages.
6 AC_DEFUN(jm_CHECK_DECLS,
7 [
8   headers='
9 #include <stdio.h>
10 #if HAVE_STRING_H
11 # if !STDC_HEADERS && HAVE_MEMORY_H
12 #  include <memory.h>
13 # endif
14 # include <string.h>
15 #else
16 # if HAVE_STRINGS_H
17 #  include <strings.h>
18 # endif
19 #endif
20 #if STDC_HEADERS
21 # include <stdlib.h>
22 #endif
23 #if HAVE_UNISTD_H
24 # include <unistd.h>
25 #endif
26 '
27
28   if test x = y; then
29     dnl This code is deliberately never run via ./configure.
30     dnl FIXME: this is a gross hack to make autoheader put entries
31     dnl for each of these symbols in the config.h.in.
32     dnl Otherwise, I'd have to update acconfig.h every time I change
33     dnl this list of functions.
34     AC_DEFINE(HAVE_DECL_FREE, 1, [Define if this function is declared.])
35     AC_DEFINE(HAVE_DECL_LSEEK, 1, [Define if this function is declared.])
36     AC_DEFINE(HAVE_DECL_MALLOC, 1, [Define if this function is declared.])
37     AC_DEFINE(HAVE_DECL_MEMCHR, 1, [Define if this function is declared.])
38     AC_DEFINE(HAVE_DECL_REALLOC, 1, [Define if this function is declared.])
39     AC_DEFINE(HAVE_DECL_STPCPY, 1, [Define if this function is declared.])
40     AC_DEFINE(HAVE_DECL_STRSTR, 1, [Define if this function is declared.])
41     AC_DEFINE(HAVE_DECL_STRTOUL, 1, [Define if this function is declared.])
42     AC_DEFINE(HAVE_DECL_STRTOULL, 1, [Define if this function is declared.])
43   fi
44
45   jm_CHECK_DECLARATIONS($headers, free lseek malloc \
46                         memchr realloc stpcpy strstr strtoul strtoull)
47 ])