From d3e9b5134663c08165f33ea38d2de7143eeb570d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Jul 2023 17:11:28 +0200 Subject: include/utils: move nl-auto base defines to "utils.h" "utils.h" will become the internal helper "library" at the lowest level. While "nl-auto.h" contains libnl3 specific functions, "utils.h" does not. Move libnl3 specific helpers from "nl-auto.h" to "utils.h". --- include/netlink-private/netlink.h | 1 + include/netlink-private/nl-auto.h | 29 +---------------------------- include/netlink-private/utils.h | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h index 60af091..6ab141b 100644 --- a/include/netlink-private/netlink.h +++ b/include/netlink-private/netlink.h @@ -60,6 +60,7 @@ #include #include #include +#include #define NSEC_PER_SEC 1000000000L diff --git a/include/netlink-private/nl-auto.h b/include/netlink-private/nl-auto.h index f4c75d3..887f627 100644 --- a/include/netlink-private/nl-auto.h +++ b/include/netlink-private/nl-auto.h @@ -5,34 +5,7 @@ #include -#define _nl_auto(fcn) __attribute__((__cleanup__(fcn))) - -#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \ - static inline void name(void *v) \ - { \ - if (*((CastType *)v)) \ - func(*((CastType *)v)); \ - } \ - struct _nl_dummy_for_tailing_semicolon - -#define _NL_AUTO_DEFINE_FCN_STRUCT(CastType, name, func) \ - static inline void name(CastType *v) \ - { \ - if (v) \ - func(v); \ - } \ - struct _nl_dummy_for_tailing_semicolon - -#define _NL_AUTO_DEFINE_FCN_TYPED0(CastType, name, func) \ - static inline void name(CastType *v) \ - { \ - if (*v) \ - func(*v); \ - } \ - struct _nl_dummy_for_tailing_semicolon - -#define _nl_auto_free _nl_auto(_nl_auto_free_fcn) -_NL_AUTO_DEFINE_FCN_VOID0(void *, _nl_auto_free_fcn, free); +#include "netlink-private/utils.h" struct nl_addr; void nl_addr_put(struct nl_addr *); diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h index b2d8b46..6c27ce5 100644 --- a/include/netlink-private/utils.h +++ b/include/netlink-private/utils.h @@ -86,6 +86,7 @@ #define _nl_deprecated(msg) __attribute__((__deprecated__(msg))) #define _nl_init __attribute__((constructor)) #define _nl_exit __attribute__((destructor)) +#define _nl_auto(fcn) __attribute__((__cleanup__(fcn))) /*****************************************************************************/ @@ -574,8 +575,6 @@ static inline char *_nl_strncpy_assert(char *dst, const char *src, size_t len) return dst; } -#include "nl-auto.h" - #define _NL_RETURN_ON_ERR(cmd) \ do { \ int _err; \ @@ -684,4 +683,33 @@ static inline char *_nl_inet_ntop_dup(int addr_family, const void *addr) INET6_ADDRSTRLEN)); } +/*****************************************************************************/ + +#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \ + static inline void name(void *v) \ + { \ + if (*((CastType *)v)) \ + func(*((CastType *)v)); \ + } \ + struct _nl_dummy_for_tailing_semicolon + +#define _NL_AUTO_DEFINE_FCN_STRUCT(CastType, name, func) \ + static inline void name(CastType *v) \ + { \ + if (v) \ + func(v); \ + } \ + struct _nl_dummy_for_tailing_semicolon + +#define _NL_AUTO_DEFINE_FCN_TYPED0(CastType, name, func) \ + static inline void name(CastType *v) \ + { \ + if (*v) \ + func(*v); \ + } \ + struct _nl_dummy_for_tailing_semicolon + +#define _nl_auto_free _nl_auto(_nl_auto_free_fcn) +_NL_AUTO_DEFINE_FCN_VOID0(void *, _nl_auto_free_fcn, free); + #endif -- cgit v0.12