Add simple helpers to correctly report failures from read/write routines using the return -errno style.
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; -- 2.43.0