luasandbox  1.4.0
Generic Lua sandbox for dynamic data analysis
output_buffer.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /** Data stream output buffer @file */
8 
9 #ifndef luasandbox_util_output_buffer_h_
10 #define luasandbox_util_output_buffer_h_
11 
12 #include <stdbool.h>
13 
14 #include "util.h"
15 
16 #define LSB_OUTPUT_SIZE 1024
17 
18 typedef struct lsb_output_buffer {
19  char *buf;
20  size_t maxsize;
21  size_t size;
22  size_t pos;
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30 /**
31  * Initialize the provided input buffer
32  *
33  * @param b Output buffer
34  * @param max_message_size The maximum message size the buffer will handle
35  * before erroring
36  *
37  * @return lsb_err_value NULL on success error message on failure
38  */
40 lsb_init_output_buffer(lsb_output_buffer *b, size_t max_message_size);
41 
42 /**
43  * Frees the memory internally allocated by the buffer and resets the state
44  *
45  * @param b Output buffer
46  */
48 
49 /**
50  * Resize the output buffer when more space is needed.
51  *
52  * @param b Output buffer to resize.
53  * @param needed Number of additional bytes needed.
54  *
55  * @return lsb_err_value NULL on success error message on failure
56  */
58  size_t needed);
59 
60 /**
61  * Append a character to the output buffer.
62  *
63  * @param b Pointer the b buffer.
64  * @param ch Character to append to the b.
65  *
66  * @return lsb_err_value NULL on success error message on failure
67  */
69 
70 /**
71  * Append a formatted string to the output buffer.
72  *
73  * @param b Pointer the b buffer.
74  * @param fmt Printf format specifier.
75  *
76  * @return lsb_err_value NULL on success error message on failure
77  */
79 lsb_outputf(lsb_output_buffer *b, const char *fmt, ...);
80 
81 /**
82  * Append a fixed string to the output buffer.
83  *
84  * @param b Pointer the b buffer.
85  * @param str String to append to the b.
86  * @param len Length of the string to append
87  *
88  * @return lsb_err_value NULL on success error message on failure
89  */
91 lsb_outputs(lsb_output_buffer *b, const char *str, size_t len);
92 
93 /**
94  * More efficient output of a double to a string. NaN/Inf check and then calls
95  * lsb_outputfd.
96  *
97  * @param b Pointer the output buffer.
98  * @param d Double value to convert to a string.
99  *
100  * @return lsb_err_value NULL on success error message on failure
101  */
103 
104 
105 /**
106  * More efficient output of a double to a string; no NaN or Inf outputs.
107  *
108  * @param b Pointer the output buffer.
109  * @param d Double value to convert to a string.
110  *
111  * @return lsb_err_value NULL on success error message on failure
112  */
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif
const char * lsb_err_value
Definition: error.h:15
LSB_UTIL_EXPORT lsb_err_value lsb_outputd(lsb_output_buffer *b, double d)
More efficient output of a double to a string.
LSB_UTIL_EXPORT lsb_err_value lsb_expand_output_buffer(lsb_output_buffer *b, size_t needed)
Resize the output buffer when more space is needed.
struct lsb_output_buffer lsb_output_buffer
LSB_UTIL_EXPORT void lsb_free_output_buffer(lsb_output_buffer *b)
Frees the memory internally allocated by the buffer and resets the state.
Shared types and structures.
#define LSB_UTIL_EXPORT
Definition: util.h:28
LSB_UTIL_EXPORT lsb_err_value lsb_outputfd(lsb_output_buffer *b, double d)
More efficient output of a double to a string; no NaN or Inf outputs.
LSB_UTIL_EXPORT lsb_err_value lsb_outputc(lsb_output_buffer *b, char ch)
Append a character to the output buffer.
LSB_UTIL_EXPORT lsb_err_value lsb_init_output_buffer(lsb_output_buffer *b, size_t max_message_size)
Initialize the provided input buffer.
LSB_UTIL_EXPORT lsb_err_value lsb_outputs(lsb_output_buffer *b, const char *str, size_t len)
Append a fixed string to the output buffer.
LSB_UTIL_EXPORT lsb_err_value lsb_outputf(lsb_output_buffer *b, const char *fmt,...)
Append a formatted string to the output buffer.