summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-06-24 10:45:44 +0200
committerThomas Haller <thaller@redhat.com>2014-10-30 15:27:32 +0100
commitf203fe8c3911b0255ca17e0b082b010b486908b9 (patch)
tree8ac8e59e82a2530dfe00338dc820894ceb12f937
parent937e8c1fd11571ad1841a0b5f522c30a47e98eaf (diff)
downloadNetworkManager-f203fe8c3911b0255ca17e0b082b010b486908b9.tar.gz
core: add utility function str_if_set()
Signed-off-by: Thomas Haller <thaller@redhat.com> (cherry picked from commit ed3f598f6355d7d4e3fac9cc8768e220a188efab)
-rw-r--r--src/NetworkManagerUtils.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index d47cdbaece..37e6641702 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -43,6 +43,22 @@ int nm_spawn_process (const char *args);
/* macro to return strlen() of a compile time string. */
#define STRLEN(str) ( sizeof ("" str) - 1 )
+/**
+ * str_if_set:
+ * @str: input string that will be returned if @str is not %NULL
+ * @fallback: if @str is %NULL, return @fallback instead
+ *
+ * This utility function is useful when printing a string to avoid passing
+ * %NULL. E.g. printf ("%s", str_if_set (get_string(), "(none)"));
+ *
+ * Returns: either @str or @fallback, depending on whether @str is %NULL.
+ */
+static inline const char *
+str_if_set (const char *str, const char *fallback)
+{
+ return str ? str : fallback;
+}
+
gboolean nm_match_spec_string (const GSList *specs, const char *string);
gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr);
gboolean nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels);