From f5df13f853cf4c0e529244dd40ab57c78a7d1bc6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 23 Sep 2008 20:48:08 +0200 Subject: Add prefixcmp() (stol^H^H^H^Hborrowed from git) This allows us to avoid the nasty repetition in strncmp(foo, bar, strlen(foo)). We'll miss out on the compiler optimizing strlen() into sizeof() - 1 for string literals for this; but we don't use this it for performance-critical functions anyways... --- src/utils.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 332c73587..f23f8c1fa 100644 --- a/src/utils.c +++ b/src/utils.c @@ -268,3 +268,13 @@ void xpthread_cond_destroy(pthread_cond_t *cond) if ((err = pthread_cond_destroy(cond))) FATAL("failed to destroy cond: %s\n", strerror(err)); } + +int prefixcmp(const char *str, const char *prefix) +{ + for (; ; str++, prefix++) + if (!*prefix) + return 0; + else if (*str != *prefix) + return (unsigned char)*prefix - (unsigned char)*str; +} + -- cgit v1.2.3