From: Pietro Cerutti Date: Mon, 21 Nov 2016 14:09:57 +0000 (+0000) Subject: lib: Implement mutt_strchrnul() X-Git-Tag: neomutt-20161126~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68e63424c863282abc9e65e21e35ca88e03711ec;p=neomutt lib: Implement mutt_strchrnul() Closes: #253 --- diff --git a/lib.c b/lib.c index 6a93d430b..86d12f615 100644 --- a/lib.c +++ b/lib.c @@ -309,6 +309,25 @@ char *mutt_strlower (char *s) return (s); } +/** + * mutt_strchrnul - find first occurrence of character in string + * @param s Haystack. + * @param c Needle. + * @return Pointer to the first occurrence if found or to the NULL character. + * + * This function is like GNU's strchrnul, which is similar to the standard + * strchr function: it looks for the c character in the NULL-terminated string + * s and returns a pointer to its location. If c is not in s, instead of + * returning NULL like its standard counterpart, this function returns a + * pointer to the terminating NULL character. + */ +const char *mutt_strchrnul(const char *s, char c) +{ + for (; *s && (*s != c); s++) + ; + return s; +} + void mutt_unlink (const char *s) { int fd; diff --git a/lib.h b/lib.h index 2bae30e21..109f5dd6c 100644 --- a/lib.h +++ b/lib.h @@ -171,6 +171,7 @@ char *mutt_concat_path (char *, const char *, const char *, size_t); char *mutt_read_line (char *, size_t *, FILE *, int *, int); char *mutt_skip_whitespace (char *); char *mutt_strlower (char *); +const char *mutt_strchrnul (const char *, char); char *mutt_substrcpy (char *, const char *, const char *, size_t); char *mutt_substrdup (const char *, const char *); char *safe_strcat (char *, size_t, const char *);