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>
This commit is contained in:
Eric Blake
2010-03-19 09:35:18 -06:00
parent 9d84afa467
commit 8e7bc4d9d4
12 changed files with 218 additions and 16 deletions
+16
View File
@@ -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...
+4
View File
@@ -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:
+4
View File
@@ -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:
+35
View File
@@ -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
+35
View File
@@ -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
+34
View File
@@ -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
+81 -1
View File
@@ -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
])
+3 -13
View File
@@ -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])
])
+1
View File
@@ -2,6 +2,7 @@ Description:
Provide the forkpty() function.
Files:
lib/forkpty.c
m4/pty.m4
Depends-on:
+1
View File
@@ -2,6 +2,7 @@ Description:
Provide the openpty() function.
Files:
lib/openpty.c
m4/pty.m4
Depends-on:
+2
View File
@@ -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; \
+2 -2
View File
@@ -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>