*** empty log message ***
[deliverable/binutils-gdb.git] / libiberty / snprintf.c
CommitLineData
2ed1e5cc
DD
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
979c05d3 18the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
2ed1e5cc
DD
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
8893fa20
DD
30This function is similar to @code{sprintf}, but it will write to
31@var{buf} at most @code{@var{n}-1} bytes of text, followed by a
32terminating null byte, for a total of @var{n} bytes.
33On error the return value is -1, otherwise it returns the number of
34bytes, not including the terminating null byte, that would have been
35written had @var{n} been sufficiently large, regardless of the actual
36value of @var{n}. Note some pre-C99 system libraries do not implement
37this correctly so users cannot generally rely on the return value if
38the system version of this function is used.
2ed1e5cc
DD
39
40@end deftypefn
41
42*/
43
44#include "ansidecl.h"
45
2ed1e5cc
DD
46#include <stdarg.h>
47#include <stddef.h>
2ed1e5cc 48
1e45deed 49int vsnprintf (char *, size_t, const char *, va_list);
2ed1e5cc
DD
50
51int
1e45deed 52snprintf (char *s, size_t n, const char *format, ...)
2ed1e5cc
DD
53{
54 int result;
55 VA_OPEN (ap, format);
56 VA_FIXEDARG (ap, char *, s);
57 VA_FIXEDARG (ap, size_t, n);
58 VA_FIXEDARG (ap, const char *, format);
59 result = vsnprintf (s, n, format, ap);
60 VA_CLOSE (ap);
61 return result;
62}
This page took 0.437345 seconds and 4 git commands to generate.