[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/19] osdep.h: Introduce a QEMU file descriptor type
From: |
Bin Meng |
Subject: |
[PATCH v2 04/19] osdep.h: Introduce a QEMU file descriptor type |
Date: |
Fri, 11 Nov 2022 12:22:10 +0800 |
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.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
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