wmem: allow wmem_destroy_list to ignore a NULL list.
[metze/wireshark/wip.git] / wsutil / buffer.h
1 /* buffer.h
2  *
3  * Wiretap Library
4  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8
9 #ifndef __W_BUFFER_H__
10 #define __W_BUFFER_H__
11
12 #include <glib.h>
13 #include "ws_symbol_export.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif /* __cplusplus */
18
19 #define SOME_FUNCTIONS_ARE_DEFINES
20
21 typedef struct Buffer {
22         guint8  *data;
23         gsize   allocated;
24         gsize   start;
25         gsize   first_free;
26 } Buffer;
27
28 WS_DLL_PUBLIC
29 void ws_buffer_init(Buffer* buffer, gsize space);
30 WS_DLL_PUBLIC
31 void ws_buffer_free(Buffer* buffer);
32 WS_DLL_PUBLIC
33 void ws_buffer_assure_space(Buffer* buffer, gsize space);
34 WS_DLL_PUBLIC
35 void ws_buffer_append(Buffer* buffer, guint8 *from, gsize bytes);
36 WS_DLL_PUBLIC
37 void ws_buffer_remove_start(Buffer* buffer, gsize bytes);
38 WS_DLL_PUBLIC
39 void ws_buffer_cleanup(void);
40
41 #ifdef SOME_FUNCTIONS_ARE_DEFINES
42 # define ws_buffer_clean(buffer) ws_buffer_remove_start((buffer), ws_buffer_length(buffer))
43 # define ws_buffer_increase_length(buffer,bytes) (buffer)->first_free += (bytes)
44 # define ws_buffer_length(buffer) ((buffer)->first_free - (buffer)->start)
45 # define ws_buffer_start_ptr(buffer) ((buffer)->data + (buffer)->start)
46 # define ws_buffer_end_ptr(buffer) ((buffer)->data + (buffer)->first_free)
47 # define ws_buffer_append_buffer(buffer,src_buffer) ws_buffer_append((buffer), ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer))
48 #else
49  void ws_buffer_clean(Buffer* buffer);
50  void ws_buffer_increase_length(Buffer* buffer, unsigned int bytes);
51  unsigned gsize ws_buffer_length(Buffer* buffer);
52  guint8* ws_buffer_start_ptr(Buffer* buffer);
53  guint8* ws_buffer_end_ptr(Buffer* buffer);
54  void ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer);
55 #endif
56
57 #ifdef __cplusplus
58 }
59 #endif /* __cplusplus */
60
61 #endif