MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / format_string

Function format_string

erpcgen/src/format_string.cpp:39–69  ·  view source on GitHub ↗

The purpose of this function to provide a convenient way of generating formatted STL strings inline. This is especially useful when throwing exceptions that take a std::string for a message. The length of the formatted output string is limited only by memory. Memory temporarily allocated for the output string is disposed of before returning. For Win32, the maximum output size is 2048 characters.

Source from the content-addressed store, hash-verified

37//! \param fmt Format string using printf-style format markers.
38//! \return An STL string object of the formatted output.
39std::string format_string(const char *fmt, ...)
40{
41 char *buf = 0;
42 va_list vargs;
43 va_start(vargs, fmt);
44 int result;
45#if WIN32 || __CYGWIN__
46 buf = (char *)malloc(WIN32_FMT_BUF_LEN);
47 if (buf)
48 {
49#if WIN32
50 result = _vsnprintf(buf, WIN32_FMT_BUF_LEN, fmt, vargs);
51#else //__CYGWIN__
52 result = vsnprintf(buf, WIN32_FMT_BUF_LEN, fmt, vargs);
53#endif // WIN32
54 }
55 else
56 {
57 result = -1;
58 }
59#else
60 result = vasprintf(&buf, fmt, vargs);
61#endif // WIN32 __CYGWIN__
62 va_end(vargs);
63 if (result != -1 && buf)
64 {
65 smart_free_ptr<char> freebuf(buf);
66 return std::string(buf);
67 }
68 return "";
69}

Callers 15

handleRootMethod · 0.85
handleEnumMemberMethod · 0.85
handleBinaryOpMethod · 0.85
handleUnaryOpMethod · 0.85
handleStructMethod · 0.85
handleStructMemberMethod · 0.85
handleUnionMethod · 0.85
handleUnionCaseMethod · 0.85
handleInterfaceMethod · 0.85
handleFunctionMethod · 0.85
handleParamMethod · 0.85
setParameterDirectionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected