MGE General C Library - API Documentation  v1.7.4
Library of general C functions.
mge-buffer.h
Go to the documentation of this file.
1 
16 /* **********************************************************************
17  * *
18  * Changelog *
19  * *
20  * Date Author Version Description *
21  * *
22  * 24/10/2017 MG 1.0.1 This ChangeLog introduced. *
23  * 04/11/2017 MG 1.0.2 Add Doxygen commenting. *
24  * 09/11/2017 MG 1.0.3 Add SPDX license tag. *
25  * 02/01/2018 MG 1.0.4 Move to new source directory structure. *
26  * 04/08/2018 MG 1.0.5 Improve offset field name to proc_next. *
27  * Improve index field name to next_free. *
28  * Convert proc_next and next_free to *
29  * size_t. *
30  * 06/09/2018 MG 1.0.6 Add an mgebuffer initialisation macro. *
31  * 09/09/2018 MG 1.0.7 Move default buffer size macro to *
32  * internal header file as it should not *
33  * be part of the API. *
34  * 25/05/2019 MG 1.0.8 Correct source buffer offset type to *
35  * unsigned. *
36  * 08/06/2019 MG 1.0.9 clang-format coding style changes. *
37  * 15/04/2021 MG 1.0.10 Add print_def_buf_values() prototype. *
38  * 03/12/2021 MG 1.0.11 Tighten SPDX tag. *
39  * 16/09/2022 MG 1.0.12 Rename of portability.h *
40  * Rename to standard format mge-buffer.h *
41  * *
42  ************************************************************************
43  */
44 
45 #ifndef MGE_BUFFER_H
46 #define MGE_BUFFER_H
47 
49 
50 #include <sys/types.h>
51 
53 
57 struct mgebuffer {
58  char *buffer;
59  size_t size;
60  size_t proc_next;
61  size_t next_free;
62 };
63 
67 #define MGEBUFFER_INIT \
68  { \
69  .buffer = NULL, .size = 0, .proc_next = 0, .next_free = 0 \
70  }
71 
72 struct mgebuffer *concat_buf(const char *s_buf, const size_t s_buf_os,
73  struct mgebuffer *m_buf);
74 
75 struct mgebuffer *trim_buf(struct mgebuffer *msg_buf);
76 
77 void print_buf(struct mgebuffer *m_buf);
78 
79 void print_def_buf_values(void);
80 
82 
83 #endif /* ndef MGE_BUFFER_H */
void print_def_buf_values(void)
Print the key default values to stdout, (for debugging).
Definition: buffer.c:168
void print_buf(struct mgebuffer *m_buf)
Print a buffer object to stdout, (for debugging).
Definition: buffer.c:155
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.
Definition: buffer.c:74
struct mgebuffer * trim_buf(struct mgebuffer *msg_buf)
Remove processed data from a buffer object if deemed necessary.
Definition: buffer.c:114
Header file to ease portability.
#define BEGIN_C_DECLS
BEGIN_C_DECLS should be used at the beginning of declarations so that C++ compilers don't mangle thei...
Definition: mge-portability.h:48
#define END_C_DECLS
Use END_C_DECLS at the end of C declarations.
Definition: mge-portability.h:52
A buffer object.
Definition: mge-buffer.h:57
size_t next_free
Next free buffer location.
Definition: mge-buffer.h:61
size_t proc_next
Next buffer location for processing.
Definition: mge-buffer.h:60
size_t size
Size of the buffer storage area.
Definition: mge-buffer.h:59
char * buffer
Buffer storage.
Definition: mge-buffer.h:58