diff options
author | Sheldon Demario <sheldon.demario@openbossa.org> | 2011-02-24 17:38:25 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2011-02-24 18:33:22 -0300 |
commit | 7aff2ceaf7a48a12763bd08e861d441c938b945a (patch) | |
tree | 5657fc41795e45b3c29f2ac6b4fe5df88b0eb86e /attrib | |
parent | a2e31571167744a65899688cf5d755f11c5e9442 (diff) | |
download | bluez-7aff2ceaf7a48a12763bd08e861d441c938b945a.tar.gz |
Create a helper function to deal with handles on interactive gatttool
Diffstat (limited to 'attrib')
-rw-r--r-- | attrib/interactive.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/attrib/interactive.c b/attrib/interactive.c index 7cc03bcf..7b18e907 100644 --- a/attrib/interactive.c +++ b/attrib/interactive.c @@ -238,6 +238,19 @@ static void cmd_primary(int argcp, char **argvp) gatt_discover_primary(attrib, &uuid, primary_by_uuid_cb, NULL); } +static int strtohandle(const char *src) +{ + char *e; + int dst; + + errno = 0; + dst = strtoll(src, &e, 16); + if (errno != 0 || *e != '\0') + return -EINVAL; + + return dst; +} + static void cmd_char(int argcp, char **argvp) { int start = 0x0001; @@ -249,28 +262,22 @@ static void cmd_char(int argcp, char **argvp) } if (argcp > 1) { - char *e; - - start = strtoll(argvp[1], &e, 16); - if (errno != 0 || *e != '\0') { + start = strtohandle(argvp[1]); + if (start < 0) { printf("Invalid start handle: %s\n", argvp[1]); return; } } if (argcp > 2) { - char *e; - - end = strtoll(argvp[2], &e, 16); - if (errno != 0 || *e != '\0') { + end = strtohandle(argvp[2]); + if (end < 0) { printf("Invalid end handle: %s\n", argvp[2]); return; } } gatt_discover_char(attrib, start, end, char_cb, NULL); - - return; } static struct { |