summaryrefslogtreecommitdiff
path: root/lib/posix_openpt.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-10-17 17:19:41 -0600
committerEric Blake <eblake@redhat.com>2011-10-18 15:15:44 -0600
commit94d63c4bfd95e7ff11c3dcbc1d60d276739f7f55 (patch)
tree28aa8c76eef4600791cc11075409784b29aa22b3 /lib/posix_openpt.c
parent0a19a162755da4ef297bcacd62cf5243c76324ed (diff)
downloadgnulib-94d63c4bfd95e7ff11c3dcbc1d60d276739f7f55.tar.gz
posix_openpt: new module
* modules/posix_openpt: New module. * m4/posix_openpt.m4: New file. * lib/posix_openpt.c: Likewise. * m4/stdlib_h.m4 (gl_STDLIB_H): Check for decl. (gl_STDLIB_H_DEFAULTS): Set defaults. * modules/stdlib (Makefile.am): Substitute macros. * lib/stdlib.in.h (posix_openpt): Declare. * MODULES.html.sh (systems lacking POSIX:2008): Document it. * doc/posix-functions/posix_openpt.texi (posix_openpt): Likewise. * modules/posix_openpt-tests: New test module. * tests/test-posix_openpt.c: New test.
Diffstat (limited to 'lib/posix_openpt.c')
-rw-r--r--lib/posix_openpt.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/posix_openpt.c b/lib/posix_openpt.c
new file mode 100644
index 0000000000..b2e4999c29
--- /dev/null
+++ b/lib/posix_openpt.c
@@ -0,0 +1,50 @@
+/* Open the master side of a pseudo-terminal.
+ Copyright (C) 2010-2011 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 <stdlib.h>
+
+#include <fcntl.h>
+#include <errno.h>
+
+int
+posix_openpty (int flags)
+{
+ int master;
+
+#ifdef _AIX /* AIX */
+
+ master = open ("/dev/ptc", flags);
+
+#elif (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ /* mingw */
+
+ /* Mingw lacks pseudo-terminals altogether. */
+ master = -1;
+ errno = ENOSYS;
+
+#else /* MacOS, OpenBSD, HP-UX, IRIX, Solaris 9, Cygwin 1.5 */
+
+ /* Most systems that lack posix_openpt() have /dev/ptmx. */
+ master = open ("/dev/ptmx", flags);
+
+#endif
+
+ return master;
+}
+
+#endif