diff options
Diffstat (limited to 'misc/bstr.c')
-rw-r--r-- | misc/bstr.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/misc/bstr.c b/misc/bstr.c index 379b2ed22d..baf736058e 100644 --- a/misc/bstr.c +++ b/misc/bstr.c @@ -63,18 +63,25 @@ int bstrcasecmp(struct bstr str1, struct bstr str2) int bstrchr(struct bstr str, int c) { - for (int i = 0; i < str.len; i++) - if (str.start[i] == c) - return i; - return -1; + if (!str.len) + return -1; + unsigned char *pos = memchr(str.start, c, str.len); + return pos ? pos - str.start : -1; } int bstrrchr(struct bstr str, int c) { + if (!str.len) + return -1; +#if HAVE_MEMRCHR + unsigned char *pos = memrchr(str.start, c, str.len); + return pos ? pos - str.start : -1; +#else for (int i = str.len - 1; i >= 0; i--) if (str.start[i] == c) return i; return -1; +#endif } int bstrcspn(struct bstr str, const char *reject) @@ -364,7 +371,7 @@ void bstr_xappend(void *talloc_ctx, bstr *s, bstr append) if (!append.len) return; resize_append(talloc_ctx, s, append.len + 1); - memcpy(s->start + s->len, append.start, append.len); + memmove(s->start + s->len, append.start, append.len); s->len += append.len; s->start[s->len] = '\0'; } |