File: blob.h

package info (click to toggle)
libdumbnet 1.18.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,084 kB
  • sloc: ansic: 11,563; sh: 4,732; python: 226; makefile: 92
file content (56 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * blob.h
 *
 * Binary blob handling.
 *
 * Copyright (c) 2002 Dug Song <dugsong@monkey.org>
 *
 * $Id$
 */

#ifndef DNET_BLOB_H
#define DNET_BLOB_H

typedef struct blob {
	u_char		*base;		/* start of data */
	int		 off;		/* offset into data */
	int		 end;		/* end of data */
	int		 size;		/* size of allocation */
} blob_t;

__BEGIN_DECLS
blob_t	*blob_new(void);

int	 blob_read(blob_t *b, void *buf, int len);
int	 blob_write(blob_t *b, const void *buf, int len);

int	 blob_seek(blob_t *b, int off, int whence);
#define  blob_skip(b, l)	blob_seek(b, l, SEEK_CUR)
#define  blob_rewind(b)		blob_seek(b, 0, SEEK_SET)

#define	 blob_offset(b)		((b)->off)
#define	 blob_left(b)		((b)->end - (b)->off)

int	 blob_index(blob_t *b, const void *buf, int len);
int	 blob_rindex(blob_t *b, const void *buf, int len);

int	 blob_pack(blob_t *b, const char *fmt, ...);
int	 blob_unpack(blob_t *b, const char *fmt, ...);

int	 blob_insert(blob_t *b, const void *buf, int len);
int	 blob_delete(blob_t *b, void *buf, int len);

int	 blob_print(blob_t *b, char *style, int len);

blob_t	*blob_free(blob_t *b);

int	 blob_register_alloc(size_t size, void *(*bmalloc)(size_t),
	    void (*bfree)(void *), void *(*brealloc)(void *, size_t));
#ifdef va_start
typedef int (*blob_fmt_cb)(int pack, int len, blob_t *b, va_list *arg);

int	 blob_register_pack(char c, blob_fmt_cb fmt_cb);
#endif
__END_DECLS

#endif /* DNET_BLOB_H */