From 6be85ada75e3b233e6a094654cd5b1b45dc87c18 Mon Sep 17 00:00:00 2001 From: Roy Zhang Date: Wed, 1 Apr 2015 14:46:50 +0800 Subject: Remove obsolete egg-string code Closes https://github.com/mate-desktop/mate-power-manager/pull/141 --- src/Makefile.am | 2 - src/egg-string.c | 453 --------------------------------------------------- src/egg-string.h | 47 ------ src/gpm-brightness.c | 32 +++- 4 files changed, 30 insertions(+), 504 deletions(-) delete mode 100644 src/egg-string.c delete mode 100644 src/egg-string.h diff --git a/src/Makefile.am b/src/Makefile.am index ddbb6ed..907ff5c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -76,8 +76,6 @@ libgpmshared_a_SOURCES = \ egg-dbus-monitor.c \ egg-discrete.h \ egg-discrete.c \ - egg-string.h \ - egg-string.c \ egg-console-kit.h \ egg-console-kit.c \ gpm-common.h \ diff --git a/src/egg-string.c b/src/egg-string.c deleted file mode 100644 index 204e6d9..0000000 --- a/src/egg-string.c +++ /dev/null @@ -1,453 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2007-2008 Richard Hughes - * - * Licensed under the GNU General Public License Version 2 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * SECTION:pk-common - * @short_description: Common utility functions for PackageKit - * - * This file contains functions that may be useful. - */ - -#include "config.h" - -#include -#include - -#include -#include -#include -#include - -#ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ - -#include - -#include "egg-debug.h" -#include "egg-string.h" - -/** - * egg_strtoint: - * @text: The text the convert - * @value: The return numeric return value - * - * Converts a string into a signed integer value in a safe way. - * - * Return value: %TRUE if the string was converted correctly - **/ -gboolean -egg_strtoint (const gchar *text, gint *value) -{ - gchar *endptr = NULL; - gint64 value_raw; - - /* invalid */ - if (text == NULL) - return FALSE; - - /* parse */ - value_raw = g_ascii_strtoll (text, &endptr, 10); - - /* parsing error */ - if (endptr == text) - return FALSE; - - /* out of range */ - if (value_raw > G_MAXINT || value_raw < G_MININT) - return FALSE; - - /* cast back down to value */ - *value = (gint) value_raw; - return TRUE; -} - -/** - * egg_strtouint: - * @text: The text the convert - * @value: The return numeric return value - * - * Converts a string into a unsigned integer value in a safe way. - * - * Return value: %TRUE if the string was converted correctly - **/ -gboolean -egg_strtouint (const gchar *text, guint *value) -{ - gchar *endptr = NULL; - guint64 value_raw; - - /* invalid */ - if (text == NULL) - return FALSE; - - /* parse */ - value_raw = g_ascii_strtoull (text, &endptr, 10); - - /* parsing error */ - if (endptr == text) - return FALSE; - - /* out of range */ - if (value_raw > G_MAXINT) - return FALSE; - - /* cast back down to value */ - *value = (guint) value_raw; - return TRUE; -} - -/** - * egg_strzero: - * @text: The text to check - * - * This function is a much safer way of doing "if (strlen (text) == 0))" - * as it does not rely on text being NULL terminated. It's also much - * quicker as it only checks the first byte rather than scanning the whole - * string just to verify it's not zero length. - * - * Return value: %TRUE if the string was converted correctly - **/ -gboolean -egg_strzero (const gchar *text) -{ - if (text == NULL) - return TRUE; - if (text[0] == '\0') - return TRUE; - return FALSE; -} - -/** - * egg_strlen: - * @text: The text to check - * @len: The maximum length of the string - * - * This function is a much safer way of doing strlen as it checks for NULL and - * a stupidly long string. - * - * Return value: the length of the string, or len if the string is too long. - **/ -guint -egg_strlen (const gchar *text, guint len) -{ - guint i; - - /* common case */ - if (text == NULL || text[0] == '\0') - return 0; - - /* only count up to len */ - for (i=1; i - * - * Licensed under the GNU General Public License Version 2 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __EGG_STRING_H -#define __EGG_STRING_H - -#include - -G_BEGIN_DECLS - -guint egg_strlen (const gchar *text, - guint len) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strzero (const gchar *text) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strvequal (gchar **id1, - gchar **id2) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strtoint (const gchar *text, - gint *value); -gboolean egg_strtouint (const gchar *text, - guint *value); -gchar *egg_strreplace (const gchar *text, - const gchar *find, - const gchar *replace); - -G_END_DECLS - -#endif /* __EGG_STRING_H */ 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" @@ -88,6 +87,35 @@ G_DEFINE_TYPE (GpmBrightness, gpm_brightness, G_TYPE_OBJECT) 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: **/ @@ -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: -- cgit v1.2.1