Skip to content
Snippets Groups Projects
Commit 076b9911 authored by Danny Auble's avatar Danny Auble
Browse files

Add xstrcmp xstrcasecmp and xstrchr

parent 31e8cd89
No related branches found
No related tags found
No related merge requests found
...@@ -317,6 +317,10 @@ ...@@ -317,6 +317,10 @@
#define xshort_hostname slurm_xshort_hostname #define xshort_hostname slurm_xshort_hostname
#define xstring_is_whitespace slurm_xstring_is_whitespace #define xstring_is_whitespace slurm_xstring_is_whitespace
#define xstrtolower slurm_xstrtolower #define xstrtolower slurm_xstrtolower
#define xstrchr slurm_xstrchr
#define xstrcmp slurm_xstrcmp
#define xstrcasecmp slurm_xstrcasecmp
/* slurm_protocol_defs.[ch] functions */ /* slurm_protocol_defs.[ch] functions */
#define preempt_mode_string slurm_preempt_mode_string #define preempt_mode_string slurm_preempt_mode_string
......
...@@ -93,6 +93,9 @@ strong_alias(xstrstrip, slurm_xstrstrip); ...@@ -93,6 +93,9 @@ strong_alias(xstrstrip, slurm_xstrstrip);
strong_alias(xshort_hostname, slurm_xshort_hostname); strong_alias(xshort_hostname, slurm_xshort_hostname);
strong_alias(xstring_is_whitespace, slurm_xstring_is_whitespace); strong_alias(xstring_is_whitespace, slurm_xstring_is_whitespace);
strong_alias(xstrtolower, slurm_xstrtolower); strong_alias(xstrtolower, slurm_xstrtolower);
strong_alias(xstrchr, slurm_xstrchr);
strong_alias(xstrcmp, slurm_xstrcmp);
strong_alias(xstrcasecmp, slurm_xstrcasecmp);
/* /*
* Ensure that a string has enough space to add 'needed' characters. * Ensure that a string has enough space to add 'needed' characters.
...@@ -553,6 +556,34 @@ char *xstrtolower(char *str) ...@@ -553,6 +556,34 @@ char *xstrtolower(char *str)
return str; return str;
} }
/* safe strchr */
char *xstrchr(const char *s1, int c)
{
return s1 ? strchr(s1, c) : NULL;
}
/* safe strcmp */
int xstrcmp(const char *s1, const char *s2)
{
if (!s1 && !s2)
return 0;
else if ((s1 && !s2) || (!s1 && s2))
return 1;
else
return strcmp(s1, s2);
}
/* safe strcasecmp */
int xstrcasecmp(const char *s1, const char *s2)
{
if (!s1 && !s2)
return 0;
else if ((s1 && !s2) || (!s1 && s2))
return 1;
else
return strcasecmp(s1, s2);
}
/* /*
* Give me a copy of the string as if it were printf. * Give me a copy of the string as if it were printf.
* This is stdarg-compatible routine, so vararg-compatible * This is stdarg-compatible routine, so vararg-compatible
......
...@@ -175,4 +175,19 @@ bool xstring_is_whitespace(const char *str); ...@@ -175,4 +175,19 @@ bool xstring_is_whitespace(const char *str);
*/ */
char *xstrtolower(char *str); char *xstrtolower(char *str);
/*
* safe strchr (handles NULL values)
*/
char *xstrchr(const char *s1, int c);
/*
* safe strcmp (handles NULL values)
*/
int xstrcmp(const char *s1, const char *s2);
/*
* safe strcasecmp (handles NULL values)
*/
int xstrcasecmp(const char *s1, const char *s2);
#endif /* !_XSTRING_H */ #endif /* !_XSTRING_H */
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