]> git.ozlabs.org Git - ccan/commitdiff
mem: Rename memmem module to mem
authorDavid Gibson <david@gibson.dropbear.id.au>
Wed, 22 Oct 2014 11:56:51 +0000 (13:56 +0200)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 27 Oct 2014 05:43:10 +0000 (16:13 +1030)
Currently the 'memmem' module does nothing but provide an implementation of
the memmem() function if it is missing from the standard C library.

However there are other functions (e.g. memrchr()) also missing from some
C library implementations, so rename the module to mem to allow future
inclusion of other functions.

This also updates the rfc822 module - the only existing user of the
memmem module - to use the new name.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
13 files changed:
Makefile-ccan
ccan/mem/LICENSE [new symlink]
ccan/mem/_info [new file with mode: 0644]
ccan/mem/mem.c [new file with mode: 0644]
ccan/mem/mem.h [new file with mode: 0644]
ccan/mem/test/run.c [new file with mode: 0644]
ccan/memmem/LICENSE [deleted symlink]
ccan/memmem/_info [deleted file]
ccan/memmem/memmem.c [deleted file]
ccan/memmem/memmem.h [deleted file]
ccan/memmem/test/run.c [deleted file]
ccan/rfc822/_info
ccan/rfc822/rfc822.c

index f97ff20d14750f4ac8487e98317bf3f2489300ce..543a3452f15ba0716a747ed61c7d0755183074f5 100644 (file)
@@ -72,7 +72,7 @@ MODS_WITH_SRC := antithread \
        lqueue \
        lstack \
        md4 \
        lqueue \
        lstack \
        md4 \
-       memmem \
+       mem \
        net \
        nfs \
        noerr \
        net \
        nfs \
        noerr \
