mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
glib-compat: add fallback for g_clear_fd/g_autofd
Those helpers were added in glib 2.76. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260623-b4-ui-v4-7-4656aec3398d@redhat.com>
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#if defined(G_OS_UNIX)
|
||||
#include <glib-unix.h>
|
||||
#include <sys/types.h>
|
||||
@@ -129,6 +130,34 @@ qemu_g_test_slow(void)
|
||||
#define g_test_thorough() qemu_g_test_slow()
|
||||
#define g_test_quick() (!qemu_g_test_slow())
|
||||
|
||||
static inline gboolean g_clear_fd_qemu(int *fd_ptr, GError **error)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION(2, 76, 0)
|
||||
return g_clear_fd(fd_ptr, error);
|
||||
#else
|
||||
int fd = *fd_ptr;
|
||||
|
||||
*fd_ptr = -1;
|
||||
|
||||
if (fd < 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return g_close(fd, error);
|
||||
#endif
|
||||
}
|
||||
#define g_clear_fd(fd, err) g_clear_fd_qemu(fd, err)
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 76, 0)
|
||||
static inline void _g_clear_fd_ignore_error(int *fd_ptr)
|
||||
{
|
||||
int errsv = errno;
|
||||
g_clear_fd(fd_ptr, NULL);
|
||||
errno = errsv;
|
||||
}
|
||||
#define g_autofd __attribute__((cleanup(_g_clear_fd_ignore_error)))
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#ifndef G_NORETURN
|
||||
|
||||
Reference in New Issue
Block a user