From ed7f6da282e263403badb507b2532f51f8ed31cf Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 11 Jun 2025 10:16:10 +0200 Subject: rust/qemu-api: log: implement io::Write This makes it possible to lock the log file; it also makes log_mask_ln! not allocate memory when logging a constant string. Reviewed-by: Zhao Liu Reviewed-by: Manos Pitsidianakis Signed-off-by: Paolo Bonzini --- util/log.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'util/log.c') diff --git a/util/log.c b/util/log.c index b87d399e4c..58d24de48a 100644 --- a/util/log.c +++ b/util/log.c @@ -558,3 +558,15 @@ void qemu_print_log_usage(FILE *f) fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n"); #endif } + +#ifdef CONFIG_HAVE_RUST +ssize_t rust_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + /* + * Same as fwrite, but return -errno because Rust libc does not provide + * portable access to errno. :( + */ + int ret = fwrite(ptr, size, nmemb, stream); + return ret < 0 ? -errno : 0; +} +#endif -- cgit 1.4.1