ptsname_r: Avoid compilation error on OSF/1 5.1.
authorBruno Haible <bruno@clisp.org>
Thu, 10 Nov 2011 12:48:16 +0000 (13:48 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 10 Nov 2011 12:48:16 +0000 (13:48 +0100)
* lib/stdlib.in.h (ptsname_r): Override if REPLACE_PTSNAME_R is 1.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_PTSNAME_R.
* m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): Set REPLACE_PTSNAME_R if the
function is not declared or incompatibly declared.
* modules/stdlib (Makefile.am): Substitute REPLACE_PTSNAME_R.
* modules/ptsname_r (Depends-on, configure.ac): Update.
* doc/glibc-functions/ptsname_r.texi: Mention the OSF/1 problems.

ChangeLog
doc/glibc-functions/ptsname_r.texi
lib/stdlib.in.h
m4/ptsname_r.m4
m4/stdlib_h.m4
modules/ptsname_r
modules/stdlib

index c7fe84d..5ac22c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-11-10  Bruno Haible  <bruno@clisp.org>
 
+       ptsname_r: Avoid compilation error on OSF/1 5.1.
+       * lib/stdlib.in.h (ptsname_r): Override if REPLACE_PTSNAME_R is 1.
+       * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_PTSNAME_R.
+       * m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): Set REPLACE_PTSNAME_R if the
+       function is not declared or incompatibly declared.
+       * modules/stdlib (Makefile.am): Substitute REPLACE_PTSNAME_R.
+       * modules/ptsname_r (Depends-on, configure.ac): Update.
+       * doc/glibc-functions/ptsname_r.texi: Mention the OSF/1 problems.
+
+2011-11-10  Bruno Haible  <bruno@clisp.org>
+
        fstatat: Make cross-compilation guess succeed everywhere except on AIX.
        * m4/fstatat.m4 (gl_FUNC_FSTATAT): Require AC_CANONICAL_HOST.
        When cross-compiling, guess yes on all platforms except AIX.
index 986e491..e51e523 100644 (file)
@@ -11,6 +11,13 @@ This function is missing on some platforms:
 MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
 AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11 2010-11, Cygwin 1.7.9, mingw,
 MSVC 9, BeOS.
+@item
+This function is not declared unless @code{_REENTRANT} is defined,
+on some platforms:
+OSF/1 5.1.
+@item
+This function has an incompatible declaration on some platforms:
+OSF/1 5.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 009b180..a59cb08 100644 (file)
@@ -459,10 +459,19 @@ _GL_WARN_ON_USE (ptsname, "ptsname is not portable - "
 /* Set the pathname of the pseudo-terminal slave associated with
    the master FD is open on and return 0, or set errno and return
    non-zero on errors.  */
-# if !@HAVE_PTSNAME_R@
+# if @REPLACE_PTSNAME_R@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef ptsname_r
+#   define ptsname_r rpl_ptsname_r
+#  endif
+_GL_FUNCDECL_RPL (ptsname_r, int, (int fd, char *buf, size_t len));
+_GL_CXXALIAS_RPL (ptsname_r, int, (int fd, char *buf, size_t len));
+# else
+#  if !@HAVE_PTSNAME_R@
 _GL_FUNCDECL_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
+# endif
 _GL_CXXALIASWARN (ptsname_r);
 #elif defined GNULIB_POSIXCHECK
 # undef ptsname_r
index fb07099..695fe79 100644 (file)
@@ -1,4 +1,4 @@
-# ptsname_r.m4 serial 1
+# ptsname_r.m4 serial 2
 dnl Copyright (C) 2010-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -14,6 +14,33 @@ AC_DEFUN([gl_FUNC_PTSNAME_R],
   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
+    fi
   fi
 ])
 
index ebf7fb5..0a8a9e5 100644 (file)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 38
+# stdlib_h.m4 serial 39
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -99,6 +99,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   REPLACE_MALLOC=0;          AC_SUBST([REPLACE_MALLOC])
   REPLACE_MBTOWC=0;          AC_SUBST([REPLACE_MBTOWC])
   REPLACE_MKSTEMP=0;         AC_SUBST([REPLACE_MKSTEMP])
+  REPLACE_PTSNAME_R=0;       AC_SUBST([REPLACE_PTSNAME_R])
   REPLACE_PUTENV=0;          AC_SUBST([REPLACE_PUTENV])
   REPLACE_REALLOC=0;         AC_SUBST([REPLACE_REALLOC])
   REPLACE_REALPATH=0;        AC_SUBST([REPLACE_REALPATH])
index daf1d98..7520847 100644 (file)
@@ -8,11 +8,11 @@ m4/ptsname_r.m4
 Depends-on:
 stdlib
 extensions
-ttyname_r       [test $HAVE_PTSNAME_R = 0]
+ttyname_r       [test $HAVE_PTSNAME_R = 0 || test $REPLACE_PTSNAME_R = 1]
 
 configure.ac:
 gl_FUNC_PTSNAME_R
-if test $HAVE_PTSNAME_R = 0; then
+if test $HAVE_PTSNAME_R = 0 || test $REPLACE_PTSNAME_R = 1; then
   AC_LIBOBJ([ptsname_r])
   gl_PREREQ_PTSNAME_R
 fi
index d46f664..2beee3d 100644 (file)
@@ -93,6 +93,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
              -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
              -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
              -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
+             -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
              -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
              -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
              -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \