Browse Source

dtc.h: add strends for suffix matching

Logic is similar to strcmp_suffix in <kernel>/drivers/of/property.c with
the exception that strends allows string length to equal suffix length.

Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
Message-Id: <20210504035944.8453-3-ilya.lipnitskiy@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
Ilya Lipnitskiy 4 years ago committed by David Gibson
parent
commit
09c6a6e887
  1. 10
      dtc.h

10
dtc.h

@ -86,6 +86,16 @@ static inline uint64_t dtb_ld64(const void *p) @@ -86,6 +86,16 @@ static inline uint64_t dtb_ld64(const void *p)
#define streq(a, b) (strcmp((a), (b)) == 0)
#define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
#define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
static inline bool strends(const char *str, const char *suffix)
{
unsigned int len, suffix_len;

len = strlen(str);
suffix_len = strlen(suffix);
if (len < suffix_len)
return false;
return streq(str + len - suffix_len, suffix);
}

#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))


Loading…
Cancel
Save