]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/snprintf.c
re PR other/35457 (Error building GCC trunk on CELL SPU)
[thirdparty/gcc.git] / libiberty / snprintf.c
CommitLineData
bd3fbc6b
KG
1/* Implement the snprintf function.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
4
5This file is part of the libiberty library. This library is free
6software; you can redistribute it and/or modify it under the
7terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11This library is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
ee58dffd 18the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
bd3fbc6b
KG
19
20As a special exception, if you link this library with files
21compiled with a GNU compiler to produce an executable, this does not cause
22the resulting executable to be covered by the GNU General Public License.
23This exception does not however invalidate any other reasons why
24the executable file might be covered by the GNU General Public License. */
25
26/*
27
28@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
29
30This function is similar to sprintf, but it will print at most @var{n}
31characters. On error the return value is -1, otherwise it returns the
32number of characters that would have been printed had @var{n} been
33sufficiently large, regardless of the actual value of @var{n}. Note
34some pre-C99 system libraries do not implement this correctly so users
35cannot generally rely on the return value if the system version of
36this function is used.
37
38@end deftypefn
39
40*/
41
42#include "ansidecl.h"
43
bd3fbc6b
KG
44#include <stdarg.h>
45#include <stddef.h>
bd3fbc6b 46
885f2199 47int vsnprintf (char *, size_t, const char *, va_list);
bd3fbc6b
KG
48
49int
885f2199 50snprintf (char *s, size_t n, const char *format, ...)
bd3fbc6b
KG
51{
52 int result;
53 VA_OPEN (ap, format);
54 VA_FIXEDARG (ap, char *, s);
55 VA_FIXEDARG (ap, size_t, n);
56 VA_FIXEDARG (ap, const char *, format);
57 result = vsnprintf (s, n, format, ap);
58 VA_CLOSE (ap);
59 return result;
60}