The following macros check for the presence of certain C header files. If there is no macro specifically defined to check for a header file you need, and you don't need to check for any special properties of it, then you can use one of the general header-file check macros.
This section tries to collect knowledge about common headers, and the problem they cause. By definition, this list will always require additions. Please help us keeping it as complete as possible.
Paul Eggert notes that: ISO C 1999 says that inttypes.h includes stdint.h, so there's no need to include stdint.h separately in a standard environment. Many implementations have inttypes.h but not stdint.h (e.g. Solaris 7), but I don't know of any implementation that has stdint.h but not inttypes.h. Nor do I know of any free software that includes stdint.h; stdint.h seems to be a creation of the committee.
These macros check for particular system header files--whether they exist, and in some cases whether they declare certain symbols.
function>AC_HEADER_DIRENT/function> Check for the following header files. For the first one that is found and defines DIR, define the listed C preprocessor macro:
dirent.h | HAVE_DIRENT_H |
sys/ndir.h | HAVE_SYS_NDIR_H |
sys/dir.h | HAVE_SYS_DIR_H |
ndir.h | HAVE_NDIR_H |
The directory-library declarations in your source code should look something like the following:
#if HAVE_DIRENT_H # include dirent.h # define NAMLEN(dirent) strlen((dirent)-d_name) #else # define dirent direct # define NAMLEN(dirent) (dirent)-d_namlen # if HAVE_SYS_NDIR_H # include sys/ndir.h # endif # if HAVE_SYS_DIR_H # include sys/dir.h # endif # if HAVE_NDIR_H # include ndir.h # endif #endif
Using the above declarations, the program would declare variables to be of type struct dirent, not struct direct, and would access the length of a directory entry name by passing a pointer to a struct dirent to the NAMLEN macro.
This macro also checks for the SCO Xenix dir and x libraries.
function>AC_HEADER_MAJOR/function> If sys/types.h does not define major, minor, and makedev, but sys/mkdev.h does, define MAJOR_IN_MKDEV; otherwise, if sys/sysmacros.h does, define MAJOR_IN_SYSMACROS.
function>AC_HEADER_STAT/function> If the macros S_ISDIR, S_ISREG et al. defined in sys/stat.h do not work properly (returning false positives), define STAT_MACROS_BROKEN. This is the case on Tektronix UTekV, Amdahl UTS and Motorola System V/88.
function>AC_HEADER_STDC/function> Define STDC_HEADERS if the system has ansi C header files. Specifically, this macro checks for stdlib.h, stdarg.h, string.h, and float.h; if the system has those, it probably has the rest of the ansi C header files. This macro also checks whether string.h declares memchr (and thus presumably the other mem functions), whether stdlib.h declare free (and thus presumably malloc and other related functions), and whether the ctype.h macros work on characters with the high bit set, as ansi C requires.
Use STDC_HEADERS instead of __STDC__ to determine whether the system has ansi-compliant header files (and probably C library functions) because many systems that have GCC do not have ansi C header files.
On systems without ansi C headers, there is so much variation that it is probably easier to declare the functions you use than to figure out exactly what the system header files declare. Some systems contain a mix of functions ansi and bsd; some are mostly ansi but lack memmove; some define the bsd functions as macros in string.h or strings.h; some have only the bsd functions but string.h; some declare the memory functions in memory.h, some in string.h; etc. It is probably sufficient to check for one string function and one memory function; if the library has the ansi versions of those then it probably has most of the others. If you put the following in configure.ac:
AC_HEADER_STDC AC_CHECK_FUNCS(strchr memcpy)
then, in your code, you can put declarations like this:
#if STDC_HEADERS # include string.h #else # if !HAVE_STRCHR # define strchr index # define strrchr rindex # endif char *strchr (), *strrchr (); # if !HAVE_MEMCPY # define memcpy(d, s, n) bcopy ((s), (d), (n)) # define memmove(d, s, n) bcopy ((s), (d), (n)) # endif #endif
If you use a function like memchr, memset, strtok, or strspn, which have no bsd equivalent, then macros won't suffice; you must provide an implementation of each function. An easy way to incorporate your implementations only when needed (since the ones in system C libraries may be hand optimized) is to, taking memchr for example, put it in memchr.c and use AC_REPLACE_FUNCS(memchr).
function>AC_HEADER_SYS_WAIT/function> If sys/wait.h exists and is compatible with posix.1, define HAVE_SYS_WAIT_H. Incompatibility can occur if sys/wait.h does not exist, or if it uses the old bsd union wait instead of int to store a status value. If sys/wait.h is not posix.1 compatible, then instead of including it, define the posix.1 macros with their usual interpretations. Here is an example:
#include sys/types.h #if HAVE_SYS_WAIT_H # include sys/wait.h #endif #ifndef WEXITSTATUS # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) 8) #endif #ifndef WIFEXITED # define WIFEXITED(stat_val) (((stat_val) 255) == 0) #endif
_POSIX_VERSION is defined when unistd.h is included on posix.1 systems. If there is no unistd.h, it is definitely not a posix.1 system. However, some non-posix.1 systems do have unistd.h.
The way to check if the system supports posix.1 is:
#if HAVE_UNISTD_H # include sys/types.h # include unistd.h #endif #ifdef _POSIX_VERSION /* Code for POSIX.1 systems. */ #endif
function>AC_HEADER_TIME/function> If a program may include both time.h and sys/time.h, define TIME_WITH_SYS_TIME. On some older systems, sys/time.h includes time.h, but time.h is not protected against multiple inclusion, so programs should not explicitly include both files. This macro is useful in programs that use, for example, struct timeval or struct timezone as well as struct tm. It is best used in conjunction with HAVE_SYS_TIME_H, which can be checked for using AC_CHECK_HEADERS(sys/time.h).
#if TIME_WITH_SYS_TIME # include sys/time.h # include time.h #else # if HAVE_SYS_TIME_H # include sys/time.h # else # include time.h # endif #endif
function>AC_HEADER_TIOCGWINSZ/function> If the use of TIOCGWINSZ requires sys/ioctl.h, then define GWINSZ_IN_SYS_IOCTL. Otherwise TIOCGWINSZ can be found in termios.h.
Use:
#if HAVE_TERMIOS_H # include termios.h #endif #if GWINSZ_IN_SYS_IOCTL # include sys/ioctl.h #endif
These macros are used to find system header files not covered by the "particular" test macros. If you need to check the contents of a header as well as find out whether it is present, you have to write your own test for it (Chapter 7).
function>AC_CHECK_HEADER/function> (header-file, [action-if-found], [action-if-not-found], [includes = default-includes]) If the system header file header-file is usable, execute shell commands action-if-found, otherwise execute action-if-not-found. If you just want to define a symbol if the header file is available, consider using AC_CHECK_HEADERS instead.
The meaning of "usable" depends upon the content of includes:
check whether
header-file
can be preprocessed without error.
Check whether
includes #include header-file
can be compiled without error. You may use AC_CHECK_HEADER (and AC_CHECK_HEADERS) to check whether two headers are compatible.
You may pass any kind of dummy content for includes, such as a single space, a comment, to check whether header-file compiles with success.
function>AC_CHECK_HEADERS/function> (header-file…, [action-if-found], [action-if-not-found], [includes = default-includes]) For each given system header file header-file in the whitespace-separated argument list that exists, define HAVE_header-file (in all capitals). If action-if-found is given, it is additional shell code to execute when one of the header files is found. You can give it a value of break to break out of the loop on the first match. If action-if-not-found is given, it is executed when one of the header files is not found.
Be sure to read the documentation of AC_CHECK_HEADER to understand the influence of includes.