Browse Source

MT#55283 remove redundant code

Use str_cmp() to implement str_eq()

Use str_shift_cmp() in place of str_prefix()

Update return types to bool

Change-Id: If7927d957e20780408e77da1d04baffa082a6914
rfuchs/gh1842
Richard Fuchs 1 year ago
parent
commit
5e51cfde5b
2 changed files with 15 additions and 30 deletions
  1. +8
    -30
      daemon/control_ng_flags_parser.c
  2. +7
    -0
      lib/str.h

+ 8
- 30
daemon/control_ng_flags_parser.c View File

@ -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;
}
/**


+ 7
- 0
lib/str.h View File

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


Loading…
Cancel
Save