@@ -39,19 +39,21 @@ extern "C"
39
39
#include "rcutils/testing/fault_injection.h"
40
40
#include "rcutils/types/rcutils_ret.h"
41
41
#include "rcutils/visibility_control.h"
42
+ #include "rcutils/configuration_flags.h"
42
43
43
- #ifdef __STDC_LIB_EXT1__
44
+ #if defined( __STDC_LIB_EXT1__ ) && !defined( RCUTILS_NO_FILESYSTEM )
44
45
/// Write the given msg out to stderr, limiting the buffer size in the `fwrite`.
45
46
/**
46
47
* This ensures that there is an upper bound to a buffer overrun if `msg` is
47
48
* non-null terminated.
48
49
*/
49
50
#define RCUTILS_SAFE_FWRITE_TO_STDERR (msg ) \
50
51
do {fwrite(msg, sizeof(char), strnlen_s(msg, 4096), stderr);} while (0)
51
- #else
52
- /// Write the given msg out to stderr.
52
+ #elif !defined(RCUTILS_NO_FILESYSTEM )
53
53
#define RCUTILS_SAFE_FWRITE_TO_STDERR (msg ) \
54
54
do {fwrite(msg, sizeof(char), strlen(msg), stderr);} while (0)
55
+ #else
56
+ #define RCUTILS_SAFE_FWRITE_TO_STDERR (msg )
55
57
#endif
56
58
57
59
/// Set the error message to stderr using a format string and format arguments.
@@ -63,6 +65,8 @@ extern "C"
63
65
* \param[in] format_string The string to be used as the format of the error message.
64
66
* \param[in] ... Arguments for the format string.
65
67
*/
68
+
69
+ #if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION )
66
70
#define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING (format_string , ...) \
67
71
do { \
68
72
char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \
@@ -73,7 +77,11 @@ extern "C"
73
77
RCUTILS_SAFE_FWRITE_TO_STDERR(output_msg); \
74
78
} \
75
79
} while (0)
80
+ #else
81
+ #define RCUTILS_SAFE_FWRITE_TO_STDERR_WITH_FORMAT_STRING (format_string , ...)
82
+ #endif
76
83
84
+ #if !defined(RCUTILS_AVOID_DYNAMIC_ALLOCATION )
77
85
/// The maximum length a formatted number is allowed to have.
78
86
#define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 20 // "18446744073709551615"
79
87
@@ -100,6 +108,13 @@ extern "C"
100
108
RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH - \
101
109
RCUTILS_ERROR_FORMATTING_CHARACTERS - \
102
110
1)
111
+ #else
112
+ #define RCUTILS_ERROR_STATE_LINE_NUMBER_STR_MAX_LENGTH 1
113
+ #define RCUTILS_ERROR_FORMATTING_CHARACTERS 1
114
+ #define RCUTILS_ERROR_MESSAGE_MAX_LENGTH 1
115
+ #define RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH 1
116
+ #define RCUTILS_ERROR_STATE_FILE_MAX_LENGTH 1
117
+ #endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
103
118
104
119
/// Struct wrapping a fixed-size c string used for returning the formatted error string.
105
120
typedef struct rcutils_error_string_s
@@ -121,7 +136,7 @@ typedef struct rcutils_error_state_s
121
136
} rcutils_error_state_t ;
122
137
123
138
// make sure our math is right...
124
- #if __STDC_VERSION__ >= 201112L
139
+ #if __STDC_VERSION__ >= 201112L && !defined( RCUTILS_AVOID_DYNAMIC_ALLOCATION )
125
140
static_assert (
126
141
sizeof (rcutils_error_string_t ) == (
127
142
RCUTILS_ERROR_STATE_MESSAGE_MAX_LENGTH +
@@ -233,8 +248,12 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
233
248
*
234
249
* \param[in] msg The error message to be set.
235
250
*/
251
+ #ifdef RCUTILS_AVOID_DYNAMIC_ALLOCATION
252
+ #define RCUTILS_SET_ERROR_MSG (msg )
253
+ #else
236
254
#define RCUTILS_SET_ERROR_MSG (msg ) \
237
255
do {rcutils_set_error_state(msg, __FILE__, __LINE__);} while (0)
256
+ #endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
238
257
239
258
/// Set the error message using a format string and format arguments.
240
259
/**
@@ -245,6 +264,9 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
245
264
* \param[in] format_string The string to be used as the format of the error message.
246
265
* \param[in] ... Arguments for the format string.
247
266
*/
267
+ #ifdef RCUTILS_AVOID_DYNAMIC_ALLOCATION
268
+ #define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING (format_string , ...)
269
+ #else
248
270
#define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING (format_string , ...) \
249
271
do { \
250
272
char output_msg[RCUTILS_ERROR_MESSAGE_MAX_LENGTH]; \
@@ -255,6 +277,8 @@ rcutils_set_error_state(const char * error_string, const char * file, size_t lin
255
277
RCUTILS_SET_ERROR_MSG(output_msg); \
256
278
} \
257
279
} while (0)
280
+ #endif // RCUTILS_AVOID_DYNAMIC_ALLOCATION
281
+
258
282
259
283
/// Indicate that the function intends to set an error message and return an error value.
260
284
/**
0 commit comments