From c46d912071dd8fad6c1ed532cbef26db34a639e9 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 7 Dec 2022 11:17:32 -0800 Subject: Call strrchr() instead of hand coding a custom version Also correct comments on hand-coded custom strcmp() replacements Signed-off-by: Alan Coopersmith --- include.c | 7 ++----- main.c | 4 ++-- parse.c | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include.c b/include.c index b638011..2a4d659 100644 --- a/include.c +++ b/include.c @@ -273,12 +273,9 @@ find_full_inc_path(const char *file, const char *include, int type) * in the directory of the file being parsed. */ if ((type == INCLUDEDOT) || (type == INCLUDENEXTDOT)) { - const char *p; + const char *p = strrchr(file, '/'); - for (p = file + strlen(file); p > file; p--) - if (*p == '/') - break; - if (p == file) { + if ((p == NULL) || (p == file)) { strcpy(path, include); } else { diff --git a/main.c b/main.c index 9ebe101..2ede1bd 100644 --- a/main.c +++ b/main.c @@ -728,9 +728,9 @@ base_name(const char *in_file) if (file == NULL) fatalerr("strdup() failure in %s()\n", __func__); - for (p = file + strlen(file); p > file && *p != '.'; p--); + p = strrchr(file, '.'); - if (*p == '.') + if (p != NULL) *p = '\0'; return (file); } diff --git a/parse.c b/parse.c index 5915a81..92431ea 100644 --- a/parse.c +++ b/parse.c @@ -336,7 +336,7 @@ define2(const char *name, const char *val, struct inclist *file) const char *s2; int middle = (first + last) / 2; - /* Fast inline strchr() */ + /* Fast inline strcmp() */ s1 = name; s2 = file->i_defs[middle]->s_name; while (*s1++ == *s2++) @@ -427,7 +427,7 @@ slookup(const char *symbol, struct inclist *file) const char *s2; int middle = (first + last) / 2; - /* Fast inline strchr() */ + /* Fast inline strcmp() */ s1 = symbol; s2 = file->i_defs[middle]->s_name; while (*s1++ == *s2++) -- cgit v1.2.1