[gnome-bluetooth] lib: Simplify bluetooth_verify_address()
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] lib: Simplify bluetooth_verify_address()
- Date: Wed, 29 Jun 2011 14:46:57 +0000 (UTC)
commit b28825f9019fcd0b4713700a0227909db863d8ae
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jun 29 12:31:50 2011 +0100
lib: Simplify bluetooth_verify_address()
lib/bluetooth-client.c | 25 ++++++++-----------------
1 files changed, 8 insertions(+), 17 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index f347fe4..54f32b9 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -171,8 +171,6 @@ const gchar *bluetooth_type_to_string(BluetoothType type)
gboolean
bluetooth_verify_address (const char *bdaddr)
{
- gboolean retval = TRUE;
- char **elems;
guint i;
g_return_val_if_fail (bdaddr != NULL, FALSE);
@@ -180,24 +178,17 @@ bluetooth_verify_address (const char *bdaddr)
if (strlen (bdaddr) != 17)
return FALSE;
- elems = g_strsplit (bdaddr, ":", -1);
- if (elems == NULL)
- return FALSE;
- if (g_strv_length (elems) != 6) {
- g_strfreev (elems);
- return FALSE;
- }
- for (i = 0; i < 6; i++) {
- if (strlen (elems[i]) != 2 ||
- g_ascii_isxdigit (elems[i][0]) == FALSE ||
- g_ascii_isxdigit (elems[i][1]) == FALSE) {
- retval = FALSE;
- break;
+ for (i = 0; i < 17; i++) {
+ if (((i + 1) % 3) == 0) {
+ if (bdaddr[i] != ':')
+ return FALSE;
+ continue;
}
+ if (g_ascii_isxdigit (bdaddr[i]) == FALSE)
+ return FALSE;
}
- g_strfreev (elems);
- return retval;
+ return TRUE;
}
guint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]