Next: , Previous: Function Portability, Up: Library Functions


5.5.2 Particular Function Checks

These macros check for particular C functions—whether they exist, and in some cases how they respond when given certain arguments.

— Macro: AC_FUNC_ALLOCA

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 defines HAVE_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 variable ALLOCA to `alloca.o' and defines C_ALLOCA (so programs can periodically call `alloca(0)' to garbage collect). This variable is separate from LIBOBJS so multiple programs can share the value of ALLOCA without needing to create an actual library, in case only some of them use the code in LIBOBJS.

This macro does not try to get alloca from 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 contain alloca or contain a buggy version. If you still want to use their alloca, use ar to extract alloca.o from them instead of compiling alloca.c.

Source files that use alloca should start with a piece of code like the following, to declare it properly. In some versions of AIX, the declaration of alloca must precede everything else except for comments and preprocessor directives. The #pragma directive is indented so that pre-ANSI C compilers will ignore it, rather than choke on it.

          /* AIX requires this to be the first thing in the file.  */
          #ifndef __GNUC__
          # if HAVE_ALLOCA_H
          #  include <alloca.h>
          # else
          #  ifdef _AIX
           #pragma alloca
          #  else
          #   ifndef alloca /* predefined by HP cc +Olibcalls */
          char *alloca ();
          #   endif
          #  endif
          # endif
          #endif
     
— Macro: AC_FUNC_CHOWN

If the chown function is available and works (in particular, it should accept -1 for uid and gid), define HAVE_CHOWN.

— Macro: AC_FUNC_CLOSEDIR_VOID

If the closedir function does not return a meaningful value, define CLOSEDIR_VOID. Otherwise, callers ought to check its return value for an error indicator.

— Macro: AC_FUNC_ERROR_AT_LINE

If the error_at_line function is not found, require an AC_LIBOBJ replacement of `error'.

— Macro: AC_FUNC_FNMATCH

If the fnmatch function conforms to POSIX, define HAVE_FNMATCH. Detect common implementation bugs, for example, the bugs in Solaris 2.4.

Note that for historical reasons, contrary to the other specific AC_FUNC macros, AC_FUNC_FNMATCH does not replace a broken/missing fnmatch. See AC_REPLACE_FNMATCH below.

— Macro: AC_FUNC_FNMATCH_GNU

Behave like AC_REPLACE_FNMATCH (replace) but also test whether fnmatch supports GNU extensions. Detect common implementation bugs, for example, the bugs in the GNU C Library 2.1.

— Macro: AC_FUNC_FORK

This macro checks for the fork and vfork functions. If a working fork is found, define HAVE_WORKING_FORK. This macro checks whether fork is just a stub by trying to run it.

If vfork.h is found, define HAVE_VFORK_H. If a working vfork is found, define HAVE_WORKING_VFORK. Otherwise, define vfork to be fork for backward compatibility with previous versions of autoconf. This macro checks for several known errors in implementations of vfork and considers the system to not have a working vfork if it detects any of them. It is not considered to be an implementation error if a child's invocation of signal modifies the parent's signal handler, since child processes rarely change their signal handlers.

Since this macro defines vfork only 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
     
— Macro: AC_FUNC_FSEEKO

If the fseeko function is available, define HAVE_FSEEKO. Define _LARGEFILE_SOURCE if necessary to make the prototype visible on some systems (e.g. glibc 2.2). Otherwise linkage problems may occur when compiling with AC_SYS_LARGEFILE on largefile-sensitive systems where off_t does not default to a 64bit entity.

— Macro: AC_FUNC_GETGROUPS

If the getgroups function is available and works (unlike on Ultrix 4.3, where `getgroups (0, 0)' always fails), define HAVE_GETGROUPS. Set GETGROUPS_LIBS to any libraries needed to get that function. This macro runs AC_TYPE_GETGROUPS.

— Macro: AC_FUNC_GETLOADAVG

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_LIBOBJ replacement directory properly (see Generic Functions, AC_CONFIG_LIBOBJ_DIR).

If the system has the getloadavg function, define HAVE_GETLOADAVG, and set GETLOADAVG_LIBS to any libraries needed to get that function. Also add GETLOADAVG_LIBS to LIBS. Otherwise, require an AC_LIBOBJ replacement for `getloadavg' with source code in dir/getloadavg.c, and possibly define several other C preprocessor macros and output variables:

  1. Define C_GETLOADAVG.
  2. Define SVR4, DGUX, UMAX, or UMAX4_3 if on those systems.
  3. If nlist.h is found, define HAVE_NLIST_H.
  4. If `struct nlist' has an `n_un.n_name' member, define HAVE_STRUCT_NLIST_N_UN_N_NAME. The obsolete symbol NLIST_NAME_UNION is still defined, but do not depend upon it.
  5. Programs may need to be installed setgid (or setuid) for getloadavg to work. In this case, define GETLOADAVG_PRIVILEGED, set the output variable NEED_SETGID to `true' (and otherwise to `false'), and set KMEM_GROUP to the name of the group that should own the installed program.

— Macro: AC_FUNC_GETMNTENT

Check for getmntent in the sun, seq, and gen libraries, for irix 4, PTX, and Unixware, respectively. Then, if getmntent is available, define HAVE_GETMNTENT.

— Macro: AC_FUNC_GETPGRP

Define GETPGRP_VOID if it is an error to pass 0 to getpgrp; this is the POSIX behavior. On older BSD systems, you must pass 0 to getpgrp, as it takes an argument and behaves like POSIX's getpgid.

          #if GETPGRP_VOID
            pid = getpgrp ();
          #else
            pid = getpgrp (0);
          #endif
     

This macro does not check whether getpgrp exists at all; if you need to work in that situation, first call AC_CHECK_FUNC for getpgrp.

