UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
membuffer.hpp
Go to the documentation of this file.
1#ifndef COMPA_GENLIB_UTIL_MEMBUFFER_HPP
2#define COMPA_GENLIB_UTIL_MEMBUFFER_HPP
3/*******************************************************************************
4 *
5 * Copyright (c) 2000-2003 Intel Corporation
6 * All rights reserved.
7 * Copyright (c) 2012 France Telecom All rights reserved.
8 * Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, Ingo@Hoeft-online.de>
9 * Redistribution only with this Copyright remark. Last modified: 2025-06-12
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither name of Intel Corporation nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36// Last compare with pupnp original source file on 2024-02-14, ver 1.14.18
45
46#include <cstddef>
48
50struct memptr {
52 char* buf;
54 size_t length;
55};
56
61struct membuffer {
63 char* buf;
65 size_t length;
67 size_t capacity;
69 size_t size_inc;
71};
73inline constexpr size_t MEMBUF_DEF_SIZE_INC{5};
75
83// Don't export function symbol; only used library intern.
84char* str_alloc(
86 const char* str,
88 size_t str_len);
89
100// Don't export function symbol; only used library intern.
101int memptr_cmp(
103 memptr* m,
105 const char* s);
106
119// Don't export function symbol; only used library intern.
122 memptr* m,
124 const char* s);
125
134// Don't export function symbol; only used library intern.
137 membuffer* m,
139 size_t new_length);
140
147// Don't export function symbol; only used library intern.
148void membuffer_init(
150 membuffer* m);
151
155// Don't export function symbol; only used library intern.
158 membuffer* m);
159
168// Don't export function symbol; only used library intern.
171 membuffer* m,
173 const void* buf,
175 size_t buf_len);
176
184// Don't export function symbol; only used library intern.
187 membuffer* m,
189 const char* c_str);
190
196// Don't export function symbol; only used library intern.
199 membuffer* m,
201 const void* buf,
203 size_t buf_len);
204
210// Don't export function symbol; only used library intern.
213 membuffer* m,
215 const char* c_str);
216
224// Don't export function symbol; only used library intern.
228 membuffer* m,
230 const void* buf,
232 size_t buf_len,
234 size_t index);
235
241// Don't export function symbol; only used library intern.
245 membuffer* m,
247 size_t index,
249 size_t num_bytes);
250
257// Don't export function symbol; only used library intern.
258char* membuffer_detach(
260 membuffer* m);
261
269// Don't export function symbol; only used library intern.
272 membuffer* m,
275 char* new_buf,
277 size_t buf_len);
278
279#endif /* COMPA_GENLIB_UTIL_MEMBUFFER_HPP */
int memptr_cmp(memptr *m, const char *s)
Compares characters of strings passed for number of bytes. If equal for the number of bytes,...
Definition membuffer.cpp:70
void membuffer_destroy(membuffer *m)
Free's memory allocated for membuffer* m.
size_t size_inc
used to increase size; MUST be > 0; (read/write).
Definition membuffer.hpp:69
size_t capacity
total allocated memory without terminating null byte (read-only).
Definition membuffer.hpp:67
int membuffer_set_size(membuffer *m, size_t new_length)
Increases or decreases buffer cap so that at least 'new_length' bytes can be stored.
char * str_alloc(const char *str, size_t str_len)
Allocate memory and copy information from the input string to the newly allocated memory.
Definition membuffer.cpp:56
size_t length
length of buffer without terminating null byte (read-only).
Definition membuffer.hpp:65
void membuffer_attach(membuffer *m, char *new_buf, size_t buf_len)
Free existing memory in membuffer and assign the new buffer in its place.
void membuffer_init(membuffer *m)
Wrapper to membuffer_initialize().
int membuffer_append(membuffer *m, const void *buf, size_t buf_len)
Invokes function to appends data from a constant buffer to the buffer.
int membuffer_assign_str(membuffer *m, const char *c_str)
Wrapper function for membuffer_assign().
char * membuffer_detach(membuffer *m)
Detaches current buffer and returns it. The caller must free the returned buffer using free()....
int membuffer_append_str(membuffer *m, const char *c_str)
Invokes function to appends data from a constant string to the buffer.
char * buf
mem buffer; must not write beyond buf[length-1] (read/write).
Definition membuffer.hpp:63
size_t length
length of memory (read-only).
Definition membuffer.hpp:54
int memptr_cmp_nocase(memptr *m, const char *s)
Compares characters of 2 strings irrespective of the case for a specific count of bytes.
Definition membuffer.cpp:84
int membuffer_insert(membuffer *m, const void *buf, size_t buf_len, size_t index)
Allocates memory for the new data to be inserted. Does memory management by moving the data from the ...
char * buf
start of memory (read/write).
Definition membuffer.hpp:52
int membuffer_assign(membuffer *m, const void *buf, size_t buf_len)
Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf.
void membuffer_delete(membuffer *m, size_t index, size_t num_bytes)
Shrink the size of the buffer depending on the current size of the buffer and the input parameters....
pointer to a chunk of memory.
Definition membuffer.hpp:50
Maintains a block of dynamically allocated memory.
Definition membuffer.hpp:61