struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / util / dbuf.h
blob3e4ce2d5461b9ae4debb10f307ddbb662ce378c7
1 /*
2 dbuf.h - Dynamic buffer interface
3 version 1.4.0, 2011-03-27
5 Copyright (c) 2002-2011 Borut Razem
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.
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:
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.
23 Borut Razem
24 borut.razem@siol.net
28 #ifndef __DBUF_H
29 #define __DBUF_H
31 #include <stddef.h>
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 */
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
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_is_initialized (struct dbuf_s *dbuf);
48 int dbuf_set_length(struct dbuf_s *dbuf, size_t size);
49 int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len);
50 int dbuf_prepend(struct dbuf_s *dbuf, const void *buf, size_t len);
51 const void *dbuf_get_buf(const struct dbuf_s *dbuf);
52 size_t dbuf_get_length(const struct dbuf_s *dbuf);
53 const char *dbuf_c_str(struct dbuf_s *dbuf);
54 int dbuf_trim(struct dbuf_s *dbuf);
55 void *dbuf_detach(struct dbuf_s *dbuf);
56 char *dbuf_detach_c_str(struct dbuf_s *dbuf);
57 void dbuf_destroy(struct dbuf_s *dbuf);
58 void dbuf_delete(struct dbuf_s *dbuf);
59 void dbuf_free(const void *buf);
61 #ifdef __cplusplus
63 #endif
65 #endif /* __DBUF_H */