— Macro: AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK

If link is a symbolic link, then lstat should treat link/ the same as link/.. However, many older lstat implementations incorrectly ignore trailing slashes.

It is safe to assume that if lstat incorrectly ignores trailing slashes, then other symbolic-link-aware functions like unlink also incorrectly ignore trailing slashes.

If lstat behaves properly, define LSTAT_FOLLOWS_SLASHED_SYMLINK, otherwise require an AC_LIBOBJ replacement of lstat.

— Macro: AC_FUNC_MALLOC

If the malloc function is compatible with the GNU C library malloc (i.e., `malloc (0)' returns a valid pointer), define HAVE_MALLOC to 1. Otherwise define HAVE_MALLOC to 0, ask for an AC_LIBOBJ replacement for `malloc', and define malloc to rpl_malloc so that the native malloc is 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);
     }

— Macro: AC_FUNC_MEMCMP

If the memcmp function 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 an AC_LIBOBJ replacement for `memcmp'.

— Macro: AC_FUNC_MBRTOWC

Define HAVE_MBRTOWC to 1 if the function mbrtowc and the type mbstate_t are properly declared.

— Macro: AC_FUNC_MKTIME

If the mktime function is not available, or does not work correctly, require an AC_LIBOBJ replacement for `mktime'. For the purposes of this test, mktime should conform to the POSIX standard and should be the inverse of localtime.

— Macro: AC_FUNC_MMAP

If the mmap function exists and works correctly, define HAVE_MMAP. Only checks private fixed mapping of already-mapped memory.

— Macro: AC_FUNC_OBSTACK

If the obstacks are found, define HAVE_OBSTACK, else require an AC_LIBOBJ replacement for `obstack'.

— Macro: AC_FUNC_REALLOC

If the realloc function is compatible with the GNU C library realloc (i.e., `realloc (0, 0)' returns a valid pointer), define HAVE_REALLOC to 1. Otherwise define HAVE_REALLOC to 0, ask for an AC_LIBOBJ replacement for `realloc', and define realloc to rpl_realloc so that the native realloc is not used in the main project. See AC_FUNC_MALLOC for details.

— Macro: AC_FUNC_SELECT_ARGTYPES

Determines the correct type to be passed for each of the select function's arguments, and defines those types in SELECT_TYPE_ARG1, SELECT_TYPE_ARG234, and SELECT_TYPE_ARG5 respectively. SELECT_TYPE_ARG1 defaults to `int', SELECT_TYPE_ARG234 defaults to `int *', and SELECT_TYPE_ARG5 defaults to `struct timeval *'.

— Macro: AC_FUNC_SETPGRP

If setpgrp takes no argument (the POSIX version), define SETPGRP_VOID. Otherwise, it is the BSD version, which takes two process IDs as arguments. This macro does not check whether setpgrp exists at all; if you need to work in that situation, first call AC_CHECK_FUNC for setpgrp.

— Macro: AC_FUNC_STAT
— Macro: AC_FUNC_LSTAT

Determine whether stat or lstat have the bug that it succeeds when given the zero-length file name as argument. The stat and lstat from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do this.

If it does, then define HAVE_STAT_EMPTY_STRING_BUG (or HAVE_LSTAT_EMPTY_STRING_BUG) and ask for an AC_LIBOBJ replacement of it.

— Macro: AC_FUNC_SETVBUF_REVERSED

If setvbuf takes the buffering type as its second argument and the buffer pointer as the third, instead of the other way around, define SETVBUF_REVERSED.

— Macro: AC_FUNC_STRCOLL

If the strcoll function exists and works correctly, define HAVE_STRCOLL. This does a bit more than `AC_CHECK_FUNCS(strcoll)', because some systems have incorrect definitions of strcoll that should not be used.

— Macro: AC_FUNC_STRTOD

If the strtod function does not exist or doesn't work correctly, ask for an AC_LIBOBJ replacement of `strtod'. In this case, because strtod.c is likely to need `pow', set the output variable POW_LIB to the extra library needed.

— Macro: AC_FUNC_STRERROR_R

If strerror_r is available, define HAVE_STRERROR_R, and if it is declared, define HAVE_DECL_STRERROR_R. If it returns a char * message, define STRERROR_R_CHAR_P; otherwise it returns an int error number. The Thread-Safe Functions option of POSIX requires strerror_r to return int, but many systems (including, for example, version 2.2.4 of the GNU C Library) return a char * value that is not necessarily equal to the buffer argument.

— Macro: AC_FUNC_STRFTIME

Check for strftime in the intl library, for SCO unix. Then, if strftime is available, define HAVE_STRFTIME.

— Macro: AC_FUNC_STRNLEN

If the strnlen function is not available, or is buggy (like the one from AIX 4.3), require an AC_LIBOBJ replacement for it.

— Macro: AC_FUNC_UTIME_NULL

If `utime(file, NULL)' sets file's timestamp to the present, define HAVE_UTIME_NULL.

— Macro: AC_FUNC_VPRINTF

If vprintf is found, define HAVE_VPRINTF. Otherwise, if _doprnt is found, define HAVE_DOPRNT. (If vprintf is available, you may assume that vfprintf and vsprintf are also available.)

— Macro: AC_REPLACE_FNMATCH

If the fnmatch function does not conform to POSIX (see AC_FUNC_FNMATCH), ask for its AC_LIBOBJ replacement.

The files fnmatch.c, fnmatch_loop.c, and fnmatch_.h in the AC_LIBOBJ replacement directory are assumed to contain a copy of the source code of GNU fnmatch. If necessary, this source code is compiled as an AC_LIBOBJ replacement, and the fnmatch_.h file is linked to fnmatch.h so that it can be included in place of the system <fnmatch.h>.