diff --git a/ccan/mem/LICENSE b/ccan/mem/LICENSE
new file mode 120000 (symlink)
index 0000000..b7951da
--- /dev/null
@@ -0,0 +1 @@
+../../licenses/CC0
\ No newline at end of file
diff --git a/ccan/mem/_info b/ccan/mem/_info
new file mode 100644 (file)
index 0000000..19b2228
--- /dev/null
@@ -0,0 +1,30 @@
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+
+/**
+ * mem - Provide mem*() functions if missing from C library
+ *
+ * This code implements some string.h mem*() functions if they're not
+ * already available in the C library.  Functions included are:
+ *     memmem()
+ *
+ * License: CC0
+ */
+int main(int argc, char *argv[])
+{
+       /* Expect exactly one argument */
+       if (argc != 2)
+               return 1;
+
+       if (strcmp(argv[1], "depends") == 0) {
+               return 0;
+       }
+
+       if (strcmp(argv[1], "testdepends") == 0) {
+               printf("ccan/array_size");
+               return 0;
+       }
+
+       return 1;
+}
diff --git a/ccan/mem/mem.c b/ccan/mem/mem.c
new file mode 100644 (file)
index 0000000..ce675ff
--- /dev/null
@@ -0,0 +1,27 @@
+/* CC0 (Public domain) - see LICENSE file for details */
+
+#include "config.h"
+
+#include <string.h>
+#include <ccan/mem/mem.h>
+
+#if !HAVE_MEMMEM
+void *memmem(const void *haystack, size_t haystacklen,
+            const void *needle, size_t needlelen)
+{
+       const char *p;
+
+       if (needlelen > haystacklen)
+               return NULL;
+
+       p = haystack;
+
+       for (p = haystack;
+            (p + needlelen) <= ((const char *)haystack + haystacklen);
+            p++)
+               if (memcmp(p, needle, needlelen) == 0)
+                       return (void *)p;
+
+       return NULL;
+}
+#endif
diff --git a/ccan/mem/mem.h b/ccan/mem/mem.h
new file mode 100644 (file)
index 0000000..771d052
--- /dev/null
@@ -0,0 +1,14 @@
+/* CC0 (Public domain) - see LICENSE file for details */
+#ifndef CCAN_MEM_H
+#define CCAN_MEM_H
+
+#include "config.h"
+
+#include <string.h>
+
+#if !HAVE_MEMMEM
+void *memmem(const void *haystack, size_t haystacklen,
+            const void *needle, size_t needlelen);
+#endif
+
+#endif /* CCAN_MEM_H */
diff --git a/ccan/mem/test/run.c b/ccan/mem/test/run.c
new file mode 100644 (file)
index 0000000..3efd1d8
--- /dev/null
@@ -0,0 +1,20 @@
+#include <ccan/array_size/array_size.h>
+#include <ccan/mem/mem.h>
+#include <ccan/tap/tap.h>
+
+int main(void)
+{
+       char haystack1[] = "abcd\0efgh";
+       char needle1[] = "ab";
+       char needle2[] = "d\0e";
+
+       /* This is how many tests you plan to run */
+       plan_tests(3);
+
+       ok1(memmem(haystack1, sizeof(haystack1), needle1, 2) == haystack1);
+       ok1(memmem(haystack1, sizeof(haystack1), needle1, 3) == NULL);
+       ok1(memmem(haystack1, sizeof(haystack1), needle2, 3) == (haystack1 + 3));
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}
diff --git a/ccan/memmem/LICENSE b/ccan/memmem/LICENSE
deleted file mode 120000 (symlink)
index b7951da..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../licenses/CC0
\ No newline at end of file
diff --git a/ccan/memmem/_info b/ccan/memmem/_info
deleted file mode 100644 (file)
index 3361be9..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "config.h"
-#include <stdio.h>
-#include <string.h>
-
-/**
- * memmem - Trivial module providing a memmem() implementation
- *
- * This code implements memmem() if it's not alreayd available in the
- * C library.
- *
- * License: CC0
- */
-int main(int argc, char *argv[])
-{
-       /* Expect exactly one argument */
-       if (argc != 2)
-               return 1;
-
-       if (strcmp(argv[1], "depends") == 0) {
-               return 0;
-       }
-
-       if (strcmp(argv[1], "testdepends") == 0) {
-               printf("ccan/array_size");
-               return 0;
-       }
-
-       return 1;
-}
diff --git a/ccan/memmem/memmem.c b/ccan/memmem/memmem.c
deleted file mode 100644 (file)
index 48a6de2..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* CC0 (Public domain) - see LICENSE file for details */
-
-#include "config.h"
-
-#include <string.h>
-#include <ccan/memmem/memmem.h>
-
-#if !HAVE_MEMMEM
-void *memmem(const void *haystack, size_t haystacklen,
-            const void *needle, size_t needlelen)
-{
-       const char *p;
-
-       if (needlelen > haystacklen)
-               return NULL;
-
-       p = haystack;
-
-       for (p = haystack;
-            (p + needlelen) <= ((const char *)haystack + haystacklen);
-            p++)
-               if (memcmp(p, needle, needlelen) == 0)
-                       return (void *)p;
-
-       return NULL;
-}
-#endif
diff --git a/ccan/memmem/memmem.h b/ccan/memmem/memmem.h
deleted file mode 100644 (file)
index 4da5394..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/* CC0 (Public domain) - see LICENSE file for details */
-#ifndef CCAN_MEMMEM_H
-#define CCAN_MEMMEM_H
-
-#include "config.h"
-
-#include <string.h>
-
-#if !HAVE_MEMMEM
-void *memmem(const void *haystack, size_t haystacklen,
-            const void *needle, size_t needlelen);
-#endif
-
-#endif /* CCAN_MEMMEM_H */
diff --git a/ccan/memmem/test/run.c b/ccan/memmem/test/run.c
deleted file mode 100644 (file)
index af9aac5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <ccan/array_size/array_size.h>
-#include <ccan/memmem/memmem.h>
-#include <ccan/tap/tap.h>
-
-int main(void)
-{
-       char haystack1[] = "abcd\0efgh";
-       char needle1[] = "ab";
-       char needle2[] = "d\0e";
-
-       /* This is how many tests you plan to run */
-       plan_tests(3);
-
-       ok1(memmem(haystack1, sizeof(haystack1), needle1, 2) == haystack1);
-       ok1(memmem(haystack1, sizeof(haystack1), needle1, 3) == NULL);
-       ok1(memmem(haystack1, sizeof(haystack1), needle2, 3) == (haystack1 + 3));
-
-       /* This exits depending on whether all tests passed */
-       return exit_status();
-}
index 7c3ca08eda7a0a3affc069257b1db31305f3b24c..680f4991981fb3b5f8663b6981addbc6052dde38 100644 (file)
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
                printf("ccan/list\n");
                printf("ccan/str\n");
                printf("ccan/bytestring\n");
                printf("ccan/list\n");
                printf("ccan/str\n");
                printf("ccan/bytestring\n");
-               printf("ccan/memmem\n");
+               printf("ccan/mem\n");
                return 0;
        }
 
                return 0;
        }
 
index 636d29a612c2c4b189af9f0fc50cfb7ad4957643..2d23b9ca79be756ddaef6e6e5df2c94cb3e01255 100644 (file)
@@ -8,7 +8,7 @@
 #include <ccan/list/list.h>
 #include <stdio.h>
 
 #include <ccan/list/list.h>
 #include <stdio.h>
 
-#include <ccan/memmem/memmem.h>
+#include <ccan/mem/mem.h>
 #include <ccan/rfc822/rfc822.h>
 
 #ifdef TAL_USE_TALLOC
 #include <ccan/rfc822/rfc822.h>
 
 #ifdef TAL_USE_TALLOC