strerror: Move AC_LIBOBJ invocations to module description.
[gnulib.git] / m4 / strerror.m4
1 # strerror.m4 serial 12
2 dnl Copyright (C) 2002, 2007-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_STRERROR],
8 [
9   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
10   AC_REQUIRE([gl_HEADER_ERRNO_H])
11   if test -z "$ERRNO_H"; then
12     AC_CACHE_CHECK([for working strerror function],
13      [gl_cv_func_working_strerror],
14      [AC_RUN_IFELSE(
15         [AC_LANG_PROGRAM(
16            [[#include <string.h>
17              #include <errno.h>
18            ]],
19            [[int result = 0;
20              if (!*strerror (-2)) result |= 1;
21              errno = 0;
22              if (!*strerror (0)) result |= 2;
23              if (errno) result |= 4;
24              return result;]])],
25         [gl_cv_func_working_strerror=yes],
26         [gl_cv_func_working_strerror=no],
27         [dnl Be pessimistic on cross-compiles for now.
28          gl_cv_func_working_strerror=no])
29     ])
30     if test $gl_cv_func_working_strerror = no; then
31       dnl The system's strerror() fails to return a string for out-of-range
32       dnl integers. Replace it.
33       REPLACE_STRERROR=1
34     fi
35   else
36     dnl The system's strerror() cannot know about the new errno values we add
37     dnl to <errno.h>. Replace it.
38     REPLACE_STRERROR=1
39   fi
40 ])
41
42 # Prerequisites of lib/strerror.c.
43 AC_DEFUN([gl_PREREQ_STRERROR], [
44   AC_CHECK_DECLS([strerror])
45   AC_CHECK_HEADERS_ONCE([sys/socket.h])
46   if test $ac_cv_header_sys_socket_h != yes; then
47     dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
48     dnl the check for those headers unconditional; yet cygwin reports
49     dnl that the headers are present but cannot be compiled (since on
50     dnl cygwin, all socket information should come from sys/socket.h).
51     AC_CHECK_HEADERS([winsock2.h])
52   fi
53 ])