summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2010-03-18 16:34:11 -0600
committerEric Blake <eblake@redhat.com>2010-03-19 09:35:18 -0600
commit8e7bc4d9d435c2d18be77134896aa823733816a0 (patch)
tree8a66254c4937bfa6ecd735e36ee27d398fc00539
parent9d84afa467b0a9abcd6e0d90fc7d1608f07bf2f1 (diff)
downloadgnulib-8e7bc4d9d435c2d18be77134896aa823733816a0.tar.gz
forkpty, openpty: prefer glibc's const-safe prototype
This silences a compiler warning for test-forkpty.c. * lib/forkpty.c (rpl_forkpty): New file. * lib/openpty.c (rpl_openpty): Likewise. * modules/forkpty (Files): Distribute it. * modules/openpty (Files): Likewise. * m4/pty_h.m4 (gl_PTY_H_DEFAULTS): Add new witnesses. Move decl check... * m4/pty.m4 (gl_FORKPTY, gl_OPENPTY): ...here. Request replacement for for non-const BSD signature. * modules/pty (Makefile.am): Substitute witnesses. * lib/pty.in.h (forkpty, openpty): Declare replacements. * tests/test-forkpty.c: Update signature check. * tests/test-openpty.c: Likewise. * doc/glibc-functions/forkpty.texi (forkpty): Document the fix. * doc/glibc-functions/openpty.texi (openpty): Likewise. Reported by Bruno Haible. Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r--ChangeLog16
-rw-r--r--doc/glibc-functions/forkpty.texi4
-rw-r--r--doc/glibc-functions/openpty.texi4
-rw-r--r--lib/forkpty.c35
-rw-r--r--lib/openpty.c35
-rw-r--r--lib/pty.in.h34
-rw-r--r--m4/pty.m482
-rw-r--r--m4/pty_h.m416
-rw-r--r--modules/forkpty1
-rw-r--r--modules/openpty1
-rw-r--r--modules/pty2
-rw-r--r--tests/test-openpty.c4
12 files changed, 218 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 8c1820aa80..b42d244c70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2010-03-19 Eric Blake <eblake@redhat.com>
+ forkpty, openpty: prefer glibc's const-safe prototype
+ * lib/forkpty.c (rpl_forkpty): New file.
+ * lib/openpty.c (rpl_openpty): Likewise.
+ * modules/forkpty (Files): Distribute it.
+ * modules/openpty (Files): Likewise.
+ * m4/pty_h.m4 (gl_PTY_H_DEFAULTS): Add new witnesses. Move decl
+ check...
+ * m4/pty.m4 (gl_FORKPTY, gl_OPENPTY): ...here. Request
+ replacement for for non-const BSD signature.
+ * modules/pty (Makefile.am): Substitute witnesses.
+ * lib/pty.in.h (forkpty, openpty): Declare replacements.
+ * tests/test-forkpty.c: Update signature check.
+ * tests/test-openpty.c: Likewise.
+ * doc/glibc-functions/forkpty.texi (forkpty): Document the fix.
+ * doc/glibc-functions/openpty.texi (openpty): Likewise.
+
forkpty, openpty: split functions into new modules
* modules/pty (Makefile.am): Substitute new witnesses.
(Libraries): Move library detection...
diff --git a/doc/glibc-functions/forkpty.texi b/doc/glibc-functions/forkpty.texi
index 8a86511585..aecc2329e2 100644
--- a/doc/glibc-functions/forkpty.texi
+++ b/doc/glibc-functions/forkpty.texi
@@ -16,6 +16,10 @@ required.
The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5,
and glibc. It is declared in util.h on Mac OS X, OpenBSD and NetBSD.
It is declared in libutil.h on FreeBSD.
+@item
+Some platforms declare the function without marking the last two
+parameters @code{const}.
+FreeBSD, Cygwin 1.7.1.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/glibc-functions/openpty.texi b/doc/glibc-functions/openpty.texi
index 7eb528efd4..5eb57c353a 100644
--- a/doc/glibc-functions/openpty.texi
+++ b/doc/glibc-functions/openpty.texi
@@ -16,6 +16,10 @@ required.
The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5,
and glibc. It is declared in util.h on Mac OS X, OpenBSD and NetBSD.
It is declared in libutil.h on FreeBSD.
+@item
+Some platforms declare the function without marking the last two
+parameters @code{const}.
+FreeBSD, Cygwin 1.7.1.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/lib/forkpty.c b/lib/forkpty.c
new file mode 100644
index 0000000000..adbc3d5518
--- /dev/null
+++ b/lib/forkpty.c
@@ -0,0 +1,35 @@
+/* Fork a child attached to a pseudo-terminal descriptor.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <pty.h>
+
+#if HAVE_DECL_FORKPTY
+# undef forkpty
+int
+rpl_forkpty (int *amaster, char *name, struct termios const *termp,
+ struct winsize const *winp)
+{
+ /* Cast away const, for implementations with weaker prototypes. */
+ return forkpty (amaster, name, (struct termios *) termp,
+ (struct winsize *) winp);
+}
+#else
+# error forkpty has not been ported to your system; \
+ report this to bug-gnulib@gnu.org for help
+#endif
diff --git a/lib/openpty.c b/lib/openpty.c
new file mode 100644
index 0000000000..e7eb46d464
--- /dev/null
+++ b/lib/openpty.c
@@ -0,0 +1,35 @@
+/* Open a pseudo-terminal descriptor.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <pty.h>
+
+#if HAVE_DECL_OPENPTY
+# undef openpty
+int
+rpl_openpty (int *amaster, int *aslave, char *name, struct termios const *termp,
+ struct winsize const *winp)
+{
+ /* Cast away const, for implementations with weaker prototypes. */
+ return openpty (amaster, aslave, name, (struct termios *) termp,
+ (struct winsize *) winp);
+}
+#else
+# error openpty has not been ported to your system; \
+ report this to bug-gnulib@gnu.org for help
+#endif
diff --git a/lib/pty.in.h b/lib/pty.in.h
index 1b7bf82055..2780d6141c 100644
--- a/lib/pty.in.h
+++ b/lib/pty.in.h
@@ -45,6 +45,23 @@
/* Declare overridden functions. */
#if @GNULIB_FORKPTY@
+# if @REPLACE_FORKPTY@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef forkpty
+# define forkpty rpl_forkpty
+# endif
+_GL_FUNCDECL_RPL (forkpty, int,
+ (int *, char *, struct termios const *,
+ struct winsize const *));
+_GL_CXXALIAS_RPL (forkpty, int,
+ (int *, char *, struct termios const *,
+ struct winsize const *));
+# else
+_GL_CXXALIAS_SYS (forkpty, int,
+ (int *, char *, struct termios const *,
+ struct winsize const *));
+# endif
+_GL_CXXALIASWARN (forkpty);
#elif defined GNULIB_POSIXCHECK
# undef forkpty
# if HAVE_RAW_DECL_FORKPTY
@@ -54,6 +71,23 @@ _GL_WARN_ON_USE (forkpty, "forkpty is not declared consistently - "
#endif
#if @GNULIB_OPENPTY@
+# if @REPLACE_OPENPTY@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef openpty
+# define openpty rpl_openpty
+# endif
+_GL_FUNCDECL_RPL (openpty, int,
+ (int *, int *, char *, struct termios const *,
+ struct winsize const *));
+_GL_CXXALIAS_RPL (openpty, int,
+ (int *, int *, char *, struct termios const *,
+ struct winsize const *));
+# else
+_GL_CXXALIAS_SYS (openpty, int,
+ (int *, int *, char *, struct termios const *,
+ struct winsize const *));
+# endif
+_GL_CXXALIASWARN (openpty);
#elif defined GNULIB_POSIXCHECK
# undef openpty
# if HAVE_RAW_DECL_OPENPTY
diff --git a/m4/pty.m4 b/m4/pty.m4
index f2a5664f84..d2f8110f13 100644
--- a/m4/pty.m4
+++ b/m4/pty.m4
@@ -1,4 +1,4 @@
-# pty.m4 serial 1
+# pty.m4 serial 2
dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -23,9 +23,89 @@ AC_DEFUN([gl_PTY_LIB],
AC_DEFUN([gl_FORKPTY],
[
AC_REQUIRE([gl_PTY_LIB])
+ AC_REQUIRE([gl_PTY])
+
+ AC_CHECK_DECLS([forkpty],,, [[
+#if HAVE_PTY_H
+# include <pty.h>
+#endif
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+]])
+ if test $ac_cv_have_decl_forkpty = no; then
+ AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
+ fi
+
+ dnl Prefer glibc's const-safe prototype, if available.
+ AC_CACHE_CHECK([for const-safe forkpty signature],
+ [gl_cv_func_forkpty_const],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[
+#if HAVE_PTY_H
+# include <pty.h>
+#endif
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+ ]], [[
+ int forkpty (int *, char *, struct termios const *,
+ struct winsize const *);
+ ]])],
+ [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])])
+ if test $gl_cv_func_forkpty_const != yes; then
+ REPLACE_FORKPTY=1
+ AC_LIBOBJ([forkpty])
+ fi
])
AC_DEFUN([gl_OPENPTY],
[
AC_REQUIRE([gl_PTY_LIB])
+ AC_REQUIRE([gl_PTY])
+
+ AC_CHECK_DECLS([openpty],,, [[
+#if HAVE_PTY_H
+# include <pty.h>
+#endif
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+]])
+ if test $ac_cv_have_decl_openpty = no; then
+ AC_MSG_WARN([[Cannot find openpty, build will likely fail]])
+ fi
+
+ dnl Prefer glibc's const-safe prototype, if available.
+ AC_CACHE_CHECK([for const-safe openpty signature],
+ [gl_cv_func_openpty_const],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[
+#if HAVE_PTY_H
+# include <pty.h>
+#endif
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+ ]], [[
+ int openpty (int *, int *, char *, struct termios const *,
+ struct winsize const *);
+ ]])],
+ [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])])
+ if test $gl_cv_func_openpty_const != yes; then
+ REPLACE_OPENPTY=1
+ AC_LIBOBJ([openpty])
+ fi
])
diff --git a/m4/pty_h.m4 b/m4/pty_h.m4
index 05ac3575c4..cf41eab814 100644
--- a/m4/pty_h.m4
+++ b/m4/pty_h.m4
@@ -1,4 +1,4 @@
-# pty_h.m4 serial 3
+# pty_h.m4 serial 4
dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -22,18 +22,6 @@ AC_DEFUN_ONCE([gl_PTY],
if test $ac_cv_header_libutil_h = yes; then
HAVE_LIBUTIL_H=1
fi
- dnl FIXME - move this into forkpty module, when replacement is provided
- AC_CHECK_DECLS([forkpty],,, [[
-#if HAVE_UTIL_H
-# include <util.h>
-#endif
-#if HAVE_LIBUTIL_H
-# include <libutil.h>
-#endif
-]])
- if test $ac_cv_have_decl_forkpty = no; then
- AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
- fi
else # Have <pty.h>, assume forkpty is declared there.
HAVE_PTY_H=1
fi
@@ -70,4 +58,6 @@ AC_DEFUN([gl_PTY_H_DEFAULTS],
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_UTIL_H=0; AC_SUBST([HAVE_UTIL_H])
HAVE_LIBUTIL_H=0; AC_SUBST([HAVE_LIBUTIL_H])
+ REPLACE_FORKPTY=0; AC_SUBST([REPLACE_FORKPTY])
+ REPLACE_OPENPTY=0; AC_SUBST([REPLACE_OPENPTY])
])
diff --git a/modules/forkpty b/modules/forkpty
index 5bfe0a5dea..8fcb382196 100644
--- a/modules/forkpty
+++ b/modules/forkpty
@@ -2,6 +2,7 @@ Description:
Provide the forkpty() function.
Files:
+lib/forkpty.c
m4/pty.m4
Depends-on:
diff --git a/modules/openpty b/modules/openpty
index 68e00db4a6..1608a8da47 100644
--- a/modules/openpty
+++ b/modules/openpty
@@ -2,6 +2,7 @@ Description:
Provide the openpty() function.
Files:
+lib/openpty.c
m4/pty.m4
Depends-on:
diff --git a/modules/pty b/modules/pty
index 8ea7ed3e32..9020a1a281 100644
--- a/modules/pty
+++ b/modules/pty
@@ -29,6 +29,8 @@ pty.h: pty.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_OPENPTY''@|$(GNULIB_OPENPTY)|g' \
-e 's|@''HAVE_UTIL_H''@|$(HAVE_UTIL_H)|g' \
-e 's|@''HAVE_LIBUTIL_H''@|$(HAVE_LIBUTIL_H)|g' \
+ -e 's|@''REPLACE_FORKPTY''@|$(REPLACE_FORKPTY)|g' \
+ -e 's|@''REPLACE_OPENPTY''@|$(REPLACE_OPENPTY)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
-e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
< $(srcdir)/pty.in.h; \
diff --git a/tests/test-openpty.c b/tests/test-openpty.c
index 255aeb0ddc..2af25b49cb 100644
--- a/tests/test-openpty.c
+++ b/tests/test-openpty.c
@@ -21,8 +21,8 @@
#include <pty.h>
#include "signature.h"
-SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios *,
- struct winsize *));
+SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios const *,
+ struct winsize const *));
#include <stdio.h>