openpty and forkpty don't exist on Solaris and other OSes. The first, simplest function gnulib can provide in this area is 'ttyname_r'. I'm adding it:
2010-03-21 Bruno Haible <br...@clisp.org> New module 'ttyname_r'. * lib/ttyname_r.c: New file. * m4/ttyname_r.m4: New file. * modules/ttyname_r: New file. * lib/unistd.in.h (ttyname_r): New declaration. * m4/unistd_h.m4 (gl_UNISTD_H): Check whether ttyname_r is declared. (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_TTYNAME_R, HAVE_TTYNAME_R. * modules/unistd (Makefile.am): Substitute GNULIB_TTYNAME_R, HAVE_TTYNAME_R. * tests/test-unistd-c++.cc: Check GNULIB_NAMESPACE::ttyname_r. * doc/posix-functions/ttyname_r.texi: Mention the new module. =============================== lib/ttyname_r.c =============================== /* Determine name of a terminal. 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/>. */ /* Written by Bruno Haible <br...@clisp.org>, 2010. */ #include <config.h> #include <unistd.h> #include <errno.h> #include <string.h> int ttyname_r (int fd, char *buf, size_t buflen) { #if HAVE_TTYNAME /* Note: This is not multithread-safe. */ char *name; size_t namelen; name = ttyname (fd); if (name == NULL) return errno; namelen = strlen (name) + 1; if (namelen > buflen) return ERANGE; memcpy (buf, name, namelen); return 0; #else /* Platforms like mingw: no ttys exist at all. */ return ENOTTY; #endif } =============================== m4/ttyname_r.m4 =============================== # ttyname_r.m4 serial 1 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, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_TTYNAME_R], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_CHECK_FUNCS([ttyname_r]) if test $ac_cv_func_ttyname_r = no; then HAVE_TTYNAME_R=0 AC_LIBOBJ([ttyname_r]) gl_PREREQ_TTYNAME_R fi ]) # Prerequisites of lib/ttyname_r.c. AC_DEFUN([gl_PREREQ_TTYNAME_R], [ AC_CHECK_FUNCS([ttyname]) ]) ============================== modules/ttyname_r ============================== Description: ttyname_r() function: Determine name of a terminal. Files: lib/ttyname_r.c m4/ttyname_r.m4 Depends-on: unistd configure.ac: gl_FUNC_TTYNAME_R gl_UNISTD_MODULE_INDICATOR([ttyname_r]) Makefile.am: Include: <unistd.h> License: LGPL Maintainer: Bruno Haible =============================================================================== --- lib/unistd.in.h.orig Sun Mar 21 14:32:23 2010 +++ lib/unistd.in.h Sun Mar 21 13:59:05 2010 @@ -1099,6 +1099,25 @@ #endif +#if @GNULIB_TTYNAME_R@ +/* Store at most BUFLEN characters of the pathname of the terminal FD is + open on in BUF. Return 0 on success, otherwise an error number. */ +# if !...@have_ttyname_r@ +_GL_FUNCDECL_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen)); +_GL_CXXALIASWARN (ttyname_r); +#elif defined GNULIB_POSIXCHECK +# undef ttyname_r +# if HAVE_RAW_DECL_TTYNAME_R +_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - " + "use gnulib module ttyname_r for portability"); +# endif +#endif + + #if @GNULIB_UNLINK@ # if @REPLACE_UNLINK@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) --- m4/unistd_h.m4.orig Sun Mar 21 14:32:23 2010 +++ m4/unistd_h.m4 Sun Mar 21 14:20:19 2010 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 41 +# unistd_h.m4 serial 42 dnl Copyright (C) 2006-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, @@ -39,7 +39,7 @@ fsync ftruncate getcwd getdomainname getdtablesize getgroups gethostname getlogin getlogin_r getpagesize getusershell setusershell endusershell lchown link linkat lseek pipe2 pread readlink readlinkat - rmdir sleep symlink symlinkat unlink unlinkat usleep]) + rmdir sleep symlink symlinkat ttyname_r unlink unlinkat usleep]) ]) AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], @@ -85,6 +85,7 @@ GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP]) GNULIB_SYMLINK=0; AC_SUBST([GNULIB_SYMLINK]) GNULIB_SYMLINKAT=0; AC_SUBST([GNULIB_SYMLINKAT]) + GNULIB_TTYNAME_R=0; AC_SUBST([GNULIB_TTYNAME_R]) GNULIB_UNISTD_H_GETOPT=0; AC_SUBST([GNULIB_UNISTD_H_GETOPT]) GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE]) GNULIB_UNLINK=0; AC_SUBST([GNULIB_UNLINK]) @@ -116,13 +117,14 @@ HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK]) HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT]) + HAVE_TTYNAME_R=1; AC_SUBST([HAVE_TTYNAME_R]) + HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) + HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL]) HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) - HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) - HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) REPLACE_DUP=0; AC_SUBST([REPLACE_DUP]) --- modules/unistd.orig Sun Mar 21 14:32:23 2010 +++ modules/unistd Sun Mar 21 14:25:33 2010 @@ -59,6 +59,7 @@ -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \ -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \ -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \ + -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \ -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \ -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \ -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \ @@ -90,6 +91,7 @@ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \ -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \ + -e 's|@''HAVE_TTYNAME_R''@|$(HAVE_TTYNAME_R)|g' \ -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ --- tests/test-unistd-c++.cc.orig Sun Mar 21 14:32:23 2010 +++ tests/test-unistd-c++.cc Sun Mar 21 14:00:25 2010 @@ -165,6 +165,11 @@ (char const *, int, char const *)); #endif +#if GNULIB_TTYNAME_R +SIGNATURE_CHECK (GNULIB_NAMESPACE::ttyname_r, int, + (int fd, char *buf, size_t buflen)); +#endif + #if GNULIB_UNLINK SIGNATURE_CHECK (GNULIB_NAMESPACE::unlink, int, (char const *)); #endif --- doc/posix-functions/ttyname_r.texi.orig Sun Mar 21 14:32:23 2010 +++ doc/posix-functions/ttyname_r.texi Sun Mar 21 14:32:16 2010 @@ -4,15 +4,14 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ttyname_r.html} -Gnulib module: --- +Gnulib module: ttyname_r Portability problems fixed by Gnulib: @itemize +This function is missing on some platforms: +NetBSD 3.0, mingw, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -...@item -This function is missing on some platforms: -NetBSD 3.0, mingw, BeOS. @end itemize