Imported Upstream version 2.9.0
[debian/cc1111] / support / Util / dbuf.h
1 /*
2   dbuf.h - Dynamic buffer interface
3   version 1.2.0, January 6th, 2007
4
5   Copyright (c) 2002-2007 Borut Razem
6
7   This software is provided 'as-is', without any express or implied
8   warranty.  In no event will the authors be held liable for any damages
9   arising from the use of this software.
10
11   Permission is granted to anyone to use this software for any purpose,
12   including commercial applications, and to alter it and redistribute it
13   freely, subject to the following restrictions:
14
15   1. The origin of this software must not be misrepresented; you must not
16      claim that you wrote the original software. If you use this software
17      in a product, an acknowledgment in the product documentation would be
18      appreciated but is not required.
19   2. Altered source versions must be plainly marked as such, and must not be
20      misrepresented as being the original software.
21   3. This notice may not be removed or altered from any source distribution.
22
23   Borut Razem
24   borut.razem@siol.net
25 */
26
27
28 #ifndef __DBUF_H
29 #define __DBUF_H
30
31 #include <stddef.h>
32
33 struct dbuf_s {
34   size_t alloc;   /* size of allocated buffer in bytes */
35   size_t len;     /* actual length of the buffer in bytes */
36   void *buf;      /* pointer to the buffer, allocated on heap */
37 };
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 int _dbuf_expand(struct dbuf_s *dbuf, size_t size);
45 struct dbuf_s *dbuf_new(size_t size);
46 int dbuf_init(struct dbuf_s *dbuf, size_t size);
47 int dbuf_set_length(struct dbuf_s *dbuf, size_t size);
48 int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len);
49 const void *dbuf_get_buf(struct dbuf_s *dbuf);
50 size_t dbuf_get_length(struct dbuf_s *dbuf);
51 const char *dbuf_c_str(struct dbuf_s *dbuf);
52 int dbuf_trim(struct dbuf_s *dbuf);
53 void *dbuf_detach(struct dbuf_s *dbuf);
54 void dbuf_destroy(struct dbuf_s *dbuf);
55 void dbuf_delete(struct dbuf_s *dbuf);
56 void dbuf_free(const void *buf);
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif  /* __DBUF_H */