Function rcutils_format_string_limit
Defined in File format_string.h
Function Documentation
-
char *rcutils_format_string_limit(rcutils_allocator_t allocator, size_t limit, const char *format_string, ...)
Return a newly allocated string, created with a format string up to a limit.
This function uses snprintf_s to determine the length of the resulting string and allocates storage for the resulting string, formats it, and then returns the result.
This function can fail and therefore return null if the format_string is null or if memory allocation fails or if snprintf_s fails. An error message is not set in any case.
Output strings that would be longer than the given limit are truncated.
All returned strings are null terminated.
The format string is passed to snprintf_s(), see its documentation for how to use the format string.
The returned string must be deallocated using the same allocator given once it is no longer needed.
See also
- Parameters:
allocator – [in] the allocator to use for allocation
limit – [in] maximum length of the output string
format_string – [in] format of the output, must be null terminated
- Returns:
The newly allocated and format output string, or
- Returns:
NULL
if there was an error.