realloc: more improvements for realloc (p, 0)
[gnulib.git] / m4 / readlinkat.m4
blob81e389a111702ac42d1e7a6edb5552067e320d2b
1 # readlinkat.m4
2 # serial 10
3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
9 # See if we need to provide readlinkat replacement.
11 # Written by Eric Blake.
13 AC_DEFUN([gl_FUNC_READLINKAT],
15   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
16   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   gl_CHECK_FUNCS_ANDROID([readlinkat], [[#include <unistd.h>]])
18   AC_REQUIRE([gl_FUNC_READLINK])
19   if test $ac_cv_func_readlinkat = no; then
20     HAVE_READLINKAT=0
21     case "$gl_cv_onwards_func_readlinkat" in
22       future*) REPLACE_READLINKAT=1 ;;
23     esac
24   else
25     AC_CACHE_CHECK([whether readlinkat signature is correct],
26       [gl_cv_decl_readlinkat_works],
27       [AC_COMPILE_IFELSE(
28          [AC_LANG_PROGRAM(
29            [[#include <unistd.h>
30              /* Check whether original declaration has correct type.  */
31              ssize_t readlinkat (int, char const *, char *, size_t);
32            ]])
33          ],
34          [gl_cv_decl_readlinkat_works=yes],
35          [gl_cv_decl_readlinkat_works=no])
36       ])
37     # Assume readlinkat has the same bugs as readlink,
38     # as is the case on macOS 14 with trailing slashes.
39     case $gl_cv_decl_readlinkat_works,$gl_cv_func_readlink_trailing_slash,$gl_cv_func_readlink_truncate in
40       *yes,*yes,*yes)
41         ;;
42       *)
43         REPLACE_READLINKAT=1
44         ;;
45     esac
47     dnl On Cygwin 3.3.6, readlinkat(AT_FDCWD,"/dev/null") returns
48     dnl "\\Device\\Null", which is unusable.
49     case "$host_os" in
50       cygwin*)
51         REPLACE_READLINKAT=1
52         ;;
53     esac
54   fi