qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2 04/19] osdep.h: Introduce a QEMU file descriptor type


From: Daniel P . Berrangé
Subject: Re: [PATCH v2 04/19] osdep.h: Introduce a QEMU file descriptor type
Date: Fri, 11 Nov 2022 09:07:26 +0000
User-agent: Mutt/2.2.7 (2022-08-07)

On Fri, Nov 11, 2022 at 12:22:10PM +0800, Bin Meng wrote:
> Introduce a new QemuFd_t type to represent a file descriptor for
> different platforms. On POSIX platforms, this is a file descriptor
> On Windows, this is a file handle.

Can we not use  _open_osfhandle() to obtain a C runtime
file descriptor from the Windows HANDLE.  We do this in
QEMU's socket code, so we don't have to work wit different
types and APIs on Windows, and I think that's much nicer
in general.

> 
> Changes in v2:
> - Change to introduce QemuFd_t in osdep.h
> 
>  include/qemu/osdep.h | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index b9c4307779..45fc8bb5d9 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -705,6 +705,32 @@ static inline int platform_does_not_support_system(const 
> char *command)
>  }
>  #endif /* !HAVE_SYSTEM_FUNCTION */
>  
> +/*
> + * QEMU file descriptor type
> + *
> + * On POSIX platforms, this is a file descriptor (int).
> + * On Windows, this is a file handle (HANDLE).
> + */
> +#ifndef _WIN32
> +typedef int QemuFd_t;
> +#define QEMU_FD_INVALID -1
> +#else
> +typedef HANDLE QemuFd_t;
> +#define QEMU_FD_INVALID INVALID_HANDLE_VALUE
> +#endif
> +
> +/**
> + * qemu_fd_invalid - determine if a given QEMU file descriptor is invalid
> + *
> + * @fd: the value of a QEMU file descriptor
> + *
> + * Returns true if a given QEMU file descriptor is invalid, otherwise false.
> + */
> +static inline bool qemu_fd_invalid(QemuFd_t fd)
> +{
> +    return (fd == QEMU_FD_INVALID);
> +}
> +
>  #ifdef __cplusplus
>  }
>  #endif
> -- 
> 2.25.1
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




reply via email to

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