]> git.ozlabs.org Git - ccan/blobdiff - ccan/rfc822/rfc822.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / rfc822 / rfc822.c
index 7f9442a8d04d235908abfd8c15e32520d97acd0f..2d23b9ca79be756ddaef6e6e5df2c94cb3e01255 100644 (file)
@@ -5,27 +5,16 @@
 #include <string.h>
 
 #include <ccan/str/str.h>
-#include <ccan/talloc/talloc.h>
 #include <ccan/list/list.h>
+#include <stdio.h>
 
+#include <ccan/mem/mem.h>
 #include <ccan/rfc822/rfc822.h>
 
-#if !HAVE_MEMMEM
-void *memmem(const void *haystack, size_t haystacklen,
-            const void *needle, size_t needlelen)
-{
-       const char *p, *last;
-
-       p = haystack;
-       last = p + haystacklen - needlelen;
-
-       do {
-               if (memcmp(p, needle, needlelen) == 0)
-                       return (void *)p;
-       } while (p++ <= last);
-
-       return NULL;
-}
+#ifdef TAL_USE_TALLOC
+#include <ccan/tal/talloc/talloc.h>
+#else
+#include <ccan/tal/tal.h>
 #endif
 
 static void (*allocation_failure_hook)(const char *);
@@ -92,6 +81,8 @@ struct rfc822_msg *rfc822_check(const struct rfc822_msg *msg,
        assert(msg);
        if (!list_check(&msg->headers, abortstr))
                 return NULL;
+       if (!tal_check(msg, abortstr))
+               return NULL;
         return (struct rfc822_msg *)msg;
 }
 
@@ -106,7 +97,7 @@ struct rfc822_msg *rfc822_start(const void *ctx, const char *p, size_t len)
        struct rfc822_msg *msg;
        int i;
 
-       msg = talloc(ctx, struct rfc822_msg);
+       msg = tal(ctx, struct rfc822_msg);
        ALLOC_CHECK(msg, NULL);
 
        msg->data = p;
@@ -128,7 +119,7 @@ struct rfc822_msg *rfc822_start(const void *ctx, const char *p, size_t len)
 void rfc822_free(struct rfc822_msg *msg)
 {
        CHECK(msg, ">rfc822_free");
-       talloc_free(msg);
+       tal_free(msg);
 }
 
 static struct rfc822_header *next_header_cached(struct rfc822_msg *msg,
@@ -200,7 +191,7 @@ static struct rfc822_header *next_header_parse(struct rfc822_msg *msg)
                msg->remainder = eh;
 
 
-       hi = talloc_zero(msg, struct rfc822_header);
+       hi = talz(msg, struct rfc822_header);
        ALLOC_CHECK(hi, NULL);
 
        hi->all = bytestring(h, eh - h);
@@ -354,7 +345,7 @@ struct bytestring rfc822_header_unfolded_value(struct rfc822_msg *msg,
                if (lines <= 1) {
                        hdr->unfolded = bytestring(raw.ptr, len);
                } else {
-                       char *unfold = talloc_array(msg, char, len);
+                       char *unfold = tal_arr(msg, char, len);
                        char *p = unfold;
 
                        ALLOC_CHECK(unfold, bytestring_NULL);
@@ -447,7 +438,7 @@ static struct rfc822_header *index_header(struct rfc822_msg *msg,
        if (!hn) {
                unsigned hash = headerhash(hname);
 
-               hn = talloc_zero(msg, struct rfc822_headers_of_name);
+               hn = talz(msg, struct rfc822_headers_of_name);
                ALLOC_CHECK(hn, NULL);
 
                hn->name = hname;