avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] [RFC] Joerg's new vsprint functions.


From: Mike Panetta
Subject: Re: [avr-libc-dev] [RFC] Joerg's new vsprint functions.
Date: 18 Nov 2003 17:39:42 -0500

I'll see if I can test it tomorrow, since I was kinda the one that
asked...

Mike

On Tue, 2003-11-18 at 14:40, Theodore A. Roth wrote:
> Hi,
> 
> Has anyone but Joerg given the new vsprintf functions a test drive yet?
> I'd like to hear some noise on this before I commit the attached to the
> 1.0 branch. I'm hoping to spin the 1.0.2 release over the weekend and I
> don't see any reason not to include this (except for minimal exposure to
> the users up to now).
> 
> Ted Roth
> ----
> 

> 2003-11-18 Joerg Wunsch <address@hidden>
> 
>       * include/stdio.h: Implement missing stdio members: vsprintf(),
>               vsprintf_P(), vsnprintf(), vsnprintf_P()
>       * libc/stdio/Makefile.am: ditto.
>       * libc/stdio/vsprintf.c: New file.
>       * libc/stdio/vsprintf_p.c: New file.
>       * libc/stdio/vsnprintf.c: New file.
>       * libc/stdio/vsnprintf_p.c: New file.
> 
> Index: include/stdio.h
> ===================================================================
> RCS file: /cvsroot/avr-libc/avr-libc/include/stdio.h,v
> retrieving revision 1.11.2.2
> diff -u -p -r1.11.2.2 stdio.h
> --- include/stdio.h   16 Oct 2003 20:45:31 -0000      1.11.2.2
> +++ include/stdio.h   18 Nov 2003 19:14:49 -0000
> @@ -429,6 +429,33 @@ extern int       snprintf(char *__s, size_t __
>  extern int   snprintf_P(char *__s, size_t __n, const char *__fmt, ...);
>  
>  /**
> +   Like \c sprintf() but takes a variable argument list for the
> +   arguments.
> +*/
> +extern int   vsprintf(char *__s, const char *__fmt, va_list ap);
> +
> +/**
> +   Variant of \c vsprintf() that uses a \c fmt string that resides
> +   in program memory.
> +*/
> +extern int   vsprintf_P(char *__s, const char *__fmt, va_list ap);
> +
> +/**
> +   Like \c vsprintf(), but instead of assuming \c s to be of infinite
> +   size, no more than \c n characters (including the trailing NUL
> +   character) will be converted to \c s.
> +
> +   Returns the number of characters that would have been written to
> +   \c s if there were enough space.
> +*/
> +extern int   vsnprintf(char *__s, size_t __n, const char *__fmt, va_list ap);
> +
> +/**
> +   Variant of \c vsnprintf() that uses a \c fmt string that resides
> +   in program memory.
> +*/
> +extern int   vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list 
> ap);
> +/**
>     The function \c fprintf performs formatted output to \c stream.
>     See \c vfprintf() for details.
>  */
> Index: libc/stdio/Makefile.am
> ===================================================================
> RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/Makefile.am,v
> retrieving revision 1.9.2.1
> diff -u -p -r1.9.2.1 Makefile.am
> --- libc/stdio/Makefile.am    16 Oct 2003 20:45:31 -0000      1.9.2.1
> +++ libc/stdio/Makefile.am    18 Nov 2003 19:14:49 -0000
> @@ -66,6 +66,10 @@ lib_a_c_sources =  \
>       sscanf_p.c      \
>       vfprintf_p.c    \
>       vfscanf_p.c     \
> +     vsnprintf.c     \
> +     vsnprintf_p.c   \
> +     vsprintf.c      \
> +     vsprintf_p.c    \
>       ungetc.c
>  
>  lib_a_asm_sources =  \
> Index: libc/stdio/vsnprintf.c
> ===================================================================
> RCS file: libc/stdio/vsnprintf.c
> diff -N libc/stdio/vsnprintf.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ libc/stdio/vsnprintf.c    18 Nov 2003 19:14:49 -0000
> @@ -0,0 +1,54 @@
> +/* Copyright (c) 2003, Joerg Wunsch
> +   All rights reserved.
> +
> +   Redistribution and use in source and binary forms, with or without
> +   modification, are permitted provided that the following conditions are 
> met:
> +
> +   * Redistributions of source code must retain the above copyright
> +     notice, this list of conditions and the following disclaimer.
> +   * 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.
> +   * Neither the name of the copyright holders nor the names of
> +     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.
> +*/
> +
> +/* $Id: vsnprintf.c,v 1.1 2003/11/12 20:50:03 joerg_wunsch Exp $ */
> +
> +#include <limits.h>
> +#include <stdarg.h>
> +#include <stdio.h>
> +
> +#include "stdio_private.h"
> +
> +int
> +vsnprintf(char *s, size_t n, const char *fmt, va_list ap)
> +{
> +     FILE f;
> +     int i;
> +
> +     f.flags = __SWR | __SSTR;
> +     f.buf = s;
> +     if (n > (size_t)INT_MAX)
> +             f.size = INT_MAX;
> +     else
> +             f.size = (int)n - 1;
> +     i = vfprintf(&f, fmt, ap);
> +     s[i < f.size? i: f.size] = 0;
> +
> +     return i;
> +}
> Index: libc/stdio/vsnprintf_p.c
> ===================================================================
> RCS file: libc/stdio/vsnprintf_p.c
> diff -N libc/stdio/vsnprintf_p.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ libc/stdio/vsnprintf_p.c  18 Nov 2003 19:14:49 -0000
> @@ -0,0 +1,54 @@
> +/* Copyright (c) 2003, Joerg Wunsch
> +   All rights reserved.
> +
> +   Redistribution and use in source and binary forms, with or without
> +   modification, are permitted provided that the following conditions are 
> met:
> +
> +   * Redistributions of source code must retain the above copyright
> +     notice, this list of conditions and the following disclaimer.
> +   * 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.
> +   * Neither the name of the copyright holders nor the names of
> +     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.
> +*/
> +
> +/* $Id: vsnprintf_p.c,v 1.1 2003/11/12 20:50:03 joerg_wunsch Exp $ */
> +
> +#include <limits.h>
> +#include <stdarg.h>
> +#include <stdio.h>
> +
> +#include "stdio_private.h"
> +
> +int
> +vsnprintf_P(char *s, size_t n, const char *fmt, va_list ap)
> +{
> +     FILE f;
> +     int i;
> +
> +     f.flags = __SWR | __SSTR | __SPGM;
> +     f.buf = s;
> +     if (n > (size_t)INT_MAX)
> +             f.size = INT_MAX;
> +     else
> +             f.size = (int)n - 1;
> +     i = vfprintf(&f, fmt, ap);
> +     s[i < f.size? i: f.size] = 0;
> +
> +     return i;
> +}
> Index: libc/stdio/vsprintf.c
> ===================================================================
> RCS file: libc/stdio/vsprintf.c
> diff -N libc/stdio/vsprintf.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ libc/stdio/vsprintf.c     18 Nov 2003 19:14:49 -0000
> @@ -0,0 +1,51 @@
> +/* Copyright (c) 2003, Joerg Wunsch
> +   All rights reserved.
> +
> +   Redistribution and use in source and binary forms, with or without
> +   modification, are permitted provided that the following conditions are 
> met:
> +
> +   * Redistributions of source code must retain the above copyright
> +     notice, this list of conditions and the following disclaimer.
> +   * 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.
> +   * Neither the name of the copyright holders nor the names of
> +     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.
> +*/
> +
> +/* $Id: vsprintf.c,v 1.1 2003/11/12 20:50:03 joerg_wunsch Exp $ */
> +
> +#include <limits.h>
> +#include <stdarg.h>
> +#include <stdio.h>
> +
> +#include "stdio_private.h"
> +
> +int
> +vsprintf(char *s, const char *fmt, va_list ap)
> +{
> +     FILE f;
> +     int i;
> +
> +     f.flags = __SWR | __SSTR;
> +     f.buf = s;
> +     f.size = INT_MAX;
> +     i = vfprintf(&f, fmt, ap);
> +     s[f.len] = 0;
> +
> +     return i;
> +}
> Index: libc/stdio/vsprintf_p.c
> ===================================================================
> RCS file: libc/stdio/vsprintf_p.c
> diff -N libc/stdio/vsprintf_p.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ libc/stdio/vsprintf_p.c   18 Nov 2003 19:14:49 -0000
> @@ -0,0 +1,51 @@
> +/* Copyright (c) 2003, Joerg Wunsch
> +   All rights reserved.
> +
> +   Redistribution and use in source and binary forms, with or without
> +   modification, are permitted provided that the following conditions are 
> met:
> +
> +   * Redistributions of source code must retain the above copyright
> +     notice, this list of conditions and the following disclaimer.
> +   * 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.
> +   * Neither the name of the copyright holders nor the names of
> +     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.
> +*/
> +
> +/* $Id: vsprintf_p.c,v 1.1 2003/11/12 20:50:03 joerg_wunsch Exp $ */
> +
> +#include <limits.h>
> +#include <stdarg.h>
> +#include <stdio.h>
> +
> +#include "stdio_private.h"
> +
> +int
> +vsprintf_P(char *s, const char *fmt, va_list ap)
> +{
> +     FILE f;
> +     int i;
> +
> +     f.flags = __SWR | __SSTR | __SPGM;
> +     f.buf = s;
> +     f.size = INT_MAX;
> +     i = vfprintf(&f, fmt, ap);
> +     s[f.len] = 0;
> +
> +     return i;
> +}
> ----
> 

> _______________________________________________
> AVR-libc-dev mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/avr-libc-dev






reply via email to

[Prev in Thread] Current Thread [Next in Thread]