This header file is part of the utilities library; it contains the memory buffer declarations.
More...
|
void | membuf_init (struct membuf *buf, void *ptr, size_t size) |
| Initializes a memory buffer. More...
|
|
void | membuf_fini (struct membuf *buf) |
| Finalizes a memory buffer. More...
|
|
void * | membuf_begin (const struct membuf *buf) |
| Returns a pointer to the first byte in a memory buffer.
|
|
void | membuf_clear (struct membuf *buf) |
| Clears a memory buffer. More...
|
|
size_t | membuf_size (const struct membuf *buf) |
| Returns the total number of bytes written to a memory buffer.
|
|
size_t | membuf_capacity (const struct membuf *buf) |
| Returns the number of unused bytes remaining in a memory buffer.
|
|
size_t | membuf_reserve (struct membuf *buf, size_t size) |
| Resizes a memory buffer, if necessary, to make room for at least an additional size bytes. More...
|
|
ptrdiff_t | membuf_seek (struct membuf *buf, ptrdiff_t offset) |
| Adjusts the position indicator of a memory buffer by offset bytes. More...
|
|
void * | membuf_alloc (struct membuf *buf, size_t *size) |
| Creates region of *size bytes in a memory buffer, starting at the current position indicator given by membuf_size(), and sets the indicator to the end of the requested region. More...
|
|
size_t | membuf_write (struct membuf *buf, const void *ptr, size_t size) |
| Writes data to a memory buffer. More...
|
|
void | membuf_flush (struct membuf *buf, size_t size) |
| Flushes size bytes from the beginning of a memory buffer.
|
|
This header file is part of the utilities library; it contains the memory buffer declarations.
- Copyright
- 2016-2020 Lely Industries N.V.
- Author
- J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file membuf.h.
size_t membuf_reserve |
( |
struct membuf * |
buf, |
|
|
size_t |
size |
|
) |
| |
Resizes a memory buffer, if necessary, to make room for at least an additional size bytes.
This function may also shrink the buffer if it is larger than required. Although this functions preserves the data already written to the buffer, it invalidates the pointers obtained from previous calls to membuf_alloc().
- Parameters
-
buf | a pointer to a memory buffer. |
size | the required capacity of the buffer. |
- Returns
- the new capacity of the buffer, or 0 on error. The new capacity can be larger than the requested capacity.
Definition at line 52 of file membuf.c.
void * membuf_alloc |
( |
struct membuf * |
buf, |
|
|
size_t * |
size |
|
) |
| |
|
inline |
Creates region of *size bytes in a memory buffer, starting at the current position indicator given by membuf_size(), and sets the indicator to the end of the requested region.
If the requested size is larger than the current capacity, *size will be updated with the actual size of the region. If the requested size turns out to be too large or too small, the region can be adjusted with membuf_seek().
- Parameters
-
buf | a pointer to a memory buffer. |
size | the address of the value containing the requested size. On exit, *size is updated with the actual size. |
- Returns
- a pointer to a memory region of at least *size consecutive bytes (which may be 0). Note that this pointer is only valid until the next call to membuf_reserve().
Definition at line 211 of file membuf.h.