Skip to content
Snippets Groups Projects
Commit 594867ac authored by Morris Jette's avatar Morris Jette
Browse files

Define safe strncmp() (for NULL args)

parent 59586758
No related branches found
No related tags found
No related merge requests found
......@@ -565,12 +565,28 @@ int xstrcmp(const char *s1, const char *s2)
{
if (!s1 && !s2)
return 0;
else if ((s1 && !s2) || (!s1 && s2))
else if (!s1)
return -1;
else if (!s2)
return 1;
else
return strcmp(s1, s2);
}
/* safe strncmp */
int xstrncmp(const char *s1, const char *s2, size_t n)
{
if (!s1 && !s2)
return 0;
else if (!s1)
return -1;
else if (!s2)
return 1;
else
return strncmp(s1, s2, n);
}
/* safe strcasecmp */
int xstrcasecmp(const char *s1, const char *s2)
{
......
......@@ -185,6 +185,11 @@ char *xstrchr(const char *s1, int c);
*/
int xstrcmp(const char *s1, const char *s2);
/*
* safe strncmp (handles NULL values)
*/
int xstrncmp(const char *s1, const char *s2, size_t n);
/*
* safe strcasecmp (handles NULL values)
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment