| 1 |
# readlink.m4 |
| 2 |
# serial 18 |
| 3 |
dnl Copyright (C) 2003, 2007, 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. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_READLINK], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 13 |
AC_CHECK_FUNCS_ONCE([readlink]) |
| 14 |
if test $ac_cv_func_readlink = no; then |
| 15 |
HAVE_READLINK=0 |
| 16 |
else |
| 17 |
AC_CACHE_CHECK([whether readlink signature is correct], |
| 18 |
[gl_cv_decl_readlink_works], |
| 19 |
[AC_COMPILE_IFELSE( |
| 20 |
[AC_LANG_PROGRAM( |
| 21 |
[[#include <unistd.h> |
| 22 |
/* Cause compilation failure if original declaration has |
| 23 |
wrong type. */ |
| 24 |
ssize_t readlink (const char *, char *, size_t); |
| 25 |
]]) |
| 26 |
], |
| 27 |
[gl_cv_decl_readlink_works=yes], [gl_cv_decl_readlink_works=no])]) |
| 28 |
|
| 29 |
dnl Solaris 9 ignores trailing slash. |
| 30 |
dnl FreeBSD 7.2 dereferences only one level of links with trailing slash. |
| 31 |
AC_CACHE_CHECK([whether readlink handles trailing slash correctly], |
| 32 |
[gl_cv_func_readlink_trailing_slash], |
| 33 |
[# We have readlink, so assume ln -s works. |
| 34 |
ln -s conftest.no-such conftest.link |
| 35 |
ln -s conftest.link conftest.lnk2 |
| 36 |
AC_RUN_IFELSE( |
| 37 |
[AC_LANG_PROGRAM( |
| 38 |
[[#include <unistd.h> |
| 39 |
]], |
| 40 |
[[char buf[20]; |
| 41 |
return readlink ("conftest.lnk2/", buf, sizeof buf) != -1; |
| 42 |
]]) |
| 43 |
], |
| 44 |
[gl_cv_func_readlink_trailing_slash=yes], |
| 45 |
[gl_cv_func_readlink_trailing_slash=no], |
| 46 |
[case "$host_os" in |
| 47 |
# Guess yes on Linux or glibc systems. |
| 48 |
linux-* | linux | *-gnu* | gnu*) |
| 49 |
gl_cv_func_readlink_trailing_slash="guessing yes" ;; |
| 50 |
# Guess yes on systems that emulate the Linux system calls. |
| 51 |
midipix*) |
| 52 |
gl_cv_func_readlink_trailing_slash="guessing yes" ;; |
| 53 |
# Guess no on AIX or HP-UX. |
| 54 |
aix* | hpux*) |
| 55 |
gl_cv_func_readlink_trailing_slash="guessing no" ;; |
| 56 |
# If we don't know, obey --enable-cross-guesses. |
| 57 |
*) |
| 58 |
gl_cv_func_readlink_trailing_slash="$gl_cross_guess_normal" ;; |
| 59 |
esac |
| 60 |
]) |
| 61 |
rm -f conftest.link conftest.lnk2]) |
| 62 |
case "$gl_cv_func_readlink_trailing_slash" in |
| 63 |
*yes) |
| 64 |
if test "$gl_cv_decl_readlink_works" != yes; then |
| 65 |
REPLACE_READLINK=1 |
| 66 |
fi |
| 67 |
;; |
| 68 |
*) |
| 69 |
AC_DEFINE([READLINK_TRAILING_SLASH_BUG], [1], [Define to 1 if readlink |
| 70 |
fails to recognize a trailing slash.]) |
| 71 |
REPLACE_READLINK=1 |
| 72 |
;; |
| 73 |
esac |
| 74 |
|
| 75 |
AC_CACHE_CHECK([whether readlink truncates results correctly], |
| 76 |
[gl_cv_func_readlink_truncate], |
| 77 |
[# We have readlink, so assume ln -s works. |
| 78 |
ln -s ab conftest.link |
| 79 |
AC_RUN_IFELSE( |
| 80 |
[AC_LANG_PROGRAM( |
| 81 |
[[#include <unistd.h> |
| 82 |
]], |
| 83 |
[[char c; |
| 84 |
return readlink ("conftest.link", &c, 1) != 1; |
| 85 |
]]) |
| 86 |
], |
| 87 |
[gl_cv_func_readlink_truncate=yes], |
| 88 |
[gl_cv_func_readlink_truncate=no], |
| 89 |
[case "$host_os" in |
| 90 |
# Guess yes on Linux or glibc systems. |
| 91 |
linux-* | linux | *-gnu* | gnu*) |
| 92 |
gl_cv_func_readlink_truncate="guessing yes" ;; |
| 93 |
# Guess yes on systems that emulate the Linux system calls. |
| 94 |
midipix*) |
| 95 |
gl_cv_func_readlink_truncate="guessing yes" ;; |
| 96 |
# Guess no on AIX or HP-UX. |
| 97 |
aix* | hpux*) |
| 98 |
gl_cv_func_readlink_truncate="guessing no" ;; |
| 99 |
# If we don't know, obey --enable-cross-guesses. |
| 100 |
*) |
| 101 |
gl_cv_func_readlink_truncate="$gl_cross_guess_normal" ;; |
| 102 |
esac |
| 103 |
]) |
| 104 |
rm -f conftest.link conftest.lnk2]) |
| 105 |
case $gl_cv_func_readlink_truncate in |
| 106 |
*yes) |
| 107 |
if test "$gl_cv_decl_readlink_works" != yes; then |
| 108 |
REPLACE_READLINK=1 |
| 109 |
fi |
| 110 |
;; |
| 111 |
*) |
| 112 |
AC_DEFINE([READLINK_TRUNCATE_BUG], [1], [Define to 1 if readlink |
| 113 |
sets errno instead of truncating a too-long link.]) |
| 114 |
REPLACE_READLINK=1 |
| 115 |
;; |
| 116 |
esac |
| 117 |
|
| 118 |
dnl On Cygwin 3.3.6, readlink("/dev/null") returns "\\Device\\Null", which |
| 119 |
dnl is unusable. |
| 120 |
case "$host_os" in |
| 121 |
cygwin*) |
| 122 |
REPLACE_READLINK=1 |
| 123 |
;; |
| 124 |
esac |
| 125 |
fi |
| 126 |
]) |
| 127 |
|
| 128 |
# Like gl_FUNC_READLINK, except prepare for separate compilation |
| 129 |
# (no REPLACE_READLINK, no AC_LIBOBJ). |
| 130 |
AC_DEFUN([gl_FUNC_READLINK_SEPARATE], |
| 131 |
[ |
| 132 |
AC_CHECK_FUNCS_ONCE([readlink]) |
| 133 |
gl_PREREQ_READLINK |
| 134 |
]) |
| 135 |
|
| 136 |
# Prerequisites of lib/readlink.c. |
| 137 |
AC_DEFUN([gl_PREREQ_READLINK], |
| 138 |
[ |
| 139 |
: |
| 140 |
]) |