mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 20:08:10 +01:00
util: add strcmp_null, a strcmp that handles NULL parameters
Add strcmp_null, a strcmp that handles NULL strings; in strcmp terms a NULL string is considered to be less than a non-NULL string.
This commit is contained in:
parent
23b8ed610a
commit
bcb695a716
2 changed files with 18 additions and 0 deletions
|
@ -222,6 +222,19 @@ parse_boolean_term (void *ctx, const char *str,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
strcmp_null (const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
if (s1 && s2)
|
||||||
|
return strcmp (s1, s2);
|
||||||
|
else if (! s1 && ! s2)
|
||||||
|
return 0;
|
||||||
|
else if (s1)
|
||||||
|
return 1; /* s1 (non-NULL) is greater than s2 (NULL) */
|
||||||
|
else
|
||||||
|
return -1; /* s1 (NULL) is less than s2 (non-NULL) */
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
strcase_equal (const void *a, const void *b)
|
strcase_equal (const void *a, const void *b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,6 +64,11 @@ int
|
||||||
parse_boolean_term (void *ctx, const char *str,
|
parse_boolean_term (void *ctx, const char *str,
|
||||||
char **prefix_out, char **term_out);
|
char **prefix_out, char **term_out);
|
||||||
|
|
||||||
|
/* strcmp that handles NULL strings; in strcmp terms a NULL string is
|
||||||
|
* considered to be less than a non-NULL string.
|
||||||
|
*/
|
||||||
|
int strcmp_null (const char *s1, const char *s2);
|
||||||
|
|
||||||
/* GLib GEqualFunc compatible strcasecmp wrapper */
|
/* GLib GEqualFunc compatible strcasecmp wrapper */
|
||||||
int strcase_equal (const void *a, const void *b);
|
int strcase_equal (const void *a, const void *b);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue