]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/snprintf.c
Update copyright years.
[thirdparty/gcc.git] / libiberty / snprintf.c
CommitLineData
bd3fbc6b 1/* Implement the snprintf function.
a945c346 2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
bd3fbc6b
KG
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
996c0cb0
RW
28@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, @
29 const char *@var{format}, ...)
bd3fbc6b 30
ec5c6f4a
EZ
31This function is similar to @code{sprintf}, but it will write to
32@var{buf} at most @code{@var{n}-1} bytes of text, followed by a
33terminating null byte, for a total of @var{n} bytes.
34On error the return value is -1, otherwise it returns the number of
35bytes, not including the terminating null byte, that would have been
36written had @var{n} been sufficiently large, regardless of the actual
37value of @var{n}. Note some pre-C99 system libraries do not implement
38this correctly so users cannot generally rely on the return value if
39the system version of this function is used.
bd3fbc6b
KG
40
41@end deftypefn
42
43*/
44
45#include "ansidecl.h"
46
bd3fbc6b
KG
47#include <stdarg.h>
48#include <stddef.h>
bd3fbc6b 49
885f2199 50int vsnprintf (char *, size_t, const char *, va_list);
bd3fbc6b
KG
51
52int
885f2199 53snprintf (char *s, size_t n, const char *format, ...)
bd3fbc6b
KG
54{
55 int result;
d2d21de9
TT
56 va_list ap;
57 va_start (ap, format);
bd3fbc6b 58 result = vsnprintf (s, n, format, ap);
d2d21de9 59 va_end (ap);
bd3fbc6b
KG
60 return result;
61}