MGE General C Library - API Documentation v1.8.4
Library of general C functions.
Loading...
Searching...
No Matches
mge-buffer.h File Reference

Header file for buffer processing. More...

#include <libmgec/mge-portability.h>
#include <sys/types.h>
Include dependency graph for mge-buffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mgebuffer
 A buffer object. More...
 

Macros

#define MGEBUFFER_INIT
 A buffer object initialisation macro.
 

Functions

struct mgebufferconcat_buf (const char *s_buf, const size_t s_buf_os, struct mgebuffer *m_buf)
 Concatenate the used portion of a flat buffer into a buffer object.
 
struct mgebuffertrim_buf (struct mgebuffer *msg_buf)
 Remove processed data from a buffer object if deemed necessary.
 
void print_buf (struct mgebuffer *m_buf)
 Print a buffer object to stdout, (for debugging).
 
void print_def_buf_values (void)
 Print the key default values to stdout, (for debugging).
 

Detailed Description

Header file for buffer processing.

All buffer manipulation related information.

Author
Copyright (C) 2017-2019, 2021-2023 Mark Grant

Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0-only

Version
v1.1.0 ==== 02/11/2023

Macro Definition Documentation

◆ MGEBUFFER_INIT

#define MGEBUFFER_INIT
Value:
{ \
.buffer = NULL, .size = 0, .proc_next = 0, .next_free = 0 \
}

A buffer object initialisation macro.

Function Documentation

◆ concat_buf()

struct mgebuffer * concat_buf ( const char *  s_buf,
const size_t  s_buf_os,
struct mgebuffer m_buf 
)

Concatenate the used portion of a flat buffer into a buffer object.

On failure NULL is returned, the function arguments are unchanged and mge_errno will be set.

Parameters
s_bufSource buffer.
s_buf_osOffset into source buffer ie extent of used portion.
m_bufThe buffer object to use.
Returns
The processed buffer object. NULL on error.

◆ print_buf()

void print_buf ( struct mgebuffer m_buf)

Print a buffer object to stdout, (for debugging).

Parameters
m_bufBuffer to print.

◆ print_def_buf_values()

void print_def_buf_values ( void  )

Print the key default values to stdout, (for debugging).

◆ trim_buf()

struct mgebuffer * trim_buf ( struct mgebuffer m_buf)

Remove processed data from a buffer object if deemed necessary.

Re-sizing the buffer every time this function is called would not be efficient. So, the function first tests whether the buffer has a defined multiple of the default buffer size (BUF_UNUSED_DEF_SIZE_MULT) free, and if so shrinks the buffer and relocates valid data to the start of the buffer. If that test does not result in action, the second test determines if the percentage of unreachable portion of the buffer to the size of the buffer exceeds a defined value (BUF_MAX_UNREACH_PERCENT), and if so, it relocates data to the start of the buffer. On failure NULL is returned, the function argument is unchanged and mge_errno will be set.

Parameters
m_bufPointer to the buffer object to process.
Returns
Pointer to the processed buffer object or NULL on error.