diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index b8d1d8a1f1..6d0436cd95 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -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; } diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 356af1f940..3128ba5fb7 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -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);