Hash :
3925836a
Author :
Date :
2024-04-09T01:16:15
ptsname_r: Work around ptsname_r bug on NetBSD 10.0. * m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): On NetBSD, arrange to override ptsname_r. * lib/ptsname_r.c (ptsname_r): Add workaround for NetBSD bug. * doc/glibc-functions/ptsname_r.texi: Mention the NetBSD bug.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
# ptsname_r.m4
# serial 10
dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_PTSNAME_R],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
dnl Persuade glibc <stdlib.h> to declare ptsname_r().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
AC_CHECK_FUNCS_ONCE([ptsname_r])
if test $ac_cv_func_ptsname_r = no; then
HAVE_PTSNAME_R=0
else
dnl On OSF/1 5.1, the type of the third argument is 'int', not 'size_t',
dnl and the declaration is missing if _REENTRANT is not defined.
AC_CACHE_CHECK([whether ptsname_r has the same signature as in glibc],
[gl_cv_func_ptsname_r_signature_ok],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <stddef.h>
#include <stdlib.h>
/* Test whether ptsname_r is declared at all. */
int (*f) (int, char *, size_t) = ptsname_r;
/* Test whether it has the same declaration as in glibc. */
#undef ptsname_r
extern
#ifdef __cplusplus
"C"
#endif
int ptsname_r (int, char *, size_t);
]],
[[return f (0, NULL, 0);]])
],
[gl_cv_func_ptsname_r_signature_ok=yes],
[gl_cv_func_ptsname_r_signature_ok=no])
])
if test $gl_cv_func_ptsname_r_signature_ok = no; then
REPLACE_PTSNAME_R=1
else
AC_DEFINE([HAVE_ESSENTIALLY_WORKING_PTSNAME_R], [1],
[Define to 1 if ptsname_r() is essentially working.])
dnl On FreeBSD 13.0 and Android 4.3, when ptsname_r fails, it returns -1
dnl instead of the error code.
AC_REQUIRE([AC_CANONICAL_HOST])
AC_CACHE_CHECK([whether ptsname_r returns an error code],
[gl_cv_func_ptsname_r_retval_ok],
[AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdlib.h>
int
main (void)
{
char buf[80];
return ptsname_r (-1, buf, sizeof buf) == -1;
}]])],
[gl_cv_func_ptsname_r_retval_ok=yes],
[gl_cv_func_ptsname_r_retval_ok=no],
[case "$host_os" in
dnl Guess no on FreeBSD, Android.
freebsd* | dragonfly* | midnightbsd* | linux*-android*)
gl_cv_func_ptsname_r_retval_ok="guessing no" ;;
dnl Guess yes otherwise.
*)
gl_cv_func_ptsname_r_retval_ok="guessing yes" ;;
esac
])
])
case "$gl_cv_func_ptsname_r_retval_ok" in
*yes) ;;
*) REPLACE_PTSNAME_R=1 ;;
esac
dnl On NetBSD 10.0, when ptsname_r fails with ERANGE, it clobbers the
dnl result buffer. We don't use an AC_RUN_IFELSE test here, because
dnl while the bug exists on all platforms, only NetBSD/i386 has the
dnl files /dev/ptyp[01] on which the bug becomes apparent.
case "$host_os" in
netbsd*) REPLACE_PTSNAME_R=1 ;;
esac
fi
fi
AC_REQUIRE([AC_HEADER_MAJOR])
])
# Prerequisites of lib/ptsname.c.
AC_DEFUN([gl_PREREQ_PTSNAME_R], [
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether isatty sets errno when it fails],
[gl_cv_func_isatty_sets_errno],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[#include <errno.h>
#if defined _WIN32 && ! defined __CYGWIN__
# include <io.h>
#else
# include <unistd.h>
#endif
]GL_MDA_DEFINES],
[[errno = 0;
isatty (-1);
return errno == 0;
]])
],
[gl_cv_func_isatty_sets_errno=yes],
[gl_cv_func_isatty_sets_errno=no],
[case "$host_os" in
irix* | solaris*)
gl_cv_func_isatty_sets_errno="guessing no" ;;
# Guess yes on mingw, no on MSVC.
mingw* | windows*)
AC_EGREP_CPP([Known], [
#ifdef __MINGW32__
Known
#endif
],
[gl_cv_func_isatty_sets_errno="guessing yes"],
[gl_cv_func_isatty_sets_errno="guessing no"])
;;
*)
gl_cv_func_isatty_sets_errno="guessing yes" ;;
esac
])
])
case "$gl_cv_func_isatty_sets_errno" in
*yes) ;;
*)
AC_DEFINE([ISATTY_FAILS_WITHOUT_SETTING_ERRNO], [1],
[Define to 1 if isatty() may fail without setting errno.])
;;
esac
])