summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-12 13:05:13 +0200
committerThomas Haller <thaller@redhat.com>2020-07-12 13:05:13 +0200
commit4168c19e0462f8dbc217436343ef9d0936533162 (patch)
tree5ddcf04b28d18d347e011997824575badccf43a0
parentecba92192087e13747a20626e64a07072c94772f (diff)
downloadNetworkManager-4168c19e0462f8dbc217436343ef9d0936533162.tar.gz
shared: move nm_close(), nm_auto_close, nm_steal_fd(), nm_steal_int() to nm-std-aux
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h75
-rw-r--r--shared/nm-std-aux/nm-std-aux.h80
2 files changed, 80 insertions, 75 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index c47fa36f90..d12fa3b602 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -151,8 +151,6 @@ NM_AUTO_DEFINE_FCN0 (GKeyFile *, gs_local_keyfile_unref, g_key_file_unref)
/*****************************************************************************/
-static inline int nm_close (int fd);
-
NM_AUTO_DEFINE_FCN0 (GVariantIter *, _nm_auto_free_variant_iter, g_variant_iter_free)
#define nm_auto_free_variant_iter nm_auto(_nm_auto_free_variant_iter)
@@ -184,30 +182,6 @@ _nm_auto_free_gstring (GString **str)
#define nm_auto_free_gstring nm_auto(_nm_auto_free_gstring)
static inline void
-_nm_auto_close (int *pfd)
-{
- if (*pfd >= 0) {
- int errsv = errno;
-
- (void) nm_close (*pfd);
- errno = errsv;
- }
-}
-#define nm_auto_close nm_auto(_nm_auto_close)
-
-static inline void
-_nm_auto_fclose (FILE **pfd)
-{
- if (*pfd) {
- int errsv = errno;
-
- (void) fclose (*pfd);
- errno = errsv;
- }
-}
-#define nm_auto_fclose nm_auto(_nm_auto_fclose)
-
-static inline void
_nm_auto_protect_errno (int *p_saved_errno)
{
errno = *p_saved_errno;
@@ -1546,55 +1520,6 @@ 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)
-{
- int fd;
-
- if ( p_fd
- && ((fd = *p_fd) >= 0)) {
- *p_fd = -1;
- return fd;
- }
- return -1;
-}
-
-/**
- * nm_close:
- *
- * Like close() but throws an assertion if the input fd is
- * invalid. Closing an invalid fd is a programming error, so
- * it's better to catch it early.
- */
-static inline int
-nm_close (int fd)
-{
- int r;
-
- r = close (fd);
- nm_assert (r != -1 || fd < 0 || errno != EBADF);
- return r;
-}
-
#define NM_PID_T_INVAL ((pid_t) -1)
/*****************************************************************************/
diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h
index 2351198930..26317c2c27 100644
--- a/shared/nm-std-aux/nm-std-aux.h
+++ b/shared/nm-std-aux/nm-std-aux.h
@@ -6,6 +6,9 @@
#include <assert.h>
#include <string.h>
#include <stdbool.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
/*****************************************************************************/
@@ -428,6 +431,25 @@ _NM_IN_STRSET_streq (const char *x, const char *s)
/*****************************************************************************/
+/**
+ * nm_close:
+ *
+ * Like close() but throws an assertion if the input fd is
+ * invalid. Closing an invalid fd is a programming error, so
+ * it's better to catch it early.
+ */
+static inline int
+nm_close (int fd)
+{
+ int r;
+
+ r = close (fd);
+ nm_assert (r != -1 || fd < 0 || errno != EBADF);
+ return r;
+}
+
+/*****************************************************************************/
+
/* Note: @value is only evaluated when *out_val is present.
* Thus,
* NM_SET_OUT (out_str, g_strdup ("hallo"));
@@ -493,6 +515,32 @@ NM_AUTO_DEFINE_FCN_VOID0 (void *, _nm_auto_free_impl, free)
/*****************************************************************************/
+static inline void
+_nm_auto_close (int *pfd)
+{
+ if (*pfd >= 0) {
+ int errsv = errno;
+
+ (void) nm_close (*pfd);
+ errno = errsv;
+ }
+}
+#define nm_auto_close nm_auto(_nm_auto_close)
+
+static inline void
+_nm_auto_fclose (FILE **pfd)
+{
+ if (*pfd) {
+ int errsv = errno;
+
+ (void) fclose (*pfd);
+ errno = errsv;
+ }
+}
+#define nm_auto_fclose nm_auto(_nm_auto_fclose)
+
+/*****************************************************************************/
+
#define nm_clear_pointer(pp, destroy) \
({ \
typeof (*(pp)) *_pp = (pp); \
@@ -538,4 +586,36 @@ _nm_steal_pointer (void *pp)
#define nm_steal_pointer(pp) \
((typeof (*(pp))) _nm_steal_pointer (pp))
+/**
+ * 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)
+{
+ int fd;
+
+ if ( p_fd
+ && ((fd = *p_fd) >= 0)) {
+ *p_fd = -1;
+ return fd;
+ }
+ return -1;
+}
+
#endif /* __NM_STD_AUX_H__ */