mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-06-02 09:46:34 +03:00
Sharpen test for bus/device number
This commit is contained in:
@@ -241,9 +241,19 @@ int str_is_in_list(const char *s, const char **l, size_t nl, int (*f)(const char
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Is the string a decimal bus/device number that ends in a colon or nul?
|
||||
static int is_busdev_num(const char *s) {
|
||||
const char *t = s;
|
||||
|
||||
while(*t >= '0' && *t <= '9')
|
||||
t++;
|
||||
|
||||
return t > s && (*t == ':' || *t == 0);
|
||||
}
|
||||
|
||||
// Do the two strings represent the same decimal number or are they the same up to a limiting colon?
|
||||
int str_busdev_eq(const char *s, const char *t) {
|
||||
if(*s >= '0' && *s <='9' && *t >= '0' && *t <='9') // Both look like a decimal number
|
||||
if(is_busdev_num(s) && is_busdev_num(t))
|
||||
if(strtoull(s, NULL, 10) == strtoull(t, NULL, 10))
|
||||
return 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user