summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-02-07 17:38:57 +0100
committerThomas Haller <thaller@redhat.com>2018-02-12 13:29:03 +0100
commitd46de19a9ab6763461fe55b41956837e3b021f13 (patch)
treece9163941c69b34a4c04484790502f1cc983bbca
parent4e5bef395129ff5e8d416dacf25a0270d41f18fa (diff)
downloadNetworkManager-d46de19a9ab6763461fe55b41956837e3b021f13.tar.gz
shared: add nm_steal_int() helper
-rw-r--r--shared/nm-utils/nm-macros-internal.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index f4b25b34e8..d3cbe2f050 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -1318,6 +1318,25 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro)
/*****************************************************************************/
+/**
+ * nm_steal_int:
+ * @p_val: pointer to an int type.
+ *
+ * Returns: *p_val and sets *p_val to zero the same time.
+ * Accepts %NULL, in which case also numeric 0 will be returned.
+ */
+#define nm_steal_int(p_val) \
+ ({ \
+ typeof (p_val) const _p_val = (p_val); \
+ typeof (*_p_val) _val = 0; \
+ \
+ if ( _p_val \
+ && (_val = *_p_val)) { \
+ *_p_val = 0; \
+ } \
+ _val; \
+ })
+
static inline int
nm_steal_fd (int *p_fd)
{