mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 00:30:09 +01:00
platform: add nm_platform_sysctl_get_int_checked() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
2b3ef7664f
commit
0a9cfb48ff
2 changed files with 23 additions and 1 deletions
|
|
@ -279,6 +279,27 @@ nm_platform_sysctl_get (const char *path)
|
|||
*/
|
||||
gint32
|
||||
nm_platform_sysctl_get_int32 (const char *path, gint32 fallback)
|
||||
{
|
||||
return nm_platform_sysctl_get_int_checked (path, 10, G_MININT32, G_MAXINT32, fallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_sysctl_get_int_checked:
|
||||
* @path: Absolute path to sysctl
|
||||
* @base: base of numeric conversion
|
||||
* @min: minimal value that is still valid
|
||||
* @max: maximal value that is still valid
|
||||
* @fallback: default value, if the content of path could not be read
|
||||
* as valid integer.
|
||||
*
|
||||
* Returns: contents of the sysctl file parsed as s64 integer, or
|
||||
* @fallback on error. On error, %errno will be set to a non-zero
|
||||
* value. On success, %errno will be set to zero. The returned value
|
||||
* will always be in the range between @min and @max
|
||||
* (inclusive) or @fallback.
|
||||
*/
|
||||
gint64
|
||||
nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gint64 max, gint64 fallback)
|
||||
{
|
||||
char *value = NULL;
|
||||
gint32 ret;
|
||||
|
|
@ -293,7 +314,7 @@ nm_platform_sysctl_get_int32 (const char *path, gint32 fallback)
|
|||
return fallback;
|
||||
}
|
||||
|
||||
ret = nm_utils_ascii_str_to_int64 (value, 10, G_MININT32, G_MAXINT32, fallback);
|
||||
ret = nm_utils_ascii_str_to_int64 (value, base, min, max, fallback);
|
||||
g_free (value);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -417,6 +417,7 @@ void nm_platform_query_devices (void);
|
|||
gboolean nm_platform_sysctl_set (const char *path, const char *value);
|
||||
char *nm_platform_sysctl_get (const char *path);
|
||||
gint32 nm_platform_sysctl_get_int32 (const char *path, gint32 fallback);
|
||||
gint64 nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gint64 max, gint64 fallback);
|
||||
|
||||
GArray *nm_platform_link_get_all (void);
|
||||
gboolean nm_platform_dummy_add (const char *name);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue