libs/libc/stdio: In the recent changes we lost the implementation of vsscanf(). This commit restores vsscanf(). sscanf() is not just a front end for vsscanf().

This commit is contained in:
Gregory Nutt 2019-02-15 17:31:58 -06:00
parent d0bd4c959d
commit 928108036c
6 changed files with 27 additions and 37 deletions

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* include/stdio.h * include/stdio.h
* *
* Copyright (C) 2007-2009, 2011, 2013-2015, 2018 Gregory Nutt. All rights * Copyright (C) 2007-2009, 2011, 2013-2015, 2018-2019 Gregory Nutt. All
* reserved. * rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -158,6 +158,7 @@ int fputs(FAR const char *s, FAR FILE *stream);
size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream); size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
FAR FILE *freopen(FAR const char *path, FAR const char *mode, FAR FILE *freopen(FAR const char *path, FAR const char *mode,
FAR FILE *stream); FAR FILE *stream);
int fscanf(FAR FILE *stream, FAR const IPTR char *fmt, ...);
int fseek(FAR FILE *stream, long int offset, int whence); int fseek(FAR FILE *stream, long int offset, int whence);
int fsetpos(FAR FILE *stream, FAR fpos_t *pos); int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
long ftell(FAR FILE *stream); long ftell(FAR FILE *stream);
@ -168,31 +169,29 @@ FAR char *gets_s(FAR char *s, rsize_t n);
void setbuf(FAR FILE *stream, FAR char *buf); void setbuf(FAR FILE *stream, FAR char *buf);
int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size); int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size);
int ungetc(int c, FAR FILE *stream); int ungetc(int c, FAR FILE *stream);
int fscanf(FAR FILE *stream, FAR const IPTR char *format, ...);
/* Operations on the stdout stream, buffers, paths, and the whole printf-family */ /* Operations on the stdout stream, buffers, paths, and the whole printf-family */
int printf(FAR const IPTR char *format, ...); void perror(FAR const char *s);
int printf(FAR const IPTR char *fmt, ...);
int puts(FAR const char *s); int puts(FAR const char *s);
int rename(FAR const char *oldpath, FAR const char *newpath); int rename(FAR const char *oldpath, FAR const char *newpath);
int sprintf(FAR char *buf, FAR const IPTR char *format, ...); int sprintf(FAR char *buf, FAR const IPTR char *fmt, ...);
int asprintf (FAR char **ptr, FAR const IPTR char *fmt, ...); int asprintf (FAR char **ptr, FAR const IPTR char *fmt, ...);
int snprintf(FAR char *buf, size_t size, int snprintf(FAR char *buf, size_t size,
FAR const IPTR char *format, ...); FAR const IPTR char *fmt, ...);
int sscanf(FAR const char *buf, FAR const IPTR char *fmt, ...); int sscanf(FAR const char *buf, FAR const IPTR char *fmt, ...);
void perror(FAR const char *s);
int vprintf(FAR const IPTR FAR char *format, va_list ap); int scanf(FAR const IPTR char *fmt, ...);
int vfprintf(FAR FILE *stream, FAR const IPTR char *format,
va_list ap);
int vsprintf(FAR char *buf, FAR const IPTR char *format, va_list ap);
int vasprintf(FAR char **ptr, FAR const IPTR char *fmt, va_list ap); int vasprintf(FAR char **ptr, FAR const IPTR char *fmt, va_list ap);
int vsnprintf(FAR char *buf, size_t size, FAR const IPTR char *format, int vfprintf(FAR FILE *stream, FAR const IPTR char *fmt,
va_list ap); va_list ap);
int vsscanf(FAR const char *buf, FAR const char *s, va_list ap); int vfscanf(FAR FILE *stream, FAR const IPTR char *fmt, va_list ap);
int scanf(FAR const IPTR char *format, ...); int vprintf(FAR const IPTR FAR char *fmt, va_list ap);
int vfscanf(FAR FILE *stream, FAR const IPTR char *format, int vsnprintf(FAR char *buf, size_t size, FAR const IPTR char *fmt,
va_list ap); va_list ap);
int vsprintf(FAR char *buf, FAR const IPTR char *fmt, va_list ap);
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap);
/* Operations on file descriptors including: /* Operations on file descriptors including:
* *

View File

@ -43,7 +43,8 @@ CSRCS += lib_vsnprintf.c lib_dprintf.c lib_vdprintf.c
CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c
CSRCS += lib_memsostream.c lib_lowoutstream.c CSRCS += lib_memsostream.c lib_lowoutstream.c
CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c
CSRCS += lib_sscanf.c lib_libsscanf.c lib_libnoflush.c lib_libsnoflush.c CSRCS += lib_sscanf.c lib_vsscanf.c lib_libsscanf.c lib_libnoflush.c
CSRCS += lib_libsnoflush.c
ifeq ($(CONFIG_NANO_PRINTF),y) ifeq ($(CONFIG_NANO_PRINTF),y)

View File

@ -38,6 +38,8 @@
****************************************************************************/ ****************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#include "libc.h"
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -52,7 +54,7 @@ int fscanf(FAR FILE *stream, FAR const IPTR char *fmt, ...)
va_list ap; va_list ap;
int n; int n;
/* vfprintf into the stream */ /* vscanf from the stream */
va_start(ap, fmt); va_start(ap, fmt);
n = vfscanf(stream, fmt, ap); n = vfscanf(stream, fmt, ap);

View File

@ -52,6 +52,8 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/streams.h>
#include "libc.h" #include "libc.h"
/**************************************************************************** /****************************************************************************
@ -74,17 +76,6 @@
# define MAX(a,b) (((a) > (b)) ? (a) : (b)) # define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif #endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
FAR const IPTR char *fmt, va_list ap);
/****************************************************************************
* Private Data
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/

View File

@ -40,6 +40,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <nuttx/streams.h>
#include "libc.h" #include "libc.h"
/**************************************************************************** /****************************************************************************
@ -52,20 +53,14 @@
int sscanf(FAR const char *buf, FAR const IPTR char *fmt, ...) int sscanf(FAR const char *buf, FAR const IPTR char *fmt, ...)
{ {
struct lib_meminstream_s meminstream;
va_list ap; va_list ap;
int n; int n;
/* Initialize a memory stream to write to the buffer */ /* vsscanf from the buffer */
lib_meminstream((FAR struct lib_meminstream_s *)&meminstream, buf,
LIB_BUFLEN_UNKNOWN);
/* Then let lib_vsscanf do the real work */
va_start(ap, fmt); va_start(ap, fmt);
n = lib_vsscanf((FAR struct lib_instream_s *)&meminstream.public, NULL, n = vsscanf(buf, fmt, ap);
fmt, ap);
va_end(ap); va_end(ap);
return n; return n;
} }

View File

@ -42,6 +42,8 @@
#include <stdio.h> #include <stdio.h>
#include <semaphore.h> #include <semaphore.h>
#include <nuttx/streams.h>
#include "libc.h" #include "libc.h"
/**************************************************************************** /****************************************************************************