bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libvirt] [PATCHv2] build: fix build on platforms without ptsname_r


From: Eric Blake
Subject: Re: [libvirt] [PATCHv2] build: fix build on platforms without ptsname_r
Date: Wed, 09 Nov 2011 12:10:46 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.4 Thunderbird/3.1.15

[moving to bug-gnulib; this started on libvir-list]

On 11/08/2011 02:29 AM, Daniel P. Berrange wrote:
Unfortunately it does not build on Mingw:

make[4]: Entering directory `/home/berrange/src/virt/libvirt/gnulib/lib'
   CC     glthread/lock.lo
   CC     openpty.lo
openpty.c:51:46: warning: 'struct winsize' declared inside parameter list
openpty.c:51:46: warning: 'struct termios' declared inside parameter list
openpty.c:50:1: error: conflicting types for 'openpty'
./pty.h:412:1: note: previous declaration of 'openpty' was here
openpty.c: In function 'openpty':
openpty.c:74:3: warning: implicit declaration of function 'grantpt'
openpty.c:79:3: warning: implicit declaration of function 'unlockpt'
openpty.c:83:3: warning: implicit declaration of function 'ptsname'
openpty.c:83:14: warning: assignment makes pointer from integer without a cast
openpty.c:107:5: warning: implicit declaration of function 'tcsetattr'
openpty.c:107:23: error: 'TCSAFLUSH' undeclared (first use in this function)
openpty.c:107:23: note: each undeclared identifier is reported only once for 
each function it appears in
openpty.c:109:19: error: 'TIOCSWINSZ' undeclared (first use in this function)
make[4]: *** [openpty.lo] Error 1


GNULIB does not even claim to support openpty on Mingw

But we can at least let things compile and fail at runtime with ENOSYS, instead of flat out making the module unusable.

I'm pushing this:

From 822c53fb8aac23cad1ee4918a85e3843f0621eaa Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 9 Nov 2011 11:47:22 -0700
Subject: [PATCH] openpty: provide a stub on mingw

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 <address@hidden>
---
 ChangeLog     |    4 ++++
 lib/openpty.c |   17 ++++++++++++++++-
 lib/pty.in.h  |    5 +++++
 3 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8b5a1ad..f51cc25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-11-09  Eric Blake  <address@hidden>

+       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.

diff --git a/lib/openpty.c b/lib/openpty.c
index c398db5..d9d9773 100644
--- a/lib/openpty.c
+++ b/lib/openpty.c
@@ -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>
diff --git a/lib/pty.in.h b/lib/pty.in.h
index aff989c..b24dd10 100644
--- a/lib/pty.in.h
+++ b/lib/pty.in.h
@@ -45,6 +45,11 @@
 #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.  */

--
1.7.4.4


--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]