From e25579e5a5774f9d08cbfbaf622b4a7cc6213438 Mon Sep 17 00:00:00 2001 From: Danny Auble <da@schedmd.com> Date: Tue, 4 Apr 2017 14:46:32 -0600 Subject: [PATCH] Add xstrrchr in preparation to remove calls to rindex. --- src/common/slurm_xlator.h | 1 + src/common/xstring.c | 7 +++++++ src/common/xstring.h | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/common/slurm_xlator.h b/src/common/slurm_xlator.h index de394afb241..2297cc785d1 100644 --- a/src/common/slurm_xlator.h +++ b/src/common/slurm_xlator.h @@ -321,6 +321,7 @@ #define xstring_is_whitespace slurm_xstring_is_whitespace #define xstrtolower slurm_xstrtolower #define xstrchr slurm_xstrchr +#define xstrrchr slurm_xstrrchr #define xstrcmp slurm_xstrcmp #define xstrcasecmp slurm_xstrcasecmp #define xstrcasestr slurm_xstrcasestr diff --git a/src/common/xstring.c b/src/common/xstring.c index 2ce70a79d7f..60718a51dab 100644 --- a/src/common/xstring.c +++ b/src/common/xstring.c @@ -87,6 +87,7 @@ strong_alias(xshort_hostname, slurm_xshort_hostname); strong_alias(xstring_is_whitespace, slurm_xstring_is_whitespace); strong_alias(xstrtolower, slurm_xstrtolower); strong_alias(xstrchr, slurm_xstrchr); +strong_alias(xstrrchr, slurm_xstrrchr); strong_alias(xstrcmp, slurm_xstrcmp); strong_alias(xstrcasecmp, slurm_xstrcasecmp); strong_alias(xstrcasestr, slurm_xstrcasestr); @@ -554,6 +555,12 @@ char *xstrchr(const char *s1, int c) return s1 ? strchr(s1, c) : NULL; } +/* safe strrchr */ +char *xstrrchr(const char *s1, int c) +{ + return s1 ? strrchr(s1, c) : NULL; +} + /* safe strcmp */ int xstrcmp(const char *s1, const char *s2) { diff --git a/src/common/xstring.h b/src/common/xstring.h index d497c2d5893..1dd4942f791 100644 --- a/src/common/xstring.h +++ b/src/common/xstring.h @@ -184,6 +184,11 @@ char *xstrtolower(char *str); */ char *xstrchr(const char *s1, int c); +/* + * safe strrchr (handles NULL values) + */ +char *xstrrchr(const char *s1, int c); + /* * safe strcmp (handles NULL values) */ -- GitLab