shared: add nm_errno() and nm_utils_error_set_errno() helper

This commit is contained in:
Thomas Haller
2018-09-10 14:54:13 +02:00
parent 2a45c32e8c
commit 4186ddb58b

View File

@@ -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,