123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /*
- * Copyright (c) 2006-2024, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2024-03-10 Meco Man the first version
- */
- #include <rtthread.h>
- /**
- * @brief This function will fill a formatted string to buffer.
- *
- * @param buf is the buffer to save formatted string.
- *
- * @param size is the size of buffer.
- *
- * @param fmt is the format parameters.
- *
- * @return The number of characters actually written to buffer.
- */
- int rt_snprintf(char *buf, rt_size_t size, const char *fmt, ...)
- {
- rt_int32_t n = 0;
- va_list args;
- va_start(args, fmt);
- n = rt_vsnprintf(buf, size, fmt, args);
- va_end(args);
- return n;
- }
- RTM_EXPORT(rt_snprintf);
- /**
- * @brief This function will fill a formatted string to buffer.
- *
- * @param buf is the buffer to save formatted string.
- *
- * @param format is the format parameters.
- *
- * @param arg_ptr is a list of variable parameters.
- *
- * @return The number of characters actually written to buffer.
- */
- int rt_vsprintf(char *buf, const char *format, va_list arg_ptr)
- {
- return rt_vsnprintf(buf, (rt_size_t) - 1, format, arg_ptr);
- }
- RTM_EXPORT(rt_vsprintf);
- /**
- * @brief This function will fill a formatted string to buffer
- *
- * @param buf the buffer to save formatted string.
- *
- * @param format is the format parameters.
- *
- * @return The number of characters actually written to buffer.
- */
- int rt_sprintf(char *buf, const char *format, ...)
- {
- rt_int32_t n = 0;
- va_list arg_ptr;
- va_start(arg_ptr, format);
- n = rt_vsprintf(buf, format, arg_ptr);
- va_end(arg_ptr);
- return n;
- }
- RTM_EXPORT(rt_sprintf);
- /**
- * @brief This function parses a formatted string from the input string.
- *
- * @param str the input string to be parsed.
- *
- * @param format the format string that specifies how to interpret the input.
- *
- * @return The number of input items successfully matched and assigned.
- */
- int rt_sscanf(const char *str, const char *format, ...)
- {
- va_list ap;
- int rv;
- va_start(ap, format);
- rv = rt_vsscanf(str, format, ap);
- va_end(ap);
- return rv;
- }
- RTM_EXPORT(rt_sscanf);
|