Sharpen test for bus/device number

This commit is contained in:
stefanrueger
2025-10-23 13:39:40 +02:00
parent f3009e7348
commit a6553e80d3

View File

@@ -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;