1 /* Copyright (C) 1991, 1995, 1997, 1998, 2004, 2006, 2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include "../libio/libioP.h"
23 #include "../libio/strfile.h"
25 extern const struct _IO_jump_t _IO_strn_jumps attribute_hidden
;
27 /* Write formatted output into S, according to the format
28 string FORMAT, writing no more than MAXLEN characters. */
31 ___vsnprintf_chk (char *s
, size_t maxlen
, int flags
, size_t slen
,
32 const char *format
, va_list args
)
34 /* XXX Maybe for less strict version do not fail immediately.
35 Though, maxlen is supposed to be the size of buffer pointed
36 to by s, so a conforming program can't pass such maxlen
38 if (__builtin_expect (slen
< maxlen
, 0))
44 sf
.f
._sbf
._f
._lock
= NULL
;
47 /* We need to handle the special case where MAXLEN is 0. Use the
48 overflow buffer right from the start. */
52 maxlen
= sizeof (sf
.overflow_buf
);
55 _IO_no_init (&sf
.f
._sbf
._f
, _IO_USER_LOCK
, -1, NULL
, NULL
);
56 _IO_JUMPS (&sf
.f
._sbf
) = &_IO_strn_jumps
;
59 /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
60 can only come from read-only format strings. */
62 sf
.f
._sbf
._f
._flags2
|= _IO_FLAGS2_FORTIFY
;
64 _IO_str_init_static_internal (&sf
.f
, s
, maxlen
- 1, s
);
65 ret
= INTUSE(_IO_vfprintf
) (&sf
.f
._sbf
._f
, format
, args
);
67 if (sf
.f
._sbf
._f
._IO_buf_base
!= sf
.overflow_buf
)
68 *sf
.f
._sbf
._f
._IO_write_ptr
= '\0';
71 ldbl_hidden_def (___vsnprintf_chk
, __vsnprintf_chk
)
72 ldbl_strong_alias (___vsnprintf_chk
, __vsnprintf_chk
)