diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2014-11-26 16:29:53 +0100 |
---|---|---|
committer | Pali Rohár <pali.rohar@gmail.com> | 2014-11-26 16:29:53 +0100 |
commit | db4c7c19512504ee1391728248ae08c966a60b43 (patch) | |
tree | 642e992f52cbce0a91f7232e49aad2e34b5a04f2 /src/global.h | |
parent | 52efd5a404f3c8ee64b62ed55c954a151e61153a (diff) | |
download | 0xFFFF-db4c7c19512504ee1391728248ae08c966a60b43.tar.bz2 |
all: Use internal MEMMEM instead gnu memem
It is used only on small strings, so it is fast enough
Diffstat (limited to 'src/global.h')
-rw-r--r-- | src/global.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/global.h b/src/global.h index 991d3b3..4cff79f 100644 --- a/src/global.h +++ b/src/global.h @@ -24,4 +24,17 @@ extern int verbose; #define SLEEP(usec) do { struct timespec _t = { 0, (usec) }; nanosleep(&_t, NULL); } while (0) +static inline void * MEMMEM(void *haystack, size_t haystacklen, const void *needle, size_t needlelen) { + for ( size_t i = 0; i < haystacklen; ++i ) { + for ( size_t j = 0; j < needlelen; ++j ) { + if ( ((char *)haystack)[i] != ((const char *)needle)[j] ) + break; + if ( j != needlelen - 1 ) + continue; + return (char *)haystack + i; + } + } + return NULL; +} + #endif |