diff mbox series

[v3,2/9] util/qemu-openpty.c: Don't assume pty.h is glibc-only

Message ID 20200703145614.16684-3-peter.maydell@linaro.org (mailing list archive)
State New, archived
Headers show
Series Build fixes for Haiku | expand

Commit Message

Peter Maydell July 3, 2020, 2:56 p.m. UTC
From: David CARLIER <devnexen@gmail.com>

Instead of using an OS-specific ifdef test to select the "openpty()
is in pty.h" codepath, make configure check for the existence of
the header and use the new CONFIG_PTY instead.

This is necessary to build on Haiku, which also provides openpty()
via pty.h.

Signed-off-by: David Carlier <devnexen@gmail.com>
[PMM: Expanded commit message]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 configure           | 9 +++++++++
 util/qemu-openpty.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

Comments

Thomas Huth July 3, 2020, 3:12 p.m. UTC | #1
On 03/07/2020 16.56, Peter Maydell wrote:
> From: David CARLIER <devnexen@gmail.com>
> 
> Instead of using an OS-specific ifdef test to select the "openpty()
> is in pty.h" codepath, make configure check for the existence of
> the header and use the new CONFIG_PTY instead.
> 
> This is necessary to build on Haiku, which also provides openpty()
> via pty.h.
> 
> Signed-off-by: David Carlier <devnexen@gmail.com>
> [PMM: Expanded commit message]
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  configure           | 9 +++++++++
>  util/qemu-openpty.c | 2 +-
>  2 files changed, 10 insertions(+), 1 deletion(-)
[...]
> diff --git a/util/qemu-openpty.c b/util/qemu-openpty.c
> index 2e8b43bdf57..9d8ad6905e0 100644
> --- a/util/qemu-openpty.c
> +++ b/util/qemu-openpty.c
> @@ -35,7 +35,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
>  
> -#if defined(__GLIBC__)
> +#if defined CONFIG_PTY

Shouldn't there be some parentheses around CONFIG_PTY here?

 Thomas
Eric Blake July 6, 2020, 2 p.m. UTC | #2
On 7/3/20 10:12 AM, Thomas Huth wrote:

>> +++ b/util/qemu-openpty.c
>> @@ -35,7 +35,7 @@
>>   #include "qemu/osdep.h"
>>   #include "qemu-common.h"
>>   
>> -#if defined(__GLIBC__)
>> +#if defined CONFIG_PTY

> 
> Shouldn't there be some parentheses around CONFIG_PTY here?

No, they are optional, and omitting them is more consistent with the 
CONFIG_BSD just below.

 >  #elif defined CONFIG_BSD
 >  # include <termios.h>
Thomas Huth July 6, 2020, 4:50 p.m. UTC | #3
On 06/07/2020 16.00, Eric Blake wrote:
> On 7/3/20 10:12 AM, Thomas Huth wrote:
> 
>>> +++ b/util/qemu-openpty.c
>>> @@ -35,7 +35,7 @@
>>>   #include "qemu/osdep.h"
>>>   #include "qemu-common.h"
>>>   -#if defined(__GLIBC__)
>>> +#if defined CONFIG_PTY
> 
>>
>> Shouldn't there be some parentheses around CONFIG_PTY here?
> 
> No, they are optional, and omitting them is more consistent with the
> CONFIG_BSD just below.

Thanks, TIL - I'm doing so many years of C programming already, and
until now I never noticed any code that does not use parentheses after
"defined" ...

 Thomas
diff mbox series

Patch

diff --git a/configure b/configure
index c9c135b70bc..5455ae10d05 100755
--- a/configure
+++ b/configure
@@ -2386,6 +2386,12 @@  else
   l2tpv3=no
 fi
 
+if check_include "pty.h" ; then
+  pty_h=yes
+else
+  pty_h=no
+fi
+
 #########################################
 # vhost interdependencies and host support
 
@@ -7856,6 +7862,9 @@  fi
 if test "$sheepdog" = "yes" ; then
   echo "CONFIG_SHEEPDOG=y" >> $config_host_mak
 fi
+if test "$pty_h" = "yes" ; then
+  echo "CONFIG_PTY=y" >> $config_host_mak
+fi
 if test "$fuzzing" = "yes" ; then
   if test "$have_fuzzer" = "yes"; then
     FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
diff --git a/util/qemu-openpty.c b/util/qemu-openpty.c
index 2e8b43bdf57..9d8ad6905e0 100644
--- a/util/qemu-openpty.c
+++ b/util/qemu-openpty.c
@@ -35,7 +35,7 @@ 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-#if defined(__GLIBC__)
+#if defined CONFIG_PTY
 # include <pty.h>
 #elif defined CONFIG_BSD
 # include <termios.h>