diff --git a/include/re_fmt.h b/include/re_fmt.h index 8fe2b73..2f942ff 100644 --- a/include/re_fmt.h +++ b/include/re_fmt.h @@ -105,6 +105,7 @@ uint8_t ch_hex(char ch); int str_hex(uint8_t *hex, size_t len, const char *str); void str_ncpy(char *dst, const char *src, size_t n); int str_dup(char **dst, const char *src); +int str_cmp(const char *s1, const char *s2); int str_casecmp(const char *s1, const char *s2); size_t str_len(const char *s); const char *str_error(int errnum, char *buf, size_t sz); diff --git a/src/fmt/str.c b/src/fmt/str.c index 514ec2a..37981af 100644 --- a/src/fmt/str.c +++ b/src/fmt/str.c @@ -94,6 +94,24 @@ int str_dup(char **dst, const char *src) * @return an integer less than, equal to, or greater than zero if s1 is found * respectively, to be less than, to match, or be greater than s2 */ +int str_cmp(const char *s1, const char *s2) +{ + if (!s1 || !s2) + return 1; + + return strcmp(s1, s2); +} + + +/** + * Compare two 0-terminated strings, ignoring case + * + * @param s1 First string + * @param s2 Second string + * + * @return an integer less than, equal to, or greater than zero if s1 is found + * respectively, to be less than, to match, or be greater than s2 + */ int str_casecmp(const char *s1, const char *s2) { /* Same strings -> equal */