From 30b321dceaa0570b4e0a556cb8723363b087709c Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Mon, 16 Nov 2015 22:18:46 -0500 Subject: [PATCH] strcasestr implementation for mingw --- tool/Makefile | 2 +- tool/strcasestr.c | 33 +++++++++++++++++++++++++++++++++ tool/strcasestr.h | 6 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tool/strcasestr.c create mode 100644 tool/strcasestr.h diff --git a/tool/Makefile b/tool/Makefile index 4800c9c..56e214a 100644 --- a/tool/Makefile +++ b/tool/Makefile @@ -10,7 +10,7 @@ endif ifeq ($(shell uname -o), Msys) -COMPAT_OBJS=sleep.o memmem.o +COMPAT_OBJS=sleep.o memmem.o strcasestr.o endif CFLAGS=-Wall -g `pkg-config $(HIDAPI_NAME) --cflags` --std=c99 diff --git a/tool/strcasestr.c b/tool/strcasestr.c new file mode 100644 index 0000000..03598e1 --- /dev/null +++ b/tool/strcasestr.c @@ -0,0 +1,33 @@ +#include + +#ifdef TEST_IMPLEMENTATION +#include + +#define strcasestr my_strcasestr + +char *strcasestr(const char *haystack, const char *needle); +int main(void) +{ + const char *a = "sdfsdj kdkf23 34fjsdf lsdf "; + + if (my_strcasestr(a, "11")) { + printf("Test 1 failed\n"); + } + if (!my_strcasestr(a, "23")) { + printf("Test 2 failed\n"); + } + +} + +#endif + +char *strcasestr(const char *haystack, const char *needle) +{ + while (*haystack) { + if (0==strncasecmp(haystack, needle, strlen(needle))) { + return (char*)haystack; + } + haystack++; + } + return NULL; +} diff --git a/tool/strcasestr.h b/tool/strcasestr.h new file mode 100644 index 0000000..d6fcf6e --- /dev/null +++ b/tool/strcasestr.h @@ -0,0 +1,6 @@ +#ifndef _strcasestr_h__ +#define _strcasestr_h_- + +char *strcasestr(const char *haystack, const char *needle); + +#endif // _strcasestr_h__