+2010-03-21 Bruno Haible <bruno@clisp.org>
+
+ New module 'ptsname'.
+ * lib/ptsname.c: New file, from glibc with modifications.
+ * m4/ptsname.m4: New file.
+ * modules/ptsname: New file.
+ * lib/stdlib.in.h (ptsname): New declaration.
+ * m4/stdlib_h.m4 (gl_STDLIB_H): Check whether ptsname is declared.
+ (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_PTSNAME, HAVE_PTSNAME.
+ * modules/stdlib (Makefile.am): Substitute GNULIB_PTSNAME,
+ HAVE_PTSNAME.
+ * doc/posix-functions/ptsname.texi: Mention the new module.
+ * tests/test-stdlib-c++.cc: Check GNULIB_NAMESPACE::ptsname.
+ * config/srclist.txt: Add ptsname.c (commented).
+
2010-03-21 Bruno Haible <bruno@clisp.org>
Tests for module 'ttyname_r'.
#$LIBCSRC/sysdeps/posix/euidaccess.c lib gpl
#$LIBCSRC/sysdeps/posix/tempname.c lib gpl
#$LIBCSRC/sysdeps/unix/bsd/poll.c lib gpl
+#$LIBCSRC/sysdeps/unix/bsd/ptsname.c lib gpl
#$LIBCSRC/sysdeps/unix/dirfd.c lib gpl
#$LIBCSRC/sysdeps/unix/rmdir.c lib gpl
#$LIBCSRC/time/strftime.c lib gpl
POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ptsname.html}
-Gnulib module: ---
+Gnulib module: ptsname
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+MacOS X 10.3, OpenBSD 3.8, mingw, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-MacOS X 10.3, OpenBSD 3.8, mingw, BeOS.
@end itemize
--- /dev/null
+/* Determine name of the slave side of a pseudo-terminal.
+ Copyright (C) 1998, 2002, 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>
+
+#include <stdlib.h>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifdef _LIBC
+# include <paths.h>
+#else
+# ifndef _PATH_TTY
+# define _PATH_TTY "/dev/tty"
+# endif
+# ifndef _PATH_DEV
+# define _PATH_DEV "/dev/"
+# endif
+
+# define __set_errno(e) errno = (e)
+# define __isatty isatty
+# define __stat stat
+# define __ttyname_r ttyname_r
+
+static int __ptsname_r (int fd, char *buf, size_t buflen);
+#endif
+
+
+/* Static buffer for `ptsname'. */
+static char buffer[sizeof (_PATH_TTY) + 2];
+
+
+/* Return the pathname of the pseudo terminal slave associated with
+ the master FD is open on, or NULL on errors.
+ The returned storage is good until the next call to this function. */
+char *
+ptsname (int fd)
+{
+ return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
+}
+
+
+/* Store at most BUFLEN characters of the pathname of the slave pseudo
+ terminal associated with the master FD is open on in BUF.
+ Return 0 on success, otherwise an error number. */
+static int
+__ptsname_r (int fd, char *buf, size_t buflen)
+{
+ int save_errno = errno;
+ struct stat st;
+
+ if (buf == NULL)
+ {
+ __set_errno (EINVAL);
+ return EINVAL;
+ }
+
+ if (!__isatty (fd))
+ /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */
+ return errno;
+
+ if (buflen < strlen (_PATH_TTY) + 3)
+ {
+ __set_errno (ERANGE);
+ return ERANGE;
+ }
+
+ if (__ttyname_r (fd, buf, buflen) != 0)
+ return errno;
+
+ buf[sizeof (_PATH_DEV) - 1] = 't';
+
+ if (__stat (buf, &st) < 0)
+ return errno;
+
+ __set_errno (save_errno);
+ return 0;
+}
# endif
#endif
+#if @GNULIB_PTSNAME@
+/* Return the pathname of the pseudo-terminal slave associated with
+ the master FD is open on, or NULL on errors. */
+# if !@HAVE_PTSNAME@
+_GL_FUNCDECL_SYS (ptsname, char *, (int fd));
+# endif
+_GL_CXXALIAS_SYS (ptsname, char *, (int fd));
+_GL_CXXALIASWARN (ptsname);
+#elif defined GNULIB_POSIXCHECK
+# undef ptsname
+# if HAVE_RAW_DECL_PTSNAME
+_GL_WARN_ON_USE (ptsname, "ptsname is not portable - "
+ "use gnulib module ptsname for portability");
+# endif
+#endif
+
#if @GNULIB_PUTENV@
# if @REPLACE_PUTENV@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
--- /dev/null
+# ptsname.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_PTSNAME],
+[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+
+ dnl Persuade glibc <stdlib.h> to declare ptsname().
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_FUNCS([ptsname])
+ if test $ac_cv_func_ptsname = no; then
+ HAVE_PTSNAME=0
+ AC_LIBOBJ([ptsname])
+ gl_PREREQ_PTSNAME
+ fi
+])
+
+# Prerequisites of lib/ptsname.c.
+AC_DEFUN([gl_PREREQ_PTSNAME], [
+ :
+])
-# stdlib_h.m4 serial 23
+# stdlib_h.m4 serial 24
dnl Copyright (C) 2007-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,
# include <random.h>
#endif
]], [atoll canonicalize_file_name getloadavg getsubopt mkdtemp
- mkostemp mkostemps mkstemp mkstemps random_r initstat_r srandom_r
+ mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
setstate_r realpath rpmatch setenv strtod strtoll strtoull unsetenv])
])
GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS])
GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS])
+ GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME])
GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R])
GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
+ HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
--- /dev/null
+Description:
+ptsname() function: Determine name of the slave side of a pseudo-terminal.
+
+Files:
+lib/ptsname.c
+m4/ptsname.m4
+
+Depends-on:
+stdlib
+extensions
+ttyname_r
+
+configure.ac:
+gl_FUNC_PTSNAME
+gl_STDLIB_MODULE_INDICATOR([ptsname])
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
-e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
-e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
-e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \
+ -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \
-e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
-e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
-e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
-e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
-e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
-e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
+ -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
-e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
-e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
-e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
SIGNATURE_CHECK (GNULIB_NAMESPACE::mkstemps, int, (char *, int));
#endif
+#if GNULIB_PTSNAME
+SIGNATURE_CHECK (GNULIB_NAMESPACE::ptsname, char *, (int));
+#endif
+
#if GNULIB_PUTENV
SIGNATURE_CHECK (GNULIB_NAMESPACE::putenv, int, (char *));
#endif