manpagez: man pages & more
info autoconf
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.6.2 Particular Header Checks

These macros check for particular system header files—whether they exist, and in some cases whether they declare certain symbols.


Check whether ‘stdbool.h’ exists and conforms to C99, and cache the result in the ac_cv_header_stdbool_h variable. If the type _Bool is defined, define HAVE__BOOL to 1.

This macro is intended for use by Gnulib (see section Gnulib) and other packages that supply a substitute ‘stdbool.h’ on platforms lacking a conforming one. The AC_HEADER_STDBOOL macro is better for code that explicitly checks for ‘stdbool.h’.


Check whether to enable assertions in the style of ‘assert.h’. Assertions are enabled by default, but the user can override this by invoking configure with the ‘--disable-assert’ option.


Check for the following header files. For the first one that is found and defines ‘DIR’, define the listed C preprocessor macro:


The directory-library declarations in your source code should look something like the following:

#include <sys/types.h>
# include <dirent.h>
# define NAMLEN(dirent) strlen ((dirent)->d_name)
# define dirent direct
# define NAMLEN(dirent) ((dirent)->d_namlen)
#  include <sys/ndir.h>
# endif
# ifdef HAVE_SYS_DIR_H
#  include <sys/dir.h>
# endif
# ifdef HAVE_NDIR_H
#  include <ndir.h>
# 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.

This macro is obsolescent, as all current systems with directory libraries have <dirent.h>. New programs need not use this macro.

Also see AC_STRUCT_DIRENT_D_INO and AC_STRUCT_DIRENT_D_TYPE (see section Particular Structure Checks).


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.


Checks for header ‘resolv.h’, checking for prerequisites first. To properly use ‘resolv.h’, your code should contain something like the following:

#  include <sys/types.h>
#  include <netinet/in.h>   /* inet_ functions / structs */
#  include <arpa/nameser.h> /* DNS HEADER struct */
#  include <netdb.h>
#include <resolv.h>


If the macros S_ISDIR, S_ISREG, etc. 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.

This macro is obsolescent, as no current systems have the bug. New programs need not use this macro.


If ‘stdbool.h’ exists and conforms to C99, define HAVE_STDBOOL_H to 1; if the type _Bool is defined, define HAVE__BOOL to 1. To fulfill the C99 requirements, your program could contain the following code:

# include <stdbool.h>
# ifndef HAVE__BOOL
#  ifdef __cplusplus
typedef bool _Bool;
#  else
#   define _Bool signed char
#  endif
# endif
# define bool _Bool
# define false 0
# define true 1
# define __bool_true_false_are_defined 1

Alternatively you can use the ‘stdbool’ package of Gnulib (see section Gnulib). It simplifies your code so that it can say just #include <stdbool.h>, and it adds support for less-common platforms.

This macro caches its result in the ac_cv_header_stdbool_h variable.

This macro differs from AC_CHECK_HEADER_STDBOOL only in that it defines HAVE_STDBOOL_H whereas AC_CHECK_HEADER_STDBOOL does not.


Define STDC_HEADERS if the system has C header files conforming to ANSI C89 (ISO C90). 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 C89 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 the C standard requires.

If you use this macro, your code can refer to STDC_HEADERS to determine whether the system has conforming header files (and probably C library functions).

This macro caches its result in the ac_cv_header_stdc variable.

This macro is obsolescent, as current systems have conforming header files. New programs need not use this macro.

Nowadays ‘string.h’ is part of the C standard and declares functions like strcpy, and ‘strings.h’ is standardized by Posix and declares BSD functions like bcopy; but historically, string functions were a major sticking point in this area. If you still want to worry about portability to ancient systems without standard 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 ancient systems contained a mix of functions from the C standard and from BSD; some were mostly standard but lacked ‘memmove’; some defined the BSD functions as macros in ‘string.h’ or ‘strings.h’; some had only the BSD functions but ‘string.h’; some declared 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 had the standard versions of those then it probably had most of the others. If you put the following in ‘’:

# This example is obsolescent.
# Nowadays you can omit these macro calls.
AC_CHECK_FUNCS([strchr memcpy])

then, in your code, you can use declarations like this:

/* This example is obsolescent.
   Nowadays you can just #include <string.h>.  */
# include <string.h>
# ifndef HAVE_STRCHR
#  define strchr index
#  define strrchr rindex
# endif
char *strchr (), *strrchr ();
# ifndef HAVE_MEMCPY
#  define memcpy(d, s, n) bcopy ((s), (d), (n))
#  define memmove(d, s, n) bcopy ((s), (d), (n))
# endif

If you use a function like memchr, memset, strtok, or strspn, which have no BSD equivalent, then macros don’t suffice to port to ancient hosts; 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])’.


If ‘sys/wait.h’ exists and is compatible with Posix, 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 compatible, then instead of including it, define the Posix macros with their usual interpretations. Here is an example:

#include <sys/types.h>
# include <sys/wait.h>
# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)

This macro caches its result in the ac_cv_header_sys_wait_h variable.

This macro is obsolescent, as current systems are compatible with Posix. New programs need not use this macro.

_POSIX_VERSION is defined when ‘unistd.h’ is included on Posix systems. If there is no ‘unistd.h’, it is definitely not a Posix system. However, some non-Posix systems do have ‘unistd.h’.

The way to check whether the system supports Posix is:

# include <sys/types.h>
# include <unistd.h>

/* Code for Posix systems.  */


If a program may include both ‘time.h’ and ‘sys/time.h’, define TIME_WITH_SYS_TIME. On some ancient systems, ‘sys/time.h’ included ‘time.h’, but ‘time.h’ was not protected against multiple inclusion, so programs could not explicitly include both files. This macro is useful in programs that use, for example, struct timeval 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]).

# include <sys/time.h>
# include <time.h>
#  include <sys/time.h>
# else
#  include <time.h>
# endif

This macro caches its result in the ac_cv_header_time variable.

This macro is obsolescent, as current systems can include both files when they exist. New programs need not use this macro.


If the use of TIOCGWINSZ requires ‘<sys/ioctl.h>’, then define GWINSZ_IN_SYS_IOCTL. Otherwise TIOCGWINSZ can be found in ‘<termios.h>’.


# include <termios.h>

# include <sys/ioctl.h>

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 26, 2012 using texi2html 5.0.

© 2000-2019
Individual documents may contain additional copyright information.