path: root/src/blob.h
diff options
authorTimo Teräs <>2010-11-07 00:47:39 +0200
committerTimo Teräs <>2010-11-07 00:47:39 +0200
commit25593b5e6fea76ed7c08db586924032c0810c27e (patch)
treeb632534eb96978ad620fee1e5a9a5d280e0b191e /src/blob.h
parente0450bd60a30ca944c16f84ee195463fd4aab653 (diff)
squark: reorganize sources to src directory
Diffstat (limited to 'src/blob.h')
1 files changed, 63 insertions, 0 deletions
diff --git a/src/blob.h b/src/blob.h
new file mode 100644
index 0000000..76afed7
--- /dev/null
+++ b/src/blob.h
@@ -0,0 +1,63 @@
+#ifndef BLOB_H
+#define BLOB_H
+#include <string.h>
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ < 96
+#define __builtin_expect(x, expected_value) (x)
+#ifndef likely
+#define likely(x) __builtin_expect((!!(x)),1)
+#ifndef unlikely
+#define unlikely(x) __builtin_expect((!!(x)),0)
+typedef struct blob {
+ char *ptr;
+ unsigned int len;
+} blob_t;
+#define BLOB_PTR_LEN(ptr,len) (blob_t){(void*)(ptr), (len)}
+#define BLOB_PTR_PTR(beg,end) BLOB_PTR_LEN((beg),(end)-(beg)+1)
+#define BLOB_BUF(buf) (blob_t){(void*)(buf), sizeof(buf)}
+#define BLOB_STRLEN(str) (blob_t){(str), strlen(str)}
+#define BLOB_STR_INIT(str) {(str), sizeof(str)-1}
+#define BLOB_STR(str) (blob_t) BLOB_STR_INIT(str)
+#define BLOB_NULL (blob_t){NULL, 0}
+static inline int blob_is_null(blob_t b)
+ return b.len == 0;
+char *blob_cstr_dup(blob_t b);
+blob_t blob_dup(blob_t b);
+int blob_cmp(blob_t a, blob_t b);
+unsigned long blob_inet_addr(blob_t buf);
+blob_t blob_pushed(blob_t buffer, blob_t left);
+void blob_push(blob_t *b, blob_t d);
+void blob_push_lower(blob_t *b, blob_t d);
+void blob_push_byte(blob_t *b, unsigned char byte);
+void blob_push_uint(blob_t *to, unsigned int value, int radix);
+void blob_push_ctime(blob_t *to, time_t t);
+void blob_push_hexdump(blob_t *to, blob_t binary);
+void blob_push_urldecode(blob_t *to, blob_t url);
+void blob_push_urlencode(blob_t *to, blob_t url);
+blob_t blob_pull(blob_t *b, int len);
+void blob_pull_skip(blob_t *b, int len);
+int blob_pull_matching(blob_t *b, blob_t e);
+unsigned int blob_pull_uint(blob_t *b, int radix);
+blob_t blob_pull_spn(blob_t *b, const blob_t spn);
+blob_t blob_pull_cspn(blob_t *b, const blob_t cspn);
+blob_t blob_expand_head(blob_t *b, blob_t limits, unsigned char sep);
+blob_t blob_expand_tail(blob_t *b, blob_t limits, unsigned char sep);
+blob_t blob_shrink_tail(blob_t *b, blob_t limits, unsigned char sep);