@@ -10,3 +10,9 @@
#define DEFINE_CLEANUP_FUNC(func) \
inline __attribute__((always_inline)) \
void func ## _cleanup(void *p) { func(*(void **) p); }
+
+#define __AUTODESTRUCT(func) \
+ __attribute((cleanup(func ## _cleanup)))
+
+#define _auto_(func) \
+ __AUTODESTRUCT(func)
@@ -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)
@@ -64,21 +59,6 @@ static inline unsigned char bit_field(const unsigned char oct,
_x / _d; \
})
-#define __AUTODESTRUCT(func) \
- __attribute((cleanup(func ## _cleanup)))
-
-#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
@@ -15,6 +15,8 @@
#include <endian.h>
#include <byteswap.h>
#include <sys/uio.h>
+#include <errno.h>
+#include <unistd.h>
#include <ell/cleanup.h>
#ifdef __cplusplus
@@ -437,6 +439,15 @@ int l_safe_atox32(const char *s, uint32_t *out_u);
int l_safe_atox16(const char *s, uint16_t *out_u);
int l_safe_atox8(const char *s, uint8_t *out_u);
+/* 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));
+}
+
#ifdef __cplusplus
}
#endif