diff --git a/daemon/control_ng_flags_parser.c b/daemon/control_ng_flags_parser.c index 0ce9ec7d2..2a2c2e65a 100644 --- a/daemon/control_ng_flags_parser.c +++ b/daemon/control_ng_flags_parser.c @@ -73,31 +73,8 @@ static bool get_key_val(str * key, str * val, str *in_out) return true; } -static inline int str_eq(const str *p, const char *q) -{ - int l = strlen(q); - if(p->len != l) - return 0; - if(memcmp(p->s, q, l)) - return 0; - return 1; -} - -static inline int str_prefix(const str *p, const char *q, str *out) -{ - int l = strlen(q); - if(p->len < l) - return 0; - if(memcmp(p->s, q, l)) - return 0; - *out = *p; - out->s += l; - out->len -= l; - return 1; -} - /* handle either "foo-bar" or "foo=bar" from flags */ -static int str_key_val_prefix(const str * p, const char * q, +static bool str_key_val_prefix(const str * p, const char * q, const str * v, str * out) { if(str_eq(p, q)) { @@ -105,17 +82,18 @@ static int str_key_val_prefix(const str * p, const char * q, return 0; *out = *v; - return 1; + return true; } - if(!str_prefix(p, q, out)) - return 0; + *out = *p; + if (str_shift_cmp(out, q)) + return false; if(out->len < 2) - return 0; + return false; if(*out->s != '-') - return 0; + return false; out->s++; out->len--; - return 1; + return true; } /** diff --git a/lib/str.h b/lib/str.h index e92f3114d..3e98cf868 100644 --- a/lib/str.h +++ b/lib/str.h @@ -68,6 +68,10 @@ __attribute__((nonnull(1, 2))) ACCESS(read_only, 1) ACCESS(read_only, 2) INLINE int str_cmp(const str *a, const char *b); +__attribute__((nonnull(1, 2))) +ACCESS(read_only, 1) +ACCESS(read_only, 2) +INLINE bool str_eq(const str *a, const char *b); /* compares a str to a non-null-terminated string */ __attribute__((nonnull(1, 2))) ACCESS(read_only, 1) @@ -255,6 +259,9 @@ INLINE int str_cmp_len(const str *a, const char *b, size_t l) { INLINE int str_cmp(const str *a, const char *b) { return str_cmp_len(a, b, strlen(b)); } +INLINE bool str_eq(const str *a, const char *b) { + return str_cmp(a, b) == 0; +} INLINE int str_cmp_str(const str *a, const str *b) { if (a->len < b->len) return -1;