From 679cadbe809bdf5436b4f7c48d9722c08a59ab59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Tue, 10 Aug 2010 14:49:46 +0300 Subject: blob: use uppercase for macroes, add some functionality Normalizing macro names to upper case and extending functionality. --- blob.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'blob.h') diff --git a/blob.h b/blob.h index ad242a8..883c053 100644 --- a/blob.h +++ b/blob.h @@ -3,16 +3,31 @@ #include +#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 -- cgit v1.2.3