mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
lib_vsprintf: Add %pV format support
test case:
void test(const char *fmt, ...)
{
struct va_format vaf;
va_list ap;
va_start(ap, fmt);
vaf.fmt = fmt;
vaf.va = ≈
printf("func:%s, %pV, line:%d\n", __func__, &vaf, __LINE__);
va_end(ap);
}
int main(int argc, FAR char *argv[])
{
char str[] = "Hello Boy and Girl!";
int count = 10;
test("%s %d", str, count);
return 0;
}
>> test
func:test, Hello Boy and Girl! 10, line:49
Change-Id: I6d97515dce3f10a880145a1ff7fcba5e9cbebd37
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -104,6 +104,12 @@
|
||||
|
||||
typedef struct file_struct FILE;
|
||||
|
||||
struct va_format
|
||||
{
|
||||
FAR const char *fmt;
|
||||
FAR va_list *va;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
@@ -117,6 +117,8 @@
|
||||
# define fmt_char(fmt) (*(fmt)++)
|
||||
#endif
|
||||
|
||||
#define fmt_ungetc(fmt) ((fmt)--)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@@ -459,6 +461,17 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
|
||||
|
||||
if (c == 'p')
|
||||
{
|
||||
if (fmt_char(fmt) == 'V')
|
||||
{
|
||||
FAR struct va_format *vaf = va_arg(ap, void *);
|
||||
vsprintf_internal(stream, NULL, 0, vaf->fmt, *vaf->va);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt_ungetc(fmt);
|
||||
}
|
||||
|
||||
/* Determine size of pointer and set flags accordingly */
|
||||
|
||||
flags &= ~(FL_LONG | FL_REPD_TYPE);
|
||||
|
||||
Reference in New Issue
Block a user