From 9c29667d060e6f1d00a9ad7997c4b357db3aa2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Tue, 10 Aug 2010 10:52:33 +0300 Subject: squark: split generic blob code to it's own file it's useful in other binaries than squark-auth too. --- blob.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 blob.h (limited to 'blob.h') diff --git a/blob.h b/blob.h new file mode 100644 index 0000000..ad242a8 --- /dev/null +++ b/blob.h @@ -0,0 +1,34 @@ +#ifndef BLOB_H +#define BLOB_H + +#include + +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)} + +extern const blob_t BLOB_NULL;; + +static inline int blob_is_null(blob_t b) +{ + return b.ptr == NULL; +} + +char *blob_cstr_dup(blob_t b); +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_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); + + +#endif -- cgit v1.2.3