12632SN/A/* 22632SN/A * blob.h 32632SN/A * 42632SN/A * Binary blob handling. 52632SN/A * 62632SN/A * Copyright (c) 2002 Dug Song <dugsong@monkey.org> 72632SN/A * 82632SN/A * $Id: blob.h,v 1.2 2002/04/05 03:06:44 dugsong Exp $ 92632SN/A */ 102632SN/A 112632SN/A#ifndef DNET_BLOB_H 122632SN/A#define DNET_BLOB_H 132632SN/A 142632SN/Atypedef struct blob { 152632SN/A u_char *base; /* start of data */ 162632SN/A int off; /* offset into data */ 172632SN/A int end; /* end of data */ 182632SN/A int size; /* size of allocation */ 192632SN/A} blob_t; 202632SN/A 212632SN/A__BEGIN_DECLS 222632SN/Ablob_t *blob_new(void); 232632SN/A 242632SN/Aint blob_read(blob_t *b, void *buf, int len); 252632SN/Aint blob_write(blob_t *b, const void *buf, int len); 262632SN/A 272632SN/Aint blob_seek(blob_t *b, int off, int whence); 282632SN/A#define blob_skip(b, l) blob_seek(b, l, SEEK_CUR) 292632SN/A#define blob_rewind(b) blob_seek(b, 0, SEEK_SET) 302632SN/A 312632SN/A#define blob_offset(b) ((b)->off) 322632SN/A#define blob_left(b) ((b)->end - (b)->off) 332632SN/A 342632SN/Aint blob_index(blob_t *b, const void *buf, int len); 352632SN/Aint blob_rindex(blob_t *b, const void *buf, int len); 362632SN/A 372632SN/Aint blob_pack(blob_t *b, const char *fmt, ...); 382632SN/Aint blob_unpack(blob_t *b, const char *fmt, ...); 392632SN/A 402632SN/Aint blob_insert(blob_t *b, const void *buf, int len); 412632SN/Aint blob_delete(blob_t *b, void *buf, int len); 422632SN/A 432632SN/Aint blob_print(blob_t *b, char *style, int len); 442632SN/A 452632SN/Ablob_t *blob_free(blob_t *b); 462632SN/A 472632SN/Aint blob_register_alloc(size_t size, void *(*bmalloc)(size_t), 482632SN/A void (*bfree)(void *), void *(*brealloc)(void *, size_t)); 492632SN/A#ifdef va_start 502632SN/Atypedef int (*blob_fmt_cb)(int pack, int len, blob_t *b, va_list *arg); 512632SN/A 522632SN/Aint blob_register_pack(char c, blob_fmt_cb fmt_cb); 532632SN/A#endif 542632SN/A__END_DECLS 552632SN/A 562632SN/A#endif /* DNET_BLOB_H */ 57