diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-12 12:34:31 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-15 23:47:14 +0100 |
commit | dec3a7e58d00bcc8b95a5b02a8c55d2da7a0b2ee (patch) | |
tree | 25092dd5b0c0d7711906c65bd2d28e3138a16b68 | |
parent | 6f3d7cbd22a281afc8f374a883a7c3281f890622 (diff) | |
download | NetworkManager-dec3a7e58d00bcc8b95a5b02a8c55d2da7a0b2ee.tar.gz |
shared: add nm_streq() and nm_streq0() macro
Using strcmp() to test for string equality is a well known pattern.
However the inverse logic still is still hard to grasp especially in
more complex expressions.
nm_streq() should is an alternative to use strcmp(). And there is a counterpart
nm_streq0() which is based on g_strcmp0().
Kernel and systemd have also similar streq() macros.
https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00047.html
-rw-r--r-- | shared/nm-macros-internal.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index f3a3124d55..63f513847a 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -242,6 +242,11 @@ _NM_IN_STRSET_streq (const char *x, const char *s) /*****************************************************************************/ +#define nm_streq(s1, s2) (strcmp (s1, s2) == 0) +#define nm_streq0(s1, s2) (g_strcmp0 (s1, s2) == 0) + +/*****************************************************************************/ + #define NM_PRINT_FMT_QUOTED(cond, prefix, str, suffix, str_else) \ (cond) ? (prefix) : "", \ (cond) ? (str) : (str_else), \ |