NEWS.stable: log cherry-pick [e446f25]->[c092018] relocatable-shell: Update suggested...
[gnulib.git] / lib / openpty.c
index 748d372..6330142 100644 (file)
@@ -1,5 +1,5 @@
 /* Open a pseudo-terminal.
-   Copyright (C) 2010-2011 Free Software Foundation, Inc.
+   Copyright (C) 2010-2014 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
@@ -32,9 +32,25 @@ rpl_openpty (int *amaster, int *aslave, char *name,
                   (struct winsize *) winp);
 }
 
-#else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw */
+#elif (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ /* mingw */
+
+# include <errno.h>
+
+int
+openpty (int *amaster _GL_UNUSED, int *aslave _GL_UNUSED,
+         char *name _GL_UNUSED,
+         struct termios const *termp _GL_UNUSED,
+         struct winsize const *winp _GL_UNUSED)
+{
+  /* Mingw lacks pseudo-terminals altogether.  */
+  errno = ENOSYS;
+  return -1;
+}
+
+#else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10 */
 
 # include <fcntl.h>
+# include <stdlib.h>
 # include <string.h>
 # include <sys/ioctl.h>
 # include <termios.h>
@@ -59,44 +75,11 @@ openpty (int *amaster, int *aslave, char *name,
 
 # else /* AIX 5.1, HP-UX 11, Solaris 10, mingw */
 
-#  if HAVE_POSIX_OPENPT /* Solaris 10 */
-
+  /* This call uses the 'posix_openpt' module.  */
   master = posix_openpt (O_RDWR | O_NOCTTY);
   if (master < 0)
     return -1;
 
-#  else /* AIX 5.1, HP-UX 11, Solaris 9, mingw */
-
-#   ifdef _AIX /* AIX */
-
-  master = open ("/dev/ptc", O_RDWR | O_NOCTTY);
-  if (master < 0)
-    return -1;
-
-#   else /* HP-UX 11, Solaris 9, mingw */
-
-  /* HP-UX, Solaris have /dev/ptmx.
-     HP-UX also has /dev/ptym/clone, but this should not be needed.
-     Linux also has /dev/ptmx, but Linux already has openpty().
-     MacOS X also has /dev/ptmx, but MacOS X already has openpty().
-     OSF/1 also has /dev/ptmx and /dev/ptmx_bsd, but OSF/1 already has
-     openpty().  */
-  master = open ("/dev/ptmx", O_RDWR | O_NOCTTY);
-  if (master < 0)
-    return -1;
-
-#   endif
-
-#  endif
-
-  /* If all this does not work, we could try to open, one by one:
-     - On MacOS X: /dev/pty[p-w][0-9a-f]
-     - On *BSD:    /dev/pty[p-sP-S][0-9a-v]
-     - On AIX:     /dev/ptyp[0-9a-f]
-     - On HP-UX:   /dev/pty[p-r][0-9a-f]
-     - On OSF/1:   /dev/pty[p-q][0-9a-f]
-     - On Solaris: /dev/pty[p-r][0-9a-f]
-   */
 # endif
 
   /* This call does not require a dependency to the 'grantpt' module,