aboutsummaryrefslogtreecommitdiff
path: root/support/ToolchainSupport.h
diff options
context:
space:
mode:
Diffstat (limited to 'support/ToolchainSupport.h')
-rw-r--r--support/ToolchainSupport.h42
1 files changed, 38 insertions, 4 deletions
diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h
index b9d9103652..ab2a9fe80f 100644
--- a/support/ToolchainSupport.h
+++ b/support/ToolchainSupport.h
@@ -144,8 +144,8 @@ inline T trunc(T value)
* @note This function implements the same behaviour as std::copysign except that it doesn't
* support Integral type. The latter is not in the namespace std in some Android toolchains.
*
- * @param[in] x value that contains the magnitued to be used in constructing the result.
- * @param[in] y value that contains the sign to be used in constructin the result.
+ * @param[in] x value that contains the magnitude to be used in constructing the result.
+ * @param[in] y value that contains the sign to be used in construct in the result.
*
* @return Floating-point value with magnitude of @p x and sign of @p y.
*/
@@ -154,6 +154,23 @@ inline T copysign(T x, T y)
{
return ::copysign(x, y);
}
+
+/** Loads the data from the given location, converts them to character string equivalents
+ * and writes the result to a character string buffer.
+ *
+ * @param[in] s Pointer to a character string to write to
+ * @param[in] n Up to buf_size - 1 characters may be written, plus the null terminator
+ * @param[in] fmt Pointer to a null-terminated multibyte string specifying how to interpret the data.
+ * @param[in] args Arguments forwarded to snprintf.
+ *
+ * @return Number of characters that would have been written for a sufficiently large buffer
+ * if successful (not including the terminating null character), or a negative value if an error occurred.
+ */
+template <typename... Ts>
+inline int snprintf(char *s, size_t n, const char *fmt, Ts &&... args)
+{
+ return ::snprintf(s, n, fmt, std::forward<Ts>(args)...);
+}
#else /* (__ANDROID__ || BARE_METAL) */
/** Convert integer and float values to string.
*
@@ -250,8 +267,8 @@ inline T trunc(T value)
* @note This function implements the same behaviour as std::copysign except that it doesn't
* support Integral type. The latter is not in the namespace std in some Android toolchains.
*
- * @param[in] x value that contains the magnitued to be used in constructing the result.
- * @param[in] y value that contains the sign to be used in constructin the result.
+ * @param[in] x value that contains the magnitude to be used in constructing the result.
+ * @param[in] y value that contains the sign to be used in construct in the result.
*
* @return Floating-point value with magnitude of @p x and sign of @p y.
*/
@@ -260,6 +277,23 @@ inline T copysign(T x, T y)
{
return std::copysign(x, y);
}
+
+/** Loads the data from the given location, converts them to character string equivalents
+ * and writes the result to a character string buffer.
+ *
+ * @param[in] s Pointer to a character string to write to
+ * @param[in] n Up to buf_size - 1 characters may be written, plus the null terminator
+ * @param[in] fmt Pointer to a null-terminated multibyte string specifying how to interpret the data.
+ * @param[in] args Arguments forwarded to std::snprintf.
+ *
+ * @return Number of characters that would have been written for a sufficiently large buffer
+ * if successful (not including the terminating null character), or a negative value if an error occurred.
+ */
+template <typename... Ts>
+inline int snprintf(char *s, std::size_t n, const char *fmt, Ts &&... args)
+{
+ return std::snprintf(s, n, fmt, std::forward<Ts>(args)...);
+}
#endif /* (__ANDROID__ || BARE_METAL) */
inline std::string to_string(bool value)