1 /* 2 * blob.h 3 * 4 * Binary blob handling. 5 * 6 * Copyright (c) 2002 Dug Song <dugsong@monkey.org> 7 * 8 * $Id: blob.h 334 2002-04-05 03:06:44Z dugsong $ 9 */ 10 11 #ifndef DNET_BLOB_H 12 #define DNET_BLOB_H 13 14 typedef struct blob { 15 u_char *base; /* start of data */ 16 int off; /* offset into data */ 17 int end; /* end of data */ 18 int size; /* size of allocation */ 19 } blob_t; 20 21 __BEGIN_DECLS 22 blob_t *blob_new(void); 23 24 int blob_read(blob_t *b, void *buf, int len); 25 int blob_write(blob_t *b, const void *buf, int len); 26 27 int blob_seek(blob_t *b, int off, int whence); 28 #define blob_skip(b, l) blob_seek(b, l, SEEK_CUR) 29 #define blob_rewind(b) blob_seek(b, 0, SEEK_SET) 30 31 #define blob_offset(b) ((b)->off) 32 #define blob_left(b) ((b)->end - (b)->off) 33 34 int blob_index(blob_t *b, const void *buf, int len); 35 int blob_rindex(blob_t *b, const void *buf, int len); 36 37 int blob_pack(blob_t *b, const char *fmt, ...); 38 int blob_unpack(blob_t *b, const char *fmt, ...); 39 40 int blob_insert(blob_t *b, const void *buf, int len); 41 int blob_delete(blob_t *b, void *buf, int len); 42 43 int blob_print(blob_t *b, char *style, int len); 44 45 blob_t *blob_free(blob_t *b); 46 47 int blob_register_alloc(size_t size, void *(*bmalloc)(size_t), 48 void (*bfree)(void *), void *(*brealloc)(void *, size_t)); 49 #ifdef va_start 50 typedef int (*blob_fmt_cb)(int pack, int len, blob_t *b, va_list *arg); 51 52 int blob_register_pack(char c, blob_fmt_cb fmt_cb); 53 #endif 54 __END_DECLS 55 56 #endif /* DNET_BLOB_H */ 57