summaryrefslogtreecommitdiffstats
path: root/blob.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-08-10 14:49:46 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-08-10 14:49:46 +0300
commit679cadbe809bdf5436b4f7c48d9722c08a59ab59 (patch)
treedc2a020fec3913112d00362a4bf7b819ec44b228 /blob.h
parent9c29667d060e6f1d00a9ad7997c4b357db3aa2ac (diff)
downloadsquark-679cadbe809bdf5436b4f7c48d9722c08a59ab59.tar.bz2
squark-679cadbe809bdf5436b4f7c48d9722c08a59ab59.tar.xz
blob: use uppercase for macroes, add some functionality
Normalizing macro names to upper case and extending functionality.
Diffstat (limited to 'blob.h')
-rw-r--r--blob.h28
1 files changed, 22 insertions, 6 deletions
diff --git a/blob.h b/blob.h
index ad242a8..883c053 100644
--- a/blob.h
+++ b/blob.h
@@ -3,16 +3,31 @@
#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)
+#endif
+
+#ifndef likely
+#define likely(x) __builtin_expect((!!(x)),1)
+#endif
+
+#ifndef unlikely
+#define unlikely(x) __builtin_expect((!!(x)),0)
+#endif
+
typedef struct blob {
char *ptr;
unsigned int len;
} blob_t;
-#define blob_dyn(ptr,len) (blob_t){(void*)(ptr), (len)}
-#define blob_buf(buf) (blob_t){(void*)(buf), sizeof(buf)}
-#define blob_str(str) (blob_t){(char*)(str), strlen(str)}
+#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_STR(str) (blob_t){(char*)(str), strlen(str)}
-extern const blob_t BLOB_NULL;;
+extern const blob_t BLOB_NULL;
static inline int blob_is_null(blob_t b)
{
@@ -24,11 +39,12 @@ blob_t blob_dup(blob_t b);
int blob_cmp(blob_t a, blob_t b);
blob_t blob_pushed(blob_t buffer, blob_t left);
void blob_push(blob_t *b, blob_t d);
-void blob_push_int_str(blob_t *b, int val);
+void blob_push_uint(blob_t *to, unsigned int value, int radix);
void blob_push_hexdump(blob_t *to, blob_t binary);
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_cspn(blob_t *b, const blob_t cspn);
#endif