1# serial 6
2# See if we need to provide readlinkat replacement.
3
4dnl Copyright (C) 2009-2021 Free Software Foundation, Inc.
5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved.
8
9# Written by Eric Blake.
10
11AC_DEFUN([gl_FUNC_READLINKAT],
12[
13  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
14  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15  AC_CHECK_FUNCS_ONCE([readlinkat])
16  AC_REQUIRE([gl_FUNC_READLINK])
17  if test $ac_cv_func_readlinkat = no; then
18    HAVE_READLINKAT=0
19  else
20    AC_CACHE_CHECK([whether readlinkat signature is correct],
21      [gl_cv_decl_readlinkat_works],
22      [AC_COMPILE_IFELSE(
23         [AC_LANG_PROGRAM(
24           [[#include <unistd.h>
25             /* Check whether original declaration has correct type.  */
26             ssize_t readlinkat (int, char const *, char *, size_t);]])],
27         [gl_cv_decl_readlinkat_works=yes],
28         [gl_cv_decl_readlinkat_works=no])])
29    # Assume readlinkat has the same bugs as readlink,
30    # as is the case on OS X 10.10 with trailing slashes.
31    case $gl_cv_decl_readlinkat_works,$gl_cv_func_readlink_trailing_slash,$gl_cv_func_readlink_truncate in
32      *yes,*yes,*yes)
33        ;;
34      *)
35        REPLACE_READLINKAT=1
36        ;;
37    esac
38  fi
39])
40