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

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2021-08-24 22:14:23 +08:00 committed by Xiang Xiao
parent 2438403f23
commit dfb4b6e3d8
2 changed files with 19 additions and 0 deletions

View File

@ -104,6 +104,12 @@
typedef struct file_struct FILE;
struct va_format
{
FAR const char *fmt;
FAR va_list *va;
};
/****************************************************************************
* Public Data
****************************************************************************/

View File

@ -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);