mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 21:00:07 +01:00
shared: add nm_errno() and nm_utils_error_set_errno() helper
This commit is contained in:
parent
2a45c32e8c
commit
4186ddb58b
1 changed files with 21 additions and 0 deletions
|
|
@ -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:
|
* NMUtilsError:
|
||||||
* @NM_UTILS_ERROR_UNKNOWN: unknown or unclassified error
|
* @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, ...) \
|
#define nm_utils_error_set(error, error_code, ...) \
|
||||||
g_set_error ((error), NM_UTILS_ERROR, error_code, __VA_ARGS__)
|
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,
|
gboolean nm_g_object_set_property (GObject *object,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue