summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-03-12 12:27:58 +0100
committerThomas Haller <thaller@redhat.com>2014-04-10 16:27:02 +0200
commit0a9cfb48ff7652d40d27f117269bf07ce17cfb0e (patch)
tree5b28a9923f0182c2e7c4917cfb6906f8337b181f
parent2b3ef7664f02651436ad73e07bd8fb0294414361 (diff)
downloadNetworkManager-0a9cfb48ff7652d40d27f117269bf07ce17cfb0e.tar.gz
platform: add nm_platform_sysctl_get_int_checked() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/platform/nm-platform.c23
-rw-r--r--src/platform/nm-platform.h1
2 files changed, 23 insertions, 1 deletions
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
@@ -280,6 +280,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);