Mercurial > hg > octave-nkf > gnulib-hg
changeset 13006:b89998923de3
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>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Thu, 18 Mar 2010 16:34:11 -0600 |
parents | 9bc579132d24 |
children | a7e84644e387 |
files | ChangeLog doc/glibc-functions/forkpty.texi doc/glibc-functions/openpty.texi lib/forkpty.c lib/openpty.c lib/pty.in.h m4/pty.m4 m4/pty_h.m4 modules/forkpty modules/openpty modules/pty tests/test-openpty.c |
diffstat | 12 files changed, 218 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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...
--- a/doc/glibc-functions/forkpty.texi +++ b/doc/glibc-functions/forkpty.texi @@ -16,6 +16,10 @@ 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:
--- a/doc/glibc-functions/openpty.texi +++ b/doc/glibc-functions/openpty.texi @@ -16,6 +16,10 @@ 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:
new file mode 100644 --- /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
new file mode 100644 --- /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
--- 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 @@ #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
--- 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_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 ])
--- 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 @@ 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 @@ 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]) ])
--- a/modules/forkpty +++ b/modules/forkpty @@ -2,6 +2,7 @@ Provide the forkpty() function. Files: +lib/forkpty.c m4/pty.m4 Depends-on:
--- a/modules/openpty +++ b/modules/openpty @@ -2,6 +2,7 @@ Provide the openpty() function. Files: +lib/openpty.c m4/pty.m4 Depends-on:
--- a/modules/pty +++ b/modules/pty @@ -29,6 +29,8 @@ -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; \
--- 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>