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 :|