From: Ralph Corderoy Date: Tue, 18 Oct 2016 16:05:24 +0000 (+0100) Subject: Add TrimSuffixC(char *s, int c). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/80ca91c25c3eb4f96f6c3842c1c14053ae69e80a?hp=122129da83e4e9ec2d0363ef9f60d32491af2629 Add TrimSuffixC(char *s, int c). TrimSuffixC deletes c from the end of non-NULL string s if it's present, shortening s by 1. Only one instance of c is removed. --- diff --git a/h/utils.h b/h/utils.h index 9b659501..edb2ab03 100644 --- a/h/utils.h +++ b/h/utils.h @@ -63,6 +63,8 @@ char *find_str (const char [], size_t, const char *); char *rfind_str (const char [], size_t, const char *); char *nmh_strcasestr (const char *, const char *); +void TrimSuffixC(char *s, int c); + /* * See if a string contains 8 bit characters (use isascii() for the test). * Arguments include: diff --git a/sbr/utils.c b/sbr/utils.c index c9769fb0..d9b903e7 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -360,6 +360,19 @@ nmh_strcasestr (const char *s1, const char *s2) { } +/* TrimSuffixC deletes c from the end of non-NULL string s if it's + * present, shortening s by 1. Only one instance of c is removed. */ +void TrimSuffixC(char *s, int c) +{ + if (!*s) + return; + + s += strlen(s) - 1; + if (*s == c) + *s = '\0'; +} + + int nmh_init(const char *argv0, int read_context) { if (! setlocale(LC_ALL, "")) {