From 653ff2c34ebe14ab5420e29f1bd329d296484c44 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 16 Feb 2019 12:29:00 -0600 Subject: [PATCH] Restore lib_sprintf(). It was removed because I thought was not used. But I was wrong; there is logic in drivers/syslog that depends on lib_sprintf(). This commits reverts a part of commit c271151d570e3ec394a45a78a81631c8c0328d92. That commit also removed lib_sscanf() which really is not needed. --- include/nuttx/streams.h | 11 ++++++ libs/libc/stdio/Make.defs | 6 +-- libs/libc/stdio/lib_libsprintf.c | 63 ++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 libs/libc/stdio/lib_libsprintf.c diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index 383efaf4c8b..68178288221 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -442,6 +442,17 @@ int lib_noflush(FAR struct lib_outstream_s *stream); int lib_snoflush(FAR struct lib_sostream_s *this); +/**************************************************************************** + * Name: lib_sprintf + * + * Description: + * Stream-oriented implementation of sprintf. Used only by the SYSLOG. + * + ****************************************************************************/ + +int lib_sprintf(FAR struct lib_outstream_s *obj, + FAR const IPTR char *fmt, ...); + /**************************************************************************** * Name: lib_vsprintf * diff --git a/libs/libc/stdio/Make.defs b/libs/libc/stdio/Make.defs index 97e91af03f1..e1463c36949 100644 --- a/libs/libc/stdio/Make.defs +++ b/libs/libc/stdio/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # libs/libc/stdio/Make.defs # -# Copyright (C) 2011-2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2014, 2019 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,8 +37,8 @@ # This first group of C files do not depend on having C streams. CSRCS += lib_fileno.c lib_printf.c lib_sprintf.c lib_asprintf.c -CSRCS += lib_snprintf.c lib_vsprintf.c lib_vasprintf.c lib_vsnprintf.c -CSRCS += lib_dprintf.c lib_vdprintf.c +CSRCS += lib_snprintf.c lib_libsprintf.c lib_vsprintf.c lib_vasprintf.c +CSRCS += lib_vsnprintf.c lib_dprintf.c lib_vdprintf.c CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c CSRCS += lib_memsostream.c lib_lowoutstream.c CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c diff --git a/libs/libc/stdio/lib_libsprintf.c b/libs/libc/stdio/lib_libsprintf.c new file mode 100644 index 00000000000..4d92143ec20 --- /dev/null +++ b/libs/libc/stdio/lib_libsprintf.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * libs/libc/stdio/lib_libsprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include "libc.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_sprintf + ****************************************************************************/ + +int lib_sprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *fmt, + ...) +{ + va_list ap; + int n; + + /* Let lib_vsprintf do the real work */ + + va_start(ap, fmt); + n = lib_vsprintf(obj, fmt, ap); + va_end(ap); + return n; +}