diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-09-20 15:43:35 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-09-20 15:43:35 -0700 |
commit | 5a42e7362b3745fb59f0aa49bab624f7fba83eff (patch) | |
tree | ab7c77c6d4d47324f40c5a1ddeef3928dfb676c7 | |
parent | 71ac281579c8b8b384cfc09d8627b549b1854fcd (diff) | |
download | mpd-5a42e7362b3745fb59f0aa49bab624f7fba83eff.tar.gz mpd-5a42e7362b3745fb59f0aa49bab624f7fba83eff.tar.xz mpd-5a42e7362b3745fb59f0aa49bab624f7fba83eff.zip |
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...
-rw-r--r-- | src/utils.c | 10 | ||||
-rw-r--r-- | src/utils.h | 2 |
2 files changed, 12 insertions, 0 deletions
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; +} + diff --git a/src/utils.h b/src/utils.h index 0001ba3c8..3958ac9a0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -90,6 +90,8 @@ void xpthread_mutex_destroy(pthread_mutex_t *mutex); void xpthread_cond_destroy(pthread_cond_t *cond); +int prefixcmp(const char *str, const char *prefix); + /* * Work-arounds for braindead APIs that require non-const pointers: * ao_play(), free(), vorbis_comment_add_tag(), iconv() |