summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2014-11-26 16:29:53 +0100
committerPali Rohár <pali.rohar@gmail.com>2014-11-26 16:29:53 +0100
commitdb4c7c19512504ee1391728248ae08c966a60b43 (patch)
tree642e992f52cbce0a91f7232e49aad2e34b5a04f2
parent52efd5a404f3c8ee64b62ed55c954a151e61153a (diff)
download0xFFFF-db4c7c19512504ee1391728248ae08c966a60b43.tar.bz2
all: Use internal MEMMEM instead gnu memem
It is used only on small strings, so it is fast enough
-rw-r--r--src/global.h13
-rw-r--r--src/mkii.c2
-rw-r--r--src/nolo.c4
3 files changed, 16 insertions, 3 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
diff --git a/src/mkii.c b/src/mkii.c
index 7e2ea26..889dae7 100644
--- a/src/mkii.c
+++ b/src/mkii.c
@@ -262,7 +262,7 @@ int mkii_flash_image(struct usb_device_info * dev, struct image * image) {
for ( i = 0; bufs[i]; ++i ) {
len = ((uint8_t*)bufs[i])[0];
- if ( memmem(bufs[i]+1, len, buf, strlen(buf)) )
+ if ( MEMMEM(bufs[i]+1, len, buf, strlen(buf)) )
break;
}
diff --git a/src/nolo.c b/src/nolo.c
index 6dce8a2..5e51a36 100644
--- a/src/nolo.c
+++ b/src/nolo.c
@@ -127,7 +127,7 @@ static int nolo_identify_string(struct usb_device_info * dev, const char * str,
if ( (size_t)ret > sizeof(buf) )
ret = sizeof(buf);
- ptr = memmem(buf, ret, str, strlen(str));
+ ptr = MEMMEM(buf, ret, str, strlen(str));
if ( ! ptr )
ERROR_RETURN("Substring was not found", -1);
@@ -326,7 +326,7 @@ static int nolo_send_image(struct usb_device_info * dev, struct image * image, i
for ( i = 0; bufs[i]; ++i ) {
len = ((uint8_t*)bufs[i])[0];
- if ( memmem(bufs[i]+1, len, buf, strlen(buf)) )
+ if ( MEMMEM(bufs[i]+1, len, buf, strlen(buf)) )
break;
}