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...
This commit is contained in:
parent
15b25ad174
commit
f5df13f853
10
src/utils.c
10
src/utils.c
@ -268,3 +268,13 @@ void xpthread_cond_destroy(pthread_cond_t *cond)
|
|||||||
if ((err = pthread_cond_destroy(cond)))
|
if ((err = pthread_cond_destroy(cond)))
|
||||||
FATAL("failed to destroy cond: %s\n", strerror(err));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -103,4 +103,6 @@ void xpthread_mutex_destroy(pthread_mutex_t *mutex);
|
|||||||
|
|
||||||
void xpthread_cond_destroy(pthread_cond_t *cond);
|
void xpthread_cond_destroy(pthread_cond_t *cond);
|
||||||
|
|
||||||
|
int prefixcmp(const char *str, const char *prefix);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user