openpty: provide a stub on mingw
authorEric Blake <eblake@redhat.com>
Wed, 9 Nov 2011 18:47:22 +0000 (11:47 -0700)
committerEric Blake <eblake@redhat.com>
Wed, 9 Nov 2011 18:47:22 +0000 (11:47 -0700)
On mingw, the compiler complained that 'struct termios' and
'struct winsize' were declared in the function prototype, then
failed to compile due to missing TCSAFLUSH.  Since we can't
emulate ptys on mingw, it's better to just make this module
be a stub that compiles but gracefully fails.

This patch assumes that the only portable way to use openpty()
is with the fourth and fifth arguments being NULL ('struct termios'
cannot be portably initialized in a standard-compliant manner
except by open(O_TTY_INIT)/tcgetattr(), and 'struct winsize' is
not standardized); for now, applications that want to alter termios
settings still have the burden of conditional compilation to avoid
the missing tcgetattr() on mingw.

* lib/pty.in.h (includes): Provide forward declarations.
* lib/openpty.c (openpty) [mingw]: Provide ENOSYS stub.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
lib/openpty.c
lib/pty.in.h

index 8b5a1ad..f51cc25 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-11-09  Eric Blake  <eblake@redhat.com>
 
+       openpty: provide a stub on mingw
+       * lib/pty.in.h (includes): Provide forward declarations.
+       * lib/openpty.c (openpty) [mingw]: Provide ENOSYS stub.
+
        raise: fix mingw handling of SIGPIPE
        * lib/sigprocmask.c (_gl_raise_SIGPIPE): Provide a return value.
 
index c398db5..d9d9773 100644 (file)
@@ -32,7 +32,22 @@ 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>
index aff989c..b24dd10 100644 (file)
 #if defined _AIX
 # include <sys/ioctl.h>
 #endif
+/* Mingw lacks 'struct termios' and 'struct winsize', but a forward
+   declaration of an opaque type is sufficient to allow compilation of
+   a stub openpty().  */
+struct termios;
+struct winsize;
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */