diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-06-21 21:18:00 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-06-21 21:18:00 +0000 |
commit | 3536636a5b1664499ee0ededd305b9bdc9ddeaa4 (patch) | |
tree | 6c2064ec0010546d771d62a0cea995740aa94241 /src/bluetooth.c | |
parent | 54d90a07ab77d86aeac4eed963071a07247eff18 (diff) |
Add common bachk() function
Diffstat (limited to 'src/bluetooth.c')
-rw-r--r-- | src/bluetooth.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/bluetooth.c b/src/bluetooth.c index f0f800a5..676e468e 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <errno.h> +#include <ctype.h> #include <stdarg.h> #include <stdlib.h> #include <malloc.h> @@ -110,6 +111,40 @@ int ba2oui(const bdaddr_t *ba, char *str) return sprintf(str, "%2.2X-%2.2X-%2.2X", b[0], b[1], b[2]); } +int bachk(const char *str) +{ + char tmp[18], *ptr = tmp; + + if (!str) + return -1; + + if (strlen(str) != 17) + return -1; + + memcpy(tmp, str, 18); + + while (*ptr) { + *ptr = toupper(*ptr); + if (*ptr < '0'|| (*ptr > '9' && *ptr < 'A') || *ptr > 'F') + return -1; + ptr++; + + *ptr = toupper(*ptr); + if (*ptr < '0'|| (*ptr > '9' && *ptr < 'A') || *ptr > 'F') + return -1; + ptr++; + + *ptr = toupper(*ptr); + if (*ptr == 0) + break; + if (*ptr != ':') + return -1; + ptr++; + } + + return 0; +} + int baprintf(const char *format, ...) { va_list ap; |