[PATCH 1/2] useful: Move close cleanup into ell/util.h
Denis Kenzior <[email protected]> Thu, 1 Feb 2024 09:17:33 -0600
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <[email protected]> |
---
ell/useful.h | 14 --------------
ell/util.h | 11 +++++++++++
2 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/ell/useful.h b/ell/useful.h
index 5a4a5eba091c..8a4bf2ce70c9 100644
--- a/ell/useful.h
+++ b/ell/useful.h
@@ -5,11 +5,6 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
-#include <unistd.h>
-#include <errno.h>
-
-#include <ell/util.h>
-
#define align_len(len, boundary) (((len)+(boundary)-1) & ~((boundary)-1))
#define likely(x) __builtin_expect(!!(x), 1)
@@ -70,15 +65,6 @@ static inline unsigned char bit_field(const unsigned char oct,
#define _auto_(func) \
__AUTODESTRUCT(func)
-/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */
-inline __attribute__((always_inline)) void close_cleanup(void *p)
-{
- int fd = *(int *) p;
-
- if (fd >= 0)
- L_TFR(close(fd));
-}
-
/*
* Trick the compiler into thinking that var might be changed somehow by
* the asm
diff --git a/ell/util.h b/ell/util.h
index 5dfc35c89ea6..db86bfe278ea 100644
--- a/ell/util.h
+++ b/ell/util.h
@@ -14,6 +14,8 @@
#include <inttypes.h>
#include <endian.h>
#include <byteswap.h>
+#include <unistd.h>
+#include <errno.h>
#include <sys/uio.h>
#include <ell/cleanup.h>
@@ -314,6 +316,15 @@ const char *l_util_get_debugfs_path(void);
while (__result == -1L && errno == EINTR); \
__result; }))
+/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */
+inline __attribute__((always_inline)) void close_cleanup(void *p)
+{
+ int fd = *(int *) p;
+
+ if (fd >= 0)
+ L_TFR(close(fd));
+}
+
#define _L_IN_SET_CMP(val, type, cmp, ...) __extension__ ({ \
const type __v = (val); \
const typeof(__v) __elems[] = {__VA_ARGS__}; \
--
2.43.0