File: adbuf.h

package info (click to toggle)
hping3 3.a2.ds2-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 2,068 kB
  • sloc: ansic: 11,628; sh: 129; makefile: 76
file content (45 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download | duplicates (6)
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
/* adbuf.h - header file for adbuf.c
 *
 * Copyright(C) 2001-2002 Salvatore Sanfilippo <antirez@invece.org>
 * All rights reserved.
 * See the LICENSE file for COPYRIGHT and PERMISSION notice */

/* $Id: adbuf.h,v 1.1.1.1 2003/08/31 17:24:00 antirez Exp $ */

#ifndef _ADBUF_H
#define _ADBUF_H

#include <sys/types.h>

struct adbuf {
	char *buf;
	size_t size;	/* total buffer size */
	size_t left;	/* unused buffer size */
	/* the size of data stored is just size-left */
};

#define ADBUF_INCR	256	/* note that this MUST BE >= 1 */
#define adbuf_used(b)	((b)->size - (b)->left)
#define adbuf_ptr(b)	((b)->buf)

/* Rawly create an adbuf object. 's' is supposed to be some heap
 * memory already allocated, with some nul-term string inside */
#define adbuf_from_heapstring(b,s) \
	do { b->buf = s; b->left = 0; b->size = strlen(s); } while(0)

int adbuf_init(struct adbuf *b);
void adbuf_free(struct adbuf *b);
int adbuf_reset(struct adbuf *b);
int adbuf_add(struct adbuf *b, void *data, size_t len);
int adbuf_addchar(struct adbuf *b, int c);
int adbuf_strcat(struct adbuf *b, char *string);
int adbuf_cat(struct adbuf *a, struct adbuf *b);
int adbuf_cut(struct adbuf *b, size_t count);
int adbuf_ltrim(struct adbuf *b, size_t count);
int adbuf_rtrim(struct adbuf *b, size_t count);
int adbuf_add_long(struct adbuf *b, long l);
int adbuf_add_ulong(struct adbuf *b, unsigned long l);
int adbuf_clone(struct adbuf *src, struct adbuf *dst);
int adbuf_printf(struct adbuf *dst, const char *fmt, ...);

#endif /* _ADBUF_H */