Next: , Previous: , Up: Header Files   [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.

Macro: AC_CHECK_HEADER_STDBOOL

Check whether stdbool.h exists and conforms to C99 or later, 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 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.

Macro: AC_HEADER_ASSERT

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.

Macro: AC_HEADER_DIRENT

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

dirent.hHAVE_DIRENT_H
sys/ndir.hHAVE_SYS_NDIR_H
sys/dir.hHAVE_SYS_DIR_H
ndir.hHAVE_NDIR_H

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

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

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 Particular Structures).

Macro: AC_HEADER_MAJOR

Detect the headers required to use makedev, major, and minor. These functions may be defined by sys/mkdev.h, sys/sysmacros.h, or sys/types.h.

AC_HEADER_MAJOR defines MAJOR_IN_MKDEV if they are in sys/mkdev.h, or MAJOR_IN_SYSMACROS if they are in sys/sysmacros.h. If neither macro is defined, they are either in sys/types.h or unavailable.

To properly use these functions, your code should contain something like:

#include <sys/types.h>
#ifdef MAJOR_IN_MKDEV
# include <sys/mkdev.h>
#elif defined MAJOR_IN_SYSMACROS
# include <sys/sysmacros.h>
#endif

Note: Configure scripts built with Autoconf 2.69 or earlier will not detect a problem if sys/types.h contains definitions of major, minor, and/or makedev that trigger compiler warnings upon use. This is known to occur with GNU libc 2.25, where those definitions are being deprecated to reduce namespace pollution. If it is not practical to use Autoconf 2.70 to regenerate the configure script of affected software, you can work around the problem by setting ‘ac_cv_header_sys_types_h_makedev=no’, as an argument to configure or as part of a config.site site default file (see Site Defaults).

Macro: AC_HEADER_RESOLV

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

#ifdef HAVE_SYS_TYPES_H
#  include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
#  include <netinet/in.h>   /* inet_ functions / structs */
#endif
#ifdef HAVE_ARPA_NAMESER_H
#  include <arpa/nameser.h> /* DNS HEADER struct */
#endif
#ifdef HAVE_NETDB_H
#  include <netdb.h>
#endif
#include <resolv.h>
Macro: AC_HEADER_STAT

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.

Macro: AC_HEADER_STDBOOL

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

#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# 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
#endif

Alternatively you can use the ‘stdbool’ package of Gnulib (see 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.

Macro: AC_HEADER_STDC

This macro is obsolescent. Its sole effect is to make sure that all the headers that are included by AC_INCLUDES_DEFAULT (see Default Includes), but not part of ISO C90, have been checked for.

All hosted environments that are still of interest for portable code provide all of the headers specified in ISO C90 (as amended in 1995).

Macro: AC_HEADER_SYS_WAIT

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>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif

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:

#ifdef HAVE_UNISTD_H
# include <sys/types.h>
# include <unistd.h>
#endif

#ifdef _POSIX_VERSION
/* Code for Posix systems.  */
#endif
Macro: AC_HEADER_TIOCGWINSZ

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

Use:

#ifdef HAVE_TERMIOS_H
# include <termios.h>
#endif

#ifdef GWINSZ_IN_SYS_IOCTL
# include <sys/ioctl.h>
#endif

Next: , Previous: , Up: Header Files   [Contents][Index]