diff options
author | Thomas Haller <thaller@redhat.com> | 2018-09-10 14:54:13 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-09-12 10:13:11 +0200 |
commit | 96954fdaf5a8658dfe8fa0fa9b25e5fb7a8d0469 (patch) | |
tree | 826be1a1b68b958c87b7ba0766c3a5b0abd5e2d5 /shared | |
parent | 21bac1da14432a81c862baa4dc79d31e9f02be22 (diff) |
shared: add nm_errno() and nm_utils_error_set_errno() helper
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-utils/nm-shared-utils.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index b3099738f..5125bd3d8 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -480,6 +480,19 @@ _nm_g_slice_free_fcn_define (16) /*****************************************************************************/ +static inline int +nm_errno (int errsv) +{ + /* several API returns negative errno values as errors. Normalize + * negative values to positive values. + * + * As a special case, map G_MININT to G_MAXINT. If you care about the + * distinction, then check for G_MININT before. */ + return errsv >= 0 + ? errsv + : ((errsv == G_MININT) ? G_MAXINT : -errsv); +} + /** * NMUtilsError: * @NM_UTILS_ERROR_UNKNOWN: unknown or unclassified error @@ -542,6 +555,14 @@ nm_utils_error_set_literal (GError **error, int error_code, const char *literal) #define nm_utils_error_set(error, error_code, ...) \ g_set_error ((error), NM_UTILS_ERROR, error_code, __VA_ARGS__) +#define nm_utils_error_set_errno(error, errsv, fmt, ...) \ + g_set_error ((error), \ + NM_UTILS_ERROR, \ + NM_UTILS_ERROR_UNKNOWN, \ + fmt, \ + ##__VA_ARGS__, \ + g_strerror (nm_errno (errsv))) + /*****************************************************************************/ gboolean nm_g_object_set_property (GObject *object, |