OSDN Git Service

a9722c2352036f93150af2b03ce94f26d65c2b41
[pf3gnuchains/pf3gnuchains4x.git] / winsup / mingw / mingwex / stdio / vsnprintf.c
1 /* vsnprintf.c
2  *
3  * $Id$
4  *
5  * Provides an implementation of the "vsnprintf" function, conforming
6  * generally to C99 and SUSv3/POSIX specifications, with extensions
7  * to support Microsoft's non-standard format specifications.  This
8  * is included in libmingwex.a, replacing the redirection through
9  * libmoldnames.a, to the MSVCRT standard "_vsnprintf" function; (the
10  * standard MSVCRT function remains available, and may  be invoked
11  * directly, using this fully qualified form of its name).
12  *
13  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
14  *
15  * This is free software.  You may redistribute and/or modify it as you
16  * see fit, without restriction of copyright.
17  *
18  * This software is provided "as is", in the hope that it may be useful,
19  * but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
20  * MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE.  At no
21  * time will the author accept any form of liability for any damages,
22  * however caused, resulting from the use of this software.
23  *
24  */
25
26 #include <stdio.h>
27 #include <stdarg.h>
28
29 #include "pformat.h"
30
31 int __cdecl __vsnprintf (char *, size_t, const char *fmt, va_list) __MINGW_NOTHROW;
32 int __cdecl __mingw_alias(vsnprintf) (char *, size_t, const char *, va_list) __MINGW_NOTHROW;
33
34 int __cdecl __vsnprintf( char *buf, size_t length, const char *fmt, va_list argv )
35 {
36   register int retval;
37
38   if( length == (size_t)(0) )
39     /*
40      * No buffer; simply compute and return the size required,
41      * without actually emitting any data.
42      */
43     return __pformat( 0, buf, 0, fmt, argv );
44
45   /* If we get to here, then we have a buffer...
46    * Emit data up to the limit of buffer length less one,
47    * then add the requisite NUL terminator.
48    */
49   retval = __pformat( 0, buf, --length, fmt, argv );
50   buf[retval < length ? retval : length] = '\0';
51
52   return retval;
53 }
54
55 /* $RCSfile$Revision$: end of file */