summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-07-28 09:05:30 (GMT)
committerThomas Haller <thaller@redhat.com>2023-07-28 09:13:33 (GMT)
commita9a9dceab502498eb0afd368a06f1093f092bd0c (patch)
treeddafbef22829f1326e92bf1b14ae8d1d92ebd008
parent590e8a61f899e76ae064ad68cff4766a77c5414a (diff)
downloadlibnl-a9a9dceab502498eb0afd368a06f1093f092bd0c.zip
libnl-a9a9dceab502498eb0afd368a06f1093f092bd0c.tar.gz
libnl-a9a9dceab502498eb0afd368a06f1093f092bd0c.tar.bz2
style: format "include/netlink-private/utils.h" with clang-format
-rw-r--r--include/netlink-private/nl-auto.h2
-rw-r--r--include/netlink-private/utils.h242
-rwxr-xr-xtools/clang-format.sh1
3 files changed, 123 insertions, 122 deletions
diff --git a/include/netlink-private/nl-auto.h b/include/netlink-private/nl-auto.h
index 4092782..4895169 100644
--- a/include/netlink-private/nl-auto.h
+++ b/include/netlink-private/nl-auto.h
@@ -5,7 +5,7 @@
#include <stdlib.h>
-#define _nl_auto(fcn) __attribute__ ((__cleanup__(fcn)))
+#define _nl_auto(fcn) __attribute__((__cleanup__(fcn)))
#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
static inline void name(void *v) \
diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
index 93a04c9..49a298b 100644
--- a/include/netlink-private/utils.h
+++ b/include/netlink-private/utils.h
@@ -24,15 +24,17 @@
/*****************************************************************************/
-#define _NL_STRINGIFY_ARG(contents) #contents
-#define _NL_STRINGIFY(macro_or_string) _NL_STRINGIFY_ARG (macro_or_string)
+#define _NL_STRINGIFY_ARG(contents) #contents
+#define _NL_STRINGIFY(macro_or_string) _NL_STRINGIFY_ARG(macro_or_string)
/*****************************************************************************/
-#if defined (__GNUC__)
-#define _NL_PRAGMA_WARNING_DO(warning) _NL_STRINGIFY(GCC diagnostic ignored warning)
-#elif defined (__clang__)
-#define _NL_PRAGMA_WARNING_DO(warning) _NL_STRINGIFY(clang diagnostic ignored warning)
+#if defined(__GNUC__)
+#define _NL_PRAGMA_WARNING_DO(warning) \
+ _NL_STRINGIFY(GCC diagnostic ignored warning)
+#elif defined(__clang__)
+#define _NL_PRAGMA_WARNING_DO(warning) \
+ _NL_STRINGIFY(clang diagnostic ignored warning)
#endif
/* you can only suppress a specific warning that the compiler
@@ -41,34 +43,34 @@
* It's not that bad however, because gcc and clang often have the
* same name for the same warning. */
-#if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
-#define _NL_PRAGMA_WARNING_DISABLE(warning) \
- _Pragma("GCC diagnostic push") \
- _Pragma(_NL_PRAGMA_WARNING_DO("-Wpragmas")) \
- _Pragma(_NL_PRAGMA_WARNING_DO(warning))
-#elif defined (__clang__)
-#define _NL_PRAGMA_WARNING_DISABLE(warning) \
- _Pragma("clang diagnostic push") \
- _Pragma(_NL_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \
- _Pragma(_NL_PRAGMA_WARNING_DO(warning))
+#if defined(__GNUC__) && \
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#define _NL_PRAGMA_WARNING_DISABLE(warning) \
+ _Pragma("GCC diagnostic push") \
+ _Pragma(_NL_PRAGMA_WARNING_DO("-Wpragmas")) \
+ _Pragma(_NL_PRAGMA_WARNING_DO(warning))
+#elif defined(__clang__)
+#define _NL_PRAGMA_WARNING_DISABLE(warning) \
+ _Pragma("clang diagnostic push") \
+ _Pragma(_NL_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \
+ _Pragma(_NL_PRAGMA_WARNING_DO(warning))
#else
#define _NL_PRAGMA_WARNING_DISABLE(warning)
#endif
-#if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
-#define _NL_PRAGMA_WARNING_REENABLE \
- _Pragma("GCC diagnostic pop")
-#elif defined (__clang__)
-#define _NL_PRAGMA_WARNING_REENABLE \
- _Pragma("clang diagnostic pop")
+#if defined(__GNUC__) && \
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#define _NL_PRAGMA_WARNING_REENABLE _Pragma("GCC diagnostic pop")
+#elif defined(__clang__)
+#define _NL_PRAGMA_WARNING_REENABLE _Pragma("clang diagnostic pop")
#else
#define _NL_PRAGMA_WARNING_REENABLE
#endif
/*****************************************************************************/
-#define _nl_unused __attribute__ ((__unused__))
-#define _nl_auto(fcn) __attribute__ ((__cleanup__(fcn)))
+#define _nl_unused __attribute__((__unused__))
+#define _nl_auto(fcn) __attribute__((__cleanup__(fcn)))
/*****************************************************************************/
@@ -89,14 +91,19 @@
/*****************************************************************************/
-#define _NL_STATIC_ASSERT(cond) ((void) sizeof (char[(cond) ? 1 : -1]))
+#define _NL_STATIC_ASSERT(cond) ((void)sizeof(char[(cond) ? 1 : -1]))
/*****************************************************************************/
#if defined(NL_MORE_ASSERTS) && NL_MORE_ASSERTS > 0
#define _nl_assert(cond) assert(cond)
#else
-#define _nl_assert(cond) do { if (0) { assert(cond); } } while (0)
+#define _nl_assert(cond) \
+ do { \
+ if (0) { \
+ assert(cond); \
+ } \
+ } while (0)
#endif
#define _nl_assert_not_reached() assert(0)
@@ -148,63 +155,62 @@ extern const char *nl_strerror_l(int err);
/* internal macro to calculate the size of a struct @type up to (and including) @field.
* this will be used for .minlen policy fields, so that we require only a field of up
* to the given size. */
-#define _nl_offsetofend(type, field) (offsetof (type, field) + sizeof (((type *) NULL)->field))
+#define _nl_offsetofend(type, field) \
+ (offsetof(type, field) + sizeof(((type *)NULL)->field))
/*****************************************************************************/
-#define _nl_clear_pointer(pp, destroy) \
- ({ \
- __typeof__ (*(pp)) *_pp = (pp); \
- __typeof__ (*_pp) _p; \
- int _changed = 0; \
- \
- if ( _pp \
- && (_p = *_pp)) { \
+#define _nl_clear_pointer(pp, destroy) \
+ ({ \
+ __typeof__(*(pp)) *_pp = (pp); \
+ __typeof__(*_pp) _p; \
+ int _changed = 0; \
+ \
+ if (_pp && (_p = *_pp)) { \
_nl_unused const void *const _p_check_is_pointer = _p; \
- \
- *_pp = NULL; \
- \
- (destroy) (_p); \
- \
- _changed = 1; \
- } \
- _changed; \
+ \
+ *_pp = NULL; \
+ \
+ (destroy)(_p); \
+ \
+ _changed = 1; \
+ } \
+ _changed; \
})
-#define _nl_clear_free(pp) _nl_clear_pointer (pp, free)
-
-#define _nl_steal_pointer(pp) \
- ({ \
- __typeof__ (*(pp)) *const _pp = (pp); \
- __typeof__ (*_pp) _p = NULL; \
- \
- if ( _pp \
- && (_p = *_pp)) { \
- *_pp = NULL; \
- } \
- \
- _p; \
+#define _nl_clear_free(pp) _nl_clear_pointer(pp, free)
+
+#define _nl_steal_pointer(pp) \
+ ({ \
+ __typeof__(*(pp)) *const _pp = (pp); \
+ __typeof__(*_pp) _p = NULL; \
+ \
+ if (_pp && (_p = *_pp)) { \
+ *_pp = NULL; \
+ } \
+ \
+ _p; \
})
/*****************************************************************************/
-#define _nl_malloc_maybe_a(alloca_maxlen, bytes, to_free) \
- ({ \
- const size_t _bytes = (bytes); \
- __typeof__ (to_free) _to_free = (to_free); \
- __typeof__ (*_to_free) _ptr; \
- \
- _NL_STATIC_ASSERT ((alloca_maxlen) <= 500); \
- _nl_assert (_to_free && !*_to_free); \
- \
- if (_bytes <= (alloca_maxlen)) { \
- _ptr = alloca (_bytes); \
- } else { \
- _ptr = malloc (_bytes); \
- *_to_free = _ptr; \
- }; \
- \
- _ptr; \
+#define _nl_malloc_maybe_a(alloca_maxlen, bytes, to_free) \
+ ({ \
+ const size_t _bytes = (bytes); \
+ __typeof__(to_free) _to_free = (to_free); \
+ __typeof__(*_to_free) _ptr; \
+ \
+ _NL_STATIC_ASSERT((alloca_maxlen) <= 500); \
+ _nl_assert(_to_free && !*_to_free); \
+ \
+ if (_bytes <= (alloca_maxlen)) { \
+ _ptr = alloca(_bytes); \
+ } else { \
+ _ptr = malloc(_bytes); \
+ *_to_free = _ptr; \
+ }; \
+ \
+ _ptr; \
})
/*****************************************************************************/
@@ -219,8 +225,7 @@ static inline bool _nl_streq0(const char *a, const char *b)
return a == b || (a && b && _nl_streq(a, b));
}
-static inline char *
-_nl_strncpy_trunc(char *dst, const char *src, size_t len)
+static inline char *_nl_strncpy_trunc(char *dst, const char *src, size_t len)
{
/* we don't use/reimplement strlcpy(), because we want the fill-all-with-NUL
* behavior of strncpy(). This is just strncpy() with gracefully handling truncation
@@ -229,8 +234,8 @@ _nl_strncpy_trunc(char *dst, const char *src, size_t len)
* Note that truncation is silently accepted.
*/
- _NL_PRAGMA_WARNING_DISABLE ("-Wstringop-truncation");
- _NL_PRAGMA_WARNING_DISABLE ("-Wstringop-overflow");
+ _NL_PRAGMA_WARNING_DISABLE("-Wstringop-truncation");
+ _NL_PRAGMA_WARNING_DISABLE("-Wstringop-overflow");
if (len > 0) {
_nl_assert(dst);
@@ -247,8 +252,7 @@ _nl_strncpy_trunc(char *dst, const char *src, size_t len)
return dst;
}
-static inline char *
-_nl_strncpy_assert(char *dst, const char *src, size_t len)
+static inline char *_nl_strncpy_assert(char *dst, const char *src, size_t len)
{
/* we don't use/reimplement strlcpy(), because we want the fill-all-with-NUL
* behavior of strncpy(). This is just strncpy() with assertion against truncation
@@ -258,8 +262,8 @@ _nl_strncpy_assert(char *dst, const char *src, size_t len)
* against that.
*/
- _NL_PRAGMA_WARNING_DISABLE ("-Wstringop-truncation");
- _NL_PRAGMA_WARNING_DISABLE ("-Wstringop-overflow");
+ _NL_PRAGMA_WARNING_DISABLE("-Wstringop-truncation");
+ _NL_PRAGMA_WARNING_DISABLE("-Wstringop-overflow");
if (len > 0) {
_nl_assert(dst);
@@ -267,7 +271,7 @@ _nl_strncpy_assert(char *dst, const char *src, size_t len)
strncpy(dst, src, len);
- _nl_assert (dst[len - 1] == '\0');
+ _nl_assert(dst[len - 1] == '\0');
dst[len - 1] = '\0';
}
@@ -280,51 +284,50 @@ _nl_strncpy_assert(char *dst, const char *src, size_t len)
#include "nl-auto.h"
-#define _NL_RETURN_ON_ERR(cmd) \
- do { \
- int _err; \
- \
- _err = (cmd); \
- if (_err < 0) \
- return _err; \
+#define _NL_RETURN_ON_ERR(cmd) \
+ do { \
+ int _err; \
+ \
+ _err = (cmd); \
+ if (_err < 0) \
+ return _err; \
} while (0)
-#define _NL_RETURN_E_ON_ERR(e, cmd) \
- do { \
- int _err; \
- \
- _err = (cmd); \
- if (_err < 0) { \
- _NL_STATIC_ASSERT((e) > 0); \
- return -(e); \
- } \
+#define _NL_RETURN_E_ON_ERR(e, cmd) \
+ do { \
+ int _err; \
+ \
+ _err = (cmd); \
+ if (_err < 0) { \
+ _NL_STATIC_ASSERT((e) > 0); \
+ return -(e); \
+ } \
} while (0)
/* _NL_RETURN_ON_PUT_ERR() shall only be used with a put command (nla_put or nlmsg_append).
* These commands can either fail with a regular error code (which gets propagated)
* or with -NLE_NOMEM. However, they don't really try to allocate memory, so we don't
* want to propagate -NLE_NOMEM. Instead, we coerce such failure to -NLE_MSGSIZE. */
-#define _NL_RETURN_ON_PUT_ERR(put_cmd) \
- do { \
- int _err; \
- \
- _err = (put_cmd); \
- if (_err < 0) { \
- if (_err == -NLE_NOMEM) { \
+#define _NL_RETURN_ON_PUT_ERR(put_cmd) \
+ do { \
+ int _err; \
+ \
+ _err = (put_cmd); \
+ if (_err < 0) { \
+ if (_err == -NLE_NOMEM) { \
/* nla_put() returns -NLE_NOMEM in case of out of buffer size. We don't
* want to propagate that error and map it to -NLE_MSGSIZE. */ \
- return -NLE_MSGSIZE; \
- } \
+ return -NLE_MSGSIZE; \
+ } \
/* any other error can only be due to invalid parameters. Propagate the
- * error, however also assert that it cannot be reached. */ \
- _nl_assert_not_reached (); \
- return _err; \
- } else \
- _nl_assert (_err == 0); \
+ * error, however also assert that it cannot be reached. */ \
+ _nl_assert_not_reached(); \
+ return _err; \
+ } else \
+ _nl_assert(_err == 0); \
} while (0)
-static inline int
-_nl_close(int fd)
+static inline int _nl_close(int fd)
{
int r;
@@ -333,8 +336,7 @@ _nl_close(int fd)
return r;
}
-static inline void *
-_nl_memdup(const void *ptr, size_t len)
+static inline void *_nl_memdup(const void *ptr, size_t len)
{
void *p;
@@ -351,7 +353,7 @@ _nl_memdup(const void *ptr, size_t len)
return p;
}
-#define _nl_memdup_ptr(ptr) ((__typeof__(ptr)) _nl_memdup((ptr), sizeof(*(ptr))))
+#define _nl_memdup_ptr(ptr) ((__typeof__(ptr))_nl_memdup((ptr), sizeof(*(ptr))))
/*****************************************************************************/
@@ -374,10 +376,10 @@ static inline char *_nl_inet_ntop(int addr_family, const void *addr,
r = (char *)inet_ntop(addr_family, addr, buf,
(addr_family == AF_INET) ? INET_ADDRSTRLEN :
- INET6_ADDRSTRLEN);
+ INET6_ADDRSTRLEN);
_nl_assert(r == buf);
_nl_assert(strlen(r) < ((addr_family == AF_INET) ? INET_ADDRSTRLEN :
- INET6_ADDRSTRLEN));
+ INET6_ADDRSTRLEN));
return r;
}
@@ -387,7 +389,7 @@ static inline char *_nl_inet_ntop_dup(int addr_family, const void *addr)
return (char *)_nl_inet_ntop(addr_family, addr,
malloc((addr_family == AF_INET) ?
INET_ADDRSTRLEN :
- INET6_ADDRSTRLEN));
+ INET6_ADDRSTRLEN));
}
#endif
diff --git a/tools/clang-format.sh b/tools/clang-format.sh
index f430114..7c0c012 100755
--- a/tools/clang-format.sh
+++ b/tools/clang-format.sh
@@ -27,7 +27,6 @@ EXCLUDE_PATHS_TOPLEVEL+=(
"include/netlink-private/socket.h"
"include/netlink-private/tc.h"
"include/netlink-private/types.h"
- "include/netlink-private/utils.h"
"include/netlink/addr.h"
"include/netlink/attr.h"
"include/netlink/cache-api.h"