Mercurial > hg > CbC > CbC_gcc
annotate libiberty/snprintf.c @ 68:561a7518be6b
update gcc-4.6
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Aug 2011 07:07:55 +0900 |
parents | f6334be47118 |
children | 04ced10e8804 |
rev | line source |
---|---|
0 | 1 /* Implement the snprintf function. |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2 Copyright (C) 2003, 2011 Free Software Foundation, Inc. |
0 | 3 Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>. |
4 | |
5 This file is part of the libiberty library. This library is free | |
6 software; you can redistribute it and/or modify it under the | |
7 terms of the GNU General Public License as published by the | |
8 Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This library is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU CC; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | |
20 As a special exception, if you link this library with files | |
21 compiled with a GNU compiler to produce an executable, this does not cause | |
22 the resulting executable to be covered by the GNU General Public License. | |
23 This exception does not however invalidate any other reasons why | |
24 the executable file might be covered by the GNU General Public License. */ | |
25 | |
26 /* | |
27 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
28 @deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, @ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
29 const char *@var{format}, ...) |
0 | 30 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
31 This function is similar to @code{sprintf}, but it will write to |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
32 @var{buf} at most @code{@var{n}-1} bytes of text, followed by a |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
33 terminating null byte, for a total of @var{n} bytes. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
34 On error the return value is -1, otherwise it returns the number of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
35 bytes, not including the terminating null byte, that would have been |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
36 written had @var{n} been sufficiently large, regardless of the actual |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
37 value of @var{n}. Note some pre-C99 system libraries do not implement |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
38 this correctly so users cannot generally rely on the return value if |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
39 the system version of this function is used. |
0 | 40 |
41 @end deftypefn | |
42 | |
43 */ | |
44 | |
45 #include "ansidecl.h" | |
46 | |
47 #include <stdarg.h> | |
48 #include <stddef.h> | |
49 | |
50 int vsnprintf (char *, size_t, const char *, va_list); | |
51 | |
52 int | |
53 snprintf (char *s, size_t n, const char *format, ...) | |
54 { | |
55 int result; | |
56 VA_OPEN (ap, format); | |
57 VA_FIXEDARG (ap, char *, s); | |
58 VA_FIXEDARG (ap, size_t, n); | |
59 VA_FIXEDARG (ap, const char *, format); | |
60 result = vsnprintf (s, n, format, ap); | |
61 VA_CLOSE (ap); | |
62 return result; | |
63 } |