From ea18312ed03e0077740e327966a8e0e5810d7f5b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Nov 2022 11:05:12 +0000 Subject: backports: Add g_steal_fd, from GLib >= 2.70 This is essentially the same as glnx_steal_fd, so make glnx_steal_fd an alias for it. The unit test is taken from GLib, slightly modified to avoid g_close() and also test the old name glnx_steal_fd(). Signed-off-by: Simon McVittie --- glnx-local-alloc.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'glnx-local-alloc.h') diff --git a/glnx-local-alloc.h b/glnx-local-alloc.h index 615b954..65ae747 100644 --- a/glnx-local-alloc.h +++ b/glnx-local-alloc.h @@ -24,6 +24,8 @@ #include #include +#include "glnx-backports.h" + G_BEGIN_DECLS /** @@ -43,19 +45,14 @@ glnx_local_obj_unref (void *v) } #define glnx_unref_object __attribute__ ((cleanup(glnx_local_obj_unref))) -static inline int -glnx_steal_fd (int *fdp) -{ - int fd = *fdp; - *fdp = -1; - return fd; -} +/* Backwards-compat with older libglnx */ +#define glnx_steal_fd g_steal_fd /** * glnx_close_fd: * @fdp: Pointer to fd * - * Effectively `close (glnx_steal_fd (&fd))`. Also + * Effectively `close (g_steal_fd (&fd))`. Also * asserts that `close()` did not raise `EBADF` - encountering * that error is usually a critical bug in the program. */ @@ -66,7 +63,7 @@ glnx_close_fd (int *fdp) g_assert (fdp); - int fd = glnx_steal_fd (fdp); + int fd = g_steal_fd (fdp); if (fd >= 0) { errsv = errno; -- cgit v1.2.1