Browse Source

Add configurator test for memmem()

memmem(), which searches for one bytestring in a longer
bytestring is one of those functions that should be standard, but
isn't.  This patch adds a ccan configurator test for the function
so that modules can use or replace it as necessary.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson 15 years ago
parent
commit
6aa15db4f4
2 changed files with 7 additions and 0 deletions
  1. 1 0
      config.h
  2. 6 0
      tools/configurator/configurator.c

+ 1 - 0
config.h

@@ -32,6 +32,7 @@
 #define HAVE_FLEXIBLE_ARRAY_MEMBER 1
 #define HAVE_FLEXIBLE_ARRAY_MEMBER 1
 #define HAVE_GETPAGESIZE 1
 #define HAVE_GETPAGESIZE 1
 #define HAVE_LITTLE_ENDIAN 1
 #define HAVE_LITTLE_ENDIAN 1
+#define HAVE_MEMMEM 1
 #define HAVE_MMAP 1
 #define HAVE_MMAP 1
 #define HAVE_NESTED_FUNCTIONS 1
 #define HAVE_NESTED_FUNCTIONS 1
 #define HAVE_STACK_GROWS_UPWARDS 0
 #define HAVE_STACK_GROWS_UPWARDS 0

+ 6 - 0
tools/configurator/configurator.c

@@ -106,6 +106,12 @@ static struct test tests[] = {
 	  "union { int i; char c[sizeof(int)]; } u;\n"
 	  "union { int i; char c[sizeof(int)]; } u;\n"
 	  "u.i = 0x01020304;\n"
 	  "u.i = 0x01020304;\n"
 	  "return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;" },
 	  "return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;" },
+	{ "HAVE_MEMMEM", DEFINES_FUNC, NULL,
+	  "#define _GNU_SOURCE\n"
+	  "#include <string.h>\n"
+	  "static void *func(void *h, size_t hl, void *n, size_t nl) {\n"
+	  "return memmem(h, hl, n, nl);"
+	  "}\n", },
 	{ "HAVE_MMAP", DEFINES_FUNC, NULL,
 	{ "HAVE_MMAP", DEFINES_FUNC, NULL,
 	  "#include <sys/mman.h>\n"
 	  "#include <sys/mman.h>\n"
 	  "static void *func(int fd) {\n"
 	  "static void *func(int fd) {\n"