summaryrefslogtreecommitdiff
path: root/src/gpm-brightness.c
diff options
context:
space:
mode:
authorRoy Zhang <[email protected]>2015-04-01 14:46:50 +0800
committerStefano Karapetsas <[email protected]>2015-04-04 16:13:11 +0200
commit6be85ada75e3b233e6a094654cd5b1b45dc87c18 (patch)
tree38a8fcb07e4e61c014e4e876232520ae1b3f9200 /src/gpm-brightness.c
parentedccac71064a0781f47af3563a2cd9d78d4de16f (diff)
downloadmate-power-manager-6be85ada75e3b233e6a094654cd5b1b45dc87c18.tar.bz2
mate-power-manager-6be85ada75e3b233e6a094654cd5b1b45dc87c18.tar.xz
Remove obsolete egg-string code
Closes https://github.com/mate-desktop/mate-power-manager/pull/141
Diffstat (limited to 'src/gpm-brightness.c')
-rw-r--r--src/gpm-brightness.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/gpm-brightness.c b/src/gpm-brightness.c
index e92b6e4..acfffc2 100644
--- a/src/gpm-brightness.c
+++ b/src/gpm-brightness.c
@@ -42,7 +42,6 @@
#include "egg-discrete.h"
#include "egg-debug.h"
-#include "egg-string.h"
#include "gpm-brightness.h"
#include "gpm-common.h"
@@ -89,6 +88,35 @@ static guint signals [LAST_SIGNAL] = { 0 };
static gpointer gpm_brightness_object = NULL;
/**
+ * gpm_brightness_helper_strtoint:
+ * @text: The text to be converted
+ * @value: The return numeric return value
+ *
+ * Convert a string to a signed integer value in a safe way.
+ *
+ * Return value: %TRUE if the string was converted correctly
+ **/
+static gboolean
+gpm_brightness_helper_strtoint (const gchar *text, gint *value)
+{
+ gchar *endptr = NULL;
+ gint64 value_raw;
+
+ if (text == NULL)
+ return FALSE;
+
+ value_raw = g_ascii_strtoll (text, &endptr, 10);
+
+ if (endptr == text)
+ return FALSE;
+ if (errno == ERANGE || value_raw > G_MAXINT || value_raw < G_MININT)
+ return FALSE;
+
+ *value = (gint) value_raw;
+ return TRUE;
+}
+
+/**
* gpm_brightness_helper_get_value:
**/
static gint
@@ -113,7 +141,7 @@ gpm_brightness_helper_get_value (const gchar *argument)
egg_debug ("executing %s retval: %i", command, exit_status);
/* parse for a number */
- ret = egg_strtoint (stdout_data, &value);
+ ret = gpm_brightness_helper_strtoint (stdout_data, &value);
if (!ret)
goto out;
out: