From 0feeeaac636e39e724a2b3dc848b0fe12858d859 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Sep 2018 14:17:22 +0200 Subject: [PATCH] shared: add nm_utils_mem_all_zero() --- shared/nm-utils/nm-shared-utils.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index ce5fd9986e..778938e09c 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -190,6 +190,22 @@ nm_ip_addr_set (int addr_family, gpointer dst, const NMIPAddr *src) /*****************************************************************************/ +static inline gboolean +nm_utils_mem_all_zero (gconstpointer mem, gsize len) +{ + const guint8 *p; + + for (p = mem; len-- > 0; p++) { + if (*p != 0) + return FALSE; + } + + /* incidentally, a buffer with len==0, is also *all-zero*. */ + return TRUE; +} + +/*****************************************************************************/ + /* like g_memdup(). The difference is that the @size argument is of type * gsize, while g_memdup() has type guint. Since, the size of container types * like GArray is guint as well, this means trying to g_memdup() an