all: Use internal MEMMEM instead gnu memem

It is used only on small strings, so it is fast enough
This commit is contained in:
Pali Rohár committed 2014-11-26 16:29:53 +01:00
1 parent 52efd5a404
commit db4c7c1951
3 files changed
+16 -3

No files matched your search

+13
View File
@@ -24,4 +24,17 @@ extern int verbose;
#define SLEEP(usec) do { struct timespec _t = { 0, (usec) }; nanosleep(&_t, NULL); } while (0) #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 #endif
+1 -1
View File
@@ -262,7 +262,7 @@ int mkii_flash_image(struct usb_device_info * dev, struct image * image) {
for ( i = 0; bufs[i]; ++i ) { for ( i = 0; bufs[i]; ++i ) {
len = ((uint8_t*)bufs[i])[0]; 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; break;
} }
+2 -2
View File
@@ -127,7 +127,7 @@ static int nolo_identify_string(struct usb_device_info * dev, const char * str,
if ( (size_t)ret > sizeof(buf) ) if ( (size_t)ret > sizeof(buf) )
ret = sizeof(buf); ret = sizeof(buf);
ptr = memmem(buf, ret, str, strlen(str)); ptr = MEMMEM(buf, ret, str, strlen(str));
if ( ! ptr ) if ( ! ptr )
ERROR_RETURN("Substring was not found", -1); 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 ) { for ( i = 0; bufs[i]; ++i ) {
len = ((uint8_t*)bufs[i])[0]; 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; break;
} }