Next: Generic Functions, Previous: Function Portability, Up: Library Functions
These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.
Check how to get
alloca. Tries to get a builtin version by checking for alloca.h or the predefined C preprocessor macros__GNUC__and_AIX. If this macro finds alloca.h, it definesHAVE_ALLOCA_H.If those attempts fail, it looks for the function in the standard C library. If any of those methods succeed, it defines
HAVE_ALLOCA. Otherwise, it sets the output variableALLOCAto ‘${LIBOBJDIR}alloca.o’ and definesC_ALLOCA(so programs can periodically call ‘alloca (0)’ to garbage collect). This variable is separate fromLIBOBJSso multiple programs can share the value ofALLOCAwithout needing to create an actual library, in case only some of them use the code inLIBOBJS. The ‘${LIBOBJDIR}’ prefix serves the same purpose as inLIBOBJS(see AC_LIBOBJ vs LIBOBJS).This macro does not try to get
allocafrom the System V R3 libPW or the System V R4 libucb because those libraries contain some incompatible functions that cause trouble. Some versions do not even containallocaor contain a buggy version. If you still want to use theiralloca, usearto extract alloca.o from them instead of compiling alloca.c.Source files that use
allocashould start with a piece of code like the following, to declare it properly.#if HAVE_ALLOCA_H # include <alloca.h> #elif defined __GNUC__ # define alloca __builtin_alloca #elif defined _AIX # define alloca __alloca #elif defined _MSC_VER # include <malloc.h> # define alloca _alloca #else # include <stddef.h> # ifdef __cplusplus extern "C" # endif void *alloca (size_t); #endif
If the
chownfunction is available and works (in particular, it should accept -1 foruidandgid), defineHAVE_CHOWN.
If the
closedirfunction does not return a meaningful value, defineCLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.Currently this test is implemented by running a test program. When cross compiling the pessimistic assumption that
closedirdoes not return a meaningful value is made.This macro is obsolescent, as
closedirreturns a meaningful value on current systems. New programs need not use this macro.
If the
error_at_linefunction is not found, require anAC_LIBOBJreplacement of ‘error’.
If the
fnmatchfunction conforms to Posix, defineHAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.Unlike the other specific
AC_FUNCmacros,AC_FUNC_FNMATCHdoes not replace a broken/missingfnmatch. This is for historical reasons. SeeAC_REPLACE_FNMATCHbelow.
Behave like
AC_REPLACE_FNMATCH(replace) but also test whetherfnmatchsupports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.
This macro checks for the
forkandvforkfunctions. If a workingforkis found, defineHAVE_WORKING_FORK. This macro checks whetherforkis just a stub by trying to run it.If vfork.h is found, define
HAVE_VFORK_H. If a workingvforkis found, defineHAVE_WORKING_VFORK. Otherwise, definevforkto beforkfor backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations ofvforkand considers the system to not have a workingvforkif it detects any of them. It is not considered to be an implementation error if a child's invocation ofsignalmodifies the parent's signal handler, since child processes rarely change their signal handlers.Since this macro defines
vforkonly for backward compatibility with previous versions of autoconf you're encouraged to define it yourself in new code:#if !HAVE_WORKING_VFORK # define vfork fork #endif
If the
fseekofunction is available, defineHAVE_FSEEKO. Define_LARGEFILE_SOURCEif necessary to make the prototype visible on some systems (e.g., glibc 2.2). Otherwise linkage problems may occur when compiling withAC_SYS_LARGEFILEon largefile-sensitive systems whereoff_tdoes not default to a 64bit entity.
If the
getgroupsfunction is available and works (unlike on Ultrix 4.3, where ‘getgroups (0, 0)’ always fails), defineHAVE_GETGROUPS. SetGETGROUPS_LIBSto any libraries needed to get that function. This macro runsAC_TYPE_GETGROUPS.
Check how to get the system load averages. To perform its tests properly, this macro needs the file getloadavg.c; therefore, be sure to set the
AC_LIBOBJreplacement directory properly (see Generic Functions,AC_CONFIG_LIBOBJ_DIR).If the system has the
getloadavgfunction, defineHAVE_GETLOADAVG, and setGETLOADAVG_LIBSto any libraries necessary to get that function. Also addGETLOADAVG_LIBStoLIBS. Otherwise, require anAC_LIBOBJreplacement for ‘getloadavg’ with source code in dir/getloadavg.c, and possibly define several other C preprocessor macros and output variables:
- Define
C_GETLOADAVG.- Define
SVR4,DGUX,UMAX, orUMAX4_3if on those systems.- If nlist.h is found, define
HAVE_NLIST_H.- If ‘struct nlist’ has an ‘n_un.n_name’ member, define
HAVE_STRUCT_NLIST_N_UN_N_NAME. The obsolete symbolNLIST_NAME_UNIONis still defined, but do not depend upon it.- Programs may need to be installed set-group-ID (or set-user-ID) for
getloadavgto work. In this case, defineGETLOADAVG_PRIVILEGED, set the output variableNEED_SETGIDto ‘true’ (and otherwise to ‘false’), and setKMEM_GROUPto the name of the group that should own the installed program.
Check for
getmntentin the standard C library, and then in the sun, seq, and gen libraries, for unicos, irix 4, ptx, and UnixWare, respectively. Then, ifgetmntentis available, defineHAVE_GETMNTENT.
Define
GETPGRP_VOIDif it is an error to pass 0 togetpgrp; this is the Posix behavior. On older BSD systems, you must pass 0 togetpgrp, as it takes an argument and behaves like Posix'sgetpgid.#if GETPGRP_VOID pid = getpgrp (); #else pid = getpgrp (0); #endifThis macro does not check whether
getpgrpexists at all; if you need to work in that situation, first callAC_CHECK_FUNCforgetpgrp.This macro is obsolescent, as current systems have a
getpgrpwhose signature conforms to Posix. New programs need not use this macro.
If link is a symbolic link, then
lstatshould treat link/ the same as link/.. However, many olderlstatimplementations incorrectly ignore trailing slashes.It is safe to assume that if
lstatincorrectly ignores trailing slashes, then other symbolic-link-aware functions likeunlinkalso incorrectly ignore trailing slashes.If
lstatbehaves properly, defineLSTAT_FOLLOWS_SLASHED_SYMLINK, otherwise require anAC_LIBOBJreplacement oflstat.
If the
mallocfunction is compatible with the GNU C librarymalloc(i.e., ‘malloc (0)’ returns a valid pointer), defineHAVE_MALLOCto 1. Otherwise defineHAVE_MALLOCto 0, ask for anAC_LIBOBJreplacement for ‘malloc’, and definemalloctorpl_mallocso that the nativemallocis not used in the main project.Typically, the replacement file malloc.c should look like (note the ‘#undef malloc’):
#if HAVE_CONFIG_H # include <config.h> #endif #undef malloc #include <sys/types.h> void *malloc (); /* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */ void * rpl_malloc (size_t n) { if (n == 0) n = 1; return malloc (n); }
If the
memcmpfunction is not available, or does not work on 8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16 bytes or more and with at least one buffer not starting on a 4-byte boundary (such as the one on NeXT x86 OpenStep), require anAC_LIBOBJreplacement for ‘memcmp’.This macro is obsolescent, as current systems have a working
memcmp. New programs need not use this macro.
Define
HAVE_MBRTOWCto 1 if the functionmbrtowcand the typembstate_tare properly declared.
If the
mktimefunction is not available, or does not work correctly, require anAC_LIBOBJreplacement for ‘mktime’. For the purposes of this test,mktimeshould conform to the Posix standard and should be the inverse oflocaltime.
If the
mmapfunction exists and works correctly, defineHAVE_MMAP. This checks only private fixed mapping of already-mapped memory.
If the obstacks are found, define
HAVE_OBSTACK, else require anAC_LIBOBJreplacement for ‘obstack’.
If the
reallocfunction is compatible with the GNU C libraryrealloc(i.e., ‘realloc (NULL, 0)’ returns a valid pointer), defineHAVE_REALLOCto 1. Otherwise defineHAVE_REALLOCto 0, ask for anAC_LIBOBJreplacement for ‘realloc’, and definerealloctorpl_reallocso that the nativereallocis not used in the main project. SeeAC_FUNC_MALLOCfor details.
Determines the correct type to be passed for each of the
selectfunction's arguments, and defines those types inSELECT_TYPE_ARG1,SELECT_TYPE_ARG234, andSELECT_TYPE_ARG5respectively.SELECT_TYPE_ARG1defaults to ‘int’,SELECT_TYPE_ARG234defaults to ‘int *’, andSELECT_TYPE_ARG5defaults to ‘struct timeval *’.This macro is obsolescent, as current systems have a
selectwhose signature conforms to Posix. New programs need not use this macro.
If
setpgrptakes no argument (the Posix version), defineSETPGRP_VOID. Otherwise, it is the BSD version, which takes two process IDs as arguments. This macro does not check whethersetpgrpexists at all; if you need to work in that situation, first callAC_CHECK_FUNCforsetpgrp.This macro is obsolescent, as current systems have a
setpgrpwhose signature conforms to Posix. New programs need not use this macro.
Determine whether
statorlstathave the bug that it succeeds when given the zero-length file name as argument. Thestatandlstatfrom SunOS 4.1.4 and the Hurd (as of 1998-11-01) do this.If it does, then define
HAVE_STAT_EMPTY_STRING_BUG(orHAVE_LSTAT_EMPTY_STRING_BUG) and ask for anAC_LIBOBJreplacement of it.These macros are obsolescent, as no current systems have the bug. New programs need not use these macros.
If
setvbuftakes the buffering type as its second argument and the buffer pointer as the third, instead of the other way around, defineSETVBUF_REVERSED.This macro is obsolescent, as no current systems have the bug. New programs need not use this macro.
If the
strcollfunction exists and works correctly, defineHAVE_STRCOLL. This does a bit more than ‘AC_CHECK_FUNCS(strcoll)’, because some systems have incorrect definitions ofstrcollthat should not be used.
If
strerror_ris available, defineHAVE_STRERROR_R, and if it is declared, defineHAVE_DECL_STRERROR_R. If it returns achar *message, defineSTRERROR_R_CHAR_P; otherwise it returns aninterror number. The Thread-Safe Functions option of Posix requiresstrerror_rto returnint, but many systems (including, for example, version 2.2.4 of the GNU C Library) return achar *value that is not necessarily equal to the buffer argument.
Check for
strftimein the intl library, for SCO Unix. Then, ifstrftimeis available, defineHAVE_STRFTIME.This macro is obsolescent, as no current systems require the intl library for
strftime. New programs need not use this macro.
If the
strtodfunction does not exist or doesn't work correctly, ask for anAC_LIBOBJreplacement of ‘strtod’. In this case, because strtod.c is likely to need ‘pow’, set the output variablePOW_LIBto the extra library needed.
If the
strnlenfunction is not available, or is buggy (like the one from AIX 4.3), require anAC_LIBOBJreplacement for it.
If ‘utime (file, NULL)’ sets file's timestamp to the present, define
HAVE_UTIME_NULL.This macro is obsolescent, as all current systems have a
utimethat behaves this way. New programs need not use this macro.
If
vprintfis found, defineHAVE_VPRINTF. Otherwise, if_doprntis found, defineHAVE_DOPRNT. (Ifvprintfis available, you may assume thatvfprintfandvsprintfare also available.)This macro is obsolescent, as all current systems have
vprintf. New programs need not use this macro.
If the
fnmatchfunction does not conform to Posix (seeAC_FUNC_FNMATCH), ask for itsAC_LIBOBJreplacement.The files fnmatch.c, fnmatch_loop.c, and fnmatch_.h in the
AC_LIBOBJreplacement directory are assumed to contain a copy of the source code of GNUfnmatch. If necessary, this source code is compiled as anAC_LIBOBJreplacement, and the fnmatch_.h file is linked to fnmatch.h so that it can be included in place of the system<fnmatch.h>.