summaryrefslogtreecommitdiff
path: root/shared/nm-utils/nm-macros-internal.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-12-15 19:38:19 +0100
committerThomas Haller <thaller@redhat.com>2016-12-15 19:38:19 +0100
commitea944d5b4c5eac192a95cf0397459df24fee39cf (patch)
treeeb32a53af49bbbc828721c3a6cda446254e03542 /shared/nm-utils/nm-macros-internal.h
parent9afbaa86ced253c5e87093b11b9ab8a580df4f45 (diff)
parentf0d20c945e96495ac6065cd02ea688f4ea37727e (diff)
core: merge branch 'th/sysctl-ifname-race-bgo775613' (early part)
Backport some of the patches from "th/sysctl-ifname-race-bgo775613" branch. https://bugzilla.gnome.org/show_bug.cgi?id=775613
Diffstat (limited to 'shared/nm-utils/nm-macros-internal.h')
-rw-r--r--shared/nm-utils/nm-macros-internal.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index b6b6bdee4..de90e3f58 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -22,7 +22,9 @@
#ifndef __NM_MACROS_INTERNAL_H__
#define __NM_MACROS_INTERNAL_H__
+#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include "nm-glib.h"
@@ -59,7 +61,31 @@ _nm_auto_free_gstring_impl (GString **str)
}
#define nm_auto_free_gstring nm_auto(_nm_auto_free_gstring_impl)
-/********************************************************/
+static inline void
+_nm_auto_close_impl (int *pfd)
+{
+ if (*pfd >= 0) {
+ int errsv = errno;
+
+ (void) close (*pfd);
+ errno = errsv;
+ }
+}
+#define nm_auto_close nm_auto(_nm_auto_close_impl)
+
+static inline void
+_nm_auto_fclose_impl (FILE **pfd)
+{
+ if (*pfd) {
+ int errsv = errno;
+
+ (void) fclose (*pfd);
+ errno = errsv;
+ }
+}
+#define nm_auto_fclose nm_auto(_nm_auto_fclose_impl)
+
+/*****************************************************************************/
/* http://stackoverflow.com/a/11172679 */
#define _NM_UTILS_MACRO_FIRST(...) __NM_UTILS_MACRO_FIRST_HELPER(__VA_ARGS__, throwaway)