TODO netlogon_user_flags_ntlmv2_enabled
[wireshark-sm.git] / wsutil / buffer.h
blobaa3706e3d2446dbff5b80d0b204fac665b4d8c21
1 /** @file
3 * Wiretap Library
4 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
9 #ifndef __W_BUFFER_H__
10 #define __W_BUFFER_H__
12 #include <inttypes.h>
13 #include <stddef.h>
14 #include "ws_symbol_export.h"
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 #define SOME_FUNCTIONS_ARE_INLINE
22 typedef struct Buffer {
23 uint8_t *data;
24 size_t allocated;
25 size_t start;
26 size_t first_free;
27 } Buffer;
29 WS_DLL_PUBLIC
30 void ws_buffer_init(Buffer* buffer, size_t space);
31 WS_DLL_PUBLIC
32 void ws_buffer_free(Buffer* buffer);
33 WS_DLL_PUBLIC
34 void ws_buffer_assure_space(Buffer* buffer, size_t space);
35 WS_DLL_PUBLIC
36 void ws_buffer_append(Buffer* buffer, const uint8_t *from, size_t bytes);
37 WS_DLL_PUBLIC
38 void ws_buffer_remove_start(Buffer* buffer, size_t bytes);
39 WS_DLL_PUBLIC
40 void ws_buffer_cleanup(void);
42 #ifdef SOME_FUNCTIONS_ARE_INLINE
43 /* Or inlines */
44 static inline void
45 ws_buffer_clean(Buffer *buffer)
47 buffer->start = 0;
48 buffer->first_free = 0;
51 static inline void
52 ws_buffer_increase_length(Buffer* buffer, size_t bytes)
54 buffer->first_free += bytes;
57 static inline size_t
58 ws_buffer_length(const Buffer* buffer)
60 return buffer->first_free - buffer->start;
63 static inline uint8_t *
64 ws_buffer_start_ptr(const Buffer* buffer)
66 return buffer->data + buffer->start;
69 static inline uint8_t *
70 ws_buffer_end_ptr(const Buffer* buffer)
72 return buffer->data + buffer->first_free;
75 static inline void
76 ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer)
78 ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
80 #else
81 WS_DLL_PUBLIC
82 void ws_buffer_clean(Buffer* buffer);
83 WS_DLL_PUBLIC
84 void ws_buffer_increase_length(Buffer* buffer, size_t bytes);
85 WS_DLL_PUBLIC
86 size_t ws_buffer_length(const Buffer* buffer);
87 WS_DLL_PUBLIC
88 uint8_t* ws_buffer_start_ptr(const Buffer* buffer);
89 WS_DLL_PUBLIC
90 uint8_t* ws_buffer_end_ptr(const Buffer* buffer);
91 WS_DLL_PUBLIC
92 void ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer);
93 #endif
95 #ifdef __cplusplus
97 #endif /* __cplusplus */
99 #endif