add str_cmp()

This commit is contained in:
Alfred E. Heggestad 2012-09-05 12:48:42 +00:00
parent 4580fb1011
commit 210be97be3
2 changed files with 19 additions and 0 deletions

View file

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

View file

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