On 4/30/25 21:39, John Levon wrote:
Add simple helpers to correctly report failures from read/write routines
using the return -errno style.

I would keep these helpers under vfio for the moment.

Their use is a bit context-specific and making them common requires
more work, which would likely make them less useful.


Thanks,

C.





Signed-off-by: John Levon <john.le...@nutanix.com>
---
  include/qemu/error-report.h | 14 ++++++++++++++
  1 file changed, 14 insertions(+)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 3ae2357fda..67afe5a020 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -70,6 +70,20 @@ void error_init(const char *argv0);
                                fmt, ##__VA_ARGS__);      \
      })
+/*
+ * Given a return value of either a short number of bytes read or -errno,
+ * construct a meaningful error message.
+ */
+#define strreaderror(ret) \
+    (ret < 0 ? strerror(-ret) : "short read")
+
+/*
+ * Given a return value of either a short number of bytes written or -errno,
+ * construct a meaningful error message.
+ */
+#define strwriteerror(ret) \
+    (ret < 0 ? strerror(-ret) : "short write")
+
  extern bool message_with_timestamp;
  extern bool error_with_guestname;
  extern const char *error_guest_name;


Reply via email to