mirror of
https://github.com/avrdudes/avrdude.git
synced 2026-06-02 09:46:34 +03:00
Provide str_busdev_eq() function
This commit is contained in:
@@ -1678,6 +1678,7 @@ extern "C" {
|
||||
int str_casematched_by(const char *string, const char *pattern);
|
||||
int str_is_pattern(const char *str);
|
||||
int str_is_in_list(const char *s, const char **l, size_t nl, int (*f)(const char *, const char *));
|
||||
int str_busdev_eq(const char *s, const char *t);
|
||||
char *str_sprintf(const char *fmt, ...)
|
||||
#if defined(__GNUC__) // Ask gcc to check whether format and parameters match
|
||||
__attribute__((format(printf, 1, 2)))
|
||||
|
||||
@@ -241,6 +241,23 @@ int str_is_in_list(const char *s, const char **l, size_t nl, int (*f)(const char
|
||||
return 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(strtoull(s, NULL, 10) == strtoull(t, NULL, 10))
|
||||
return 1;
|
||||
|
||||
int len = 0; // Length of strings up to optional colon
|
||||
while(s[len] && s[len] != ':' && t[len] && t[len] != ':')
|
||||
len++;
|
||||
|
||||
// Different length means strings are not the same
|
||||
if((s[len] && s[len] != ':') || (t[len] && t[len] != ':'))
|
||||
return 0;
|
||||
|
||||
return !strncmp(s, t, len);
|
||||
}
|
||||
|
||||
// Return a mmt_malloc'd string with the sprintf() result
|
||||
char *str_sprintf(const char *fmt, ...) {
|
||||
int size = 0;
|
||||
|
||||
Reference in New Issue
Block a user