diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-glib-aux/nm-c-list.h | 28 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-glib.h | 12 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-io-utils.c | 23 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-io-utils.h | 4 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-macros-internal.h | 24 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.c | 29 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 3 |
7 files changed, 119 insertions, 4 deletions
diff --git a/shared/nm-glib-aux/nm-c-list.h b/shared/nm-glib-aux/nm-c-list.h index d835bbc1d4..36f1ff755b 100644 --- a/shared/nm-glib-aux/nm-c-list.h +++ b/shared/nm-glib-aux/nm-c-list.h @@ -101,12 +101,24 @@ nm_c_list_elem_find_first (CList *head, gconstpointer needle) /*****************************************************************************/ +/** + * nm_c_list_move_before: + * @lst: the list element to which @elem will be prepended. + * @elem: the list element to move. + * + * This unlinks @elem from the current list and linkes it before + * @lst. This is like c_list_link_before(), except that @elem must + * be initialized and linked. Note that @elem may be linked in @lst + * or in another list. In both cases it gets moved. + * + * Returns: %TRUE if there were any changes. %FALSE if elem was already + * linked at the right place. + */ static inline gboolean nm_c_list_move_before (CList *lst, CList *elem) { nm_assert (lst); nm_assert (elem); - nm_assert (c_list_contains (lst, elem)); if ( lst != elem && lst->prev != elem) { @@ -118,12 +130,24 @@ nm_c_list_move_before (CList *lst, CList *elem) } #define nm_c_list_move_tail(lst, elem) nm_c_list_move_before (lst, elem) +/** + * nm_c_list_move_after: + * @lst: the list element to which @elem will be prepended. + * @elem: the list element to move. + * + * This unlinks @elem from the current list and linkes it after + * @lst. This is like c_list_link_after(), except that @elem must + * be initialized and linked. Note that @elem may be linked in @lst + * or in another list. In both cases it gets moved. + * + * Returns: %TRUE if there were any changes. %FALSE if elem was already + * linked at the right place. + */ static inline gboolean nm_c_list_move_after (CList *lst, CList *elem) { nm_assert (lst); nm_assert (elem); - nm_assert (c_list_contains (lst, elem)); if ( lst != elem && lst->next != elem) { diff --git a/shared/nm-glib-aux/nm-glib.h b/shared/nm-glib-aux/nm-glib.h index 77a0913899..bdb7ea5b3e 100644 --- a/shared/nm-glib-aux/nm-glib.h +++ b/shared/nm-glib-aux/nm-glib.h @@ -522,10 +522,18 @@ _nm_g_variant_new_printf (const char *format_string, ...) /*****************************************************************************/ -#if !GLIB_CHECK_VERSION (2, 56, 0) +/* Recent glib also casts the results to typeof(Obj), but only if + * + * ( defined(g_has_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56 ) + * + * Since we build NetworkManager with older GLIB_VERSION_MAX_ALLOWED, it's + * not taking effect. + * + * Override this. */ +#undef g_object_ref +#undef g_object_ref_sink #define g_object_ref(Obj) ((typeof(Obj)) g_object_ref (Obj)) #define g_object_ref_sink(Obj) ((typeof(Obj)) g_object_ref_sink (Obj)) -#endif /*****************************************************************************/ diff --git a/shared/nm-glib-aux/nm-io-utils.c b/shared/nm-glib-aux/nm-io-utils.c index 7b9ca0218a..23133ec568 100644 --- a/shared/nm-glib-aux/nm-io-utils.c +++ b/shared/nm-glib-aux/nm-io-utils.c @@ -436,3 +436,26 @@ nm_utils_file_set_contents (const char *filename, return TRUE; } + +/** + * nm_utils_file_stat: + * @filename: the filename to stat. + * @out_st: (allow-none) (out): if given, this will be passed to stat(). + * + * Just wraps stat() and gives the errno number as function result instead + * of setting the errno (though, errno is also set). It's only for convenience + * with + * + * if (nm_utils_file_stat (filename, NULL) == -ENOENT) { + * } + * + * Returns: 0 on success a negative errno on failure. */ +int +nm_utils_file_stat (const char *filename, struct stat *out_st) +{ + struct stat st; + + if (stat (filename, out_st ?: &st) != 0) + return -NM_ERRNO_NATIVE (errno); + return 0; +} diff --git a/shared/nm-glib-aux/nm-io-utils.h b/shared/nm-glib-aux/nm-io-utils.h index 6037242b02..121fc481d9 100644 --- a/shared/nm-glib-aux/nm-io-utils.h +++ b/shared/nm-glib-aux/nm-io-utils.h @@ -59,4 +59,8 @@ gboolean nm_utils_file_set_contents (const char *filename, mode_t mode, GError **error); +struct stat; + +int nm_utils_file_stat (const char *filename, struct stat *out_st); + #endif /* __NM_IO_UTILS_H__ */ diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 5b594a2ab5..d2210db006 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1160,6 +1160,30 @@ nm_g_object_unref (gpointer obj) #define nm_clear_g_object(pp) \ nm_clear_pointer (pp, g_object_unref) +/** + * nm_clear_error: + * @err: a pointer to pointer to a #GError. + * + * This is like g_clear_error(). The only difference is + * that this is an inline function. + */ +static inline void +nm_clear_error (GError **err) +{ + if (err && *err) { + g_error_free (*err); + *err = NULL; + } +} + +/* Patch g_clear_error() to use nm_clear_error(), which is inlineable + * and visible to the compiler. For example gs_free_error attribute only + * frees the error after checking that it's not %NULL. So, in many cases + * the compiler knows that gs_free_error has no effect and can optimize + * the call away. By making g_clear_error() inlineable, we give the compiler + * more chance to detect that the function actually has no effect. */ +#define g_clear_error(ptr) nm_clear_error(ptr) + static inline gboolean nm_clear_g_source (guint *id) { diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index 49037ed7b4..472a4c484f 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -2282,6 +2282,35 @@ nm_utils_hash_keys_to_array (GHashTable *hash, return keys; } +gboolean +nm_utils_hashtable_same_keys (const GHashTable *a, + const GHashTable *b) +{ + GHashTableIter h; + const char *k; + + if (a == b) + return TRUE; + if (!a || !b) + return FALSE; + if (g_hash_table_size ((GHashTable *) a) != g_hash_table_size ((GHashTable *) b)) + return FALSE; + + g_hash_table_iter_init (&h, (GHashTable *) a); + while (g_hash_table_iter_next (&h, (gpointer) &k, NULL)) { + if (!g_hash_table_contains ((GHashTable *) b, k)) + return FALSE; + } + +#if NM_MORE_ASSERTS > 5 + g_hash_table_iter_init (&h, (GHashTable *) b); + while (g_hash_table_iter_next (&h, (gpointer) &k, NULL)) + nm_assert (g_hash_table_contains ((GHashTable *) a, k)); +#endif + + return TRUE; +} + char ** nm_utils_strv_make_deep_copied (const char **strv) { diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index a8f2966b38..e65d1be683 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -966,6 +966,9 @@ nm_utils_strdict_get_keys (const GHashTable *hash, out_length); } +gboolean nm_utils_hashtable_same_keys (const GHashTable *a, + const GHashTable *b); + char **nm_utils_strv_make_deep_copied (const char **strv); char **nm_utils_strv_make_deep_copied_n (const char **strv, gsize len); |