MGE General C Library - API Documentation
Library of general C functions.
mgebuffer.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  * *
38  ************************************************************************
39  */
40 
41 #ifndef MGEBUFFER_H
42 #define MGEBUFFER_H
43 
44 #include <portability.h>
45 #include <sys/types.h>
46 
48 
52 struct mgebuffer {
53  char *buffer;
54  size_t size;
55  size_t proc_next;
56  size_t next_free;
57 };
58 
62 #define MGEBUFFER_INIT \
63  { \
64  .buffer = NULL, .size = 0, .proc_next = 0, .next_free = 0 \
65  }
66 
67 struct mgebuffer *concat_buf(const char *s_buf, const size_t s_buf_os,
68  struct mgebuffer *m_buf);
69 
70 struct mgebuffer *trim_buf(struct mgebuffer *msg_buf);
71 
72 void print_buf(struct mgebuffer *m_buf);
73 
75 
76 #endif /* ndef MGEBUFFER_H */
77 
A buffer object.
Definition: mgebuffer.h:52
Header file to ease portability.
size_t size
Size of the buffer storage area.
Definition: mgebuffer.h:54
void print_buf(struct mgebuffer *m_buf)
Print a buffer object to stdout, (for debugging).
Definition: buffer.c:150
#define END_C_DECLS
Use END_C_DECLS at the end of C declarations.
Definition: portability.h:50
struct mgebuffer * trim_buf(struct mgebuffer *msg_buf)
Remove processed data from a buffer object if deemed necessary.
Definition: buffer.c:109
#define BEGIN_C_DECLS
BEGIN_C_DECLS should be used at the beginning of declarations so that C++ compilers don't mangle thei...
Definition: portability.h:46
size_t proc_next
Next buffer location for processing.
Definition: mgebuffer.h:55
size_t next_free
Next free buffer location.
Definition: mgebuffer.h:56
char * buffer
Buffer storage.
Definition: mgebuffer.h:53
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:70