diff options
author | Thomas Haller <thaller@redhat.com> | 2020-05-05 08:23:00 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-05-06 08:21:56 +0200 |
commit | 701d596be7f10c6fcbd88059223e2193389119e7 (patch) | |
tree | 215f0dd440d5bc0e6bd1c64ea786860df81c612c | |
parent | 4ea602a3b20750c7f4e81772faee39fb3ca88a6a (diff) | |
download | NetworkManager-701d596be7f10c6fcbd88059223e2193389119e7.tar.gz |
shared: add nm_g_error_matches() helper
-rw-r--r-- | shared/nm-glib-aux/nm-shared-utils.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index d5990c2d54..36a770bdb9 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -926,6 +926,21 @@ _nm_g_slice_free_fcn_define (32) /*****************************************************************************/ +/* Like g_error_matches() however: + * - as macro it is always inlined. + * - the @domain is usually a error quark getter function that cannot + * be inlined. This macro calls the getter only if there is an error (lazy). + * - accept a list of allowed codes, instead of only one. + */ +#define nm_g_error_matches(error, err_domain, ...) \ + ({ \ + const GError *const _error = (error); \ + \ + _error \ + && _error->domain == (err_domain) \ + && NM_IN_SET (_error->code, __VA_ARGS__); \ + }) + static inline void nm_g_set_error_take (GError **error, GError *error_take) { |