1 /* Copyright (C) 1991-2016 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
20 #include "../libio/libioP.h"
21 #include "../libio/strfile.h"
23 extern const struct _IO_jump_t _IO_strn_jumps libio_vtable attribute_hidden
;
25 /* Write formatted output into S, according to the format
26 string FORMAT, writing no more than MAXLEN characters. */
29 ___vsnprintf_chk (char *s
, size_t maxlen
, int flags
, size_t slen
,
30 const char *format
, va_list args
)
32 /* XXX Maybe for less strict version do not fail immediately.
33 Though, maxlen is supposed to be the size of buffer pointed
34 to by s, so a conforming program can't pass such maxlen
36 if (__glibc_unlikely (slen
< maxlen
))
42 sf
.f
._sbf
._f
._lock
= NULL
;
45 /* We need to handle the special case where MAXLEN is 0. Use the
46 overflow buffer right from the start. */
50 maxlen
= sizeof (sf
.overflow_buf
);
53 _IO_no_init (&sf
.f
._sbf
._f
, _IO_USER_LOCK
, -1, NULL
, NULL
);
54 _IO_JUMPS (&sf
.f
._sbf
) = &_IO_strn_jumps
;
57 /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
58 can only come from read-only format strings. */
60 sf
.f
._sbf
._f
._flags2
|= _IO_FLAGS2_FORTIFY
;
62 _IO_str_init_static_internal (&sf
.f
, s
, maxlen
- 1, s
);
63 ret
= _IO_vfprintf (&sf
.f
._sbf
._f
, format
, args
);
65 if (sf
.f
._sbf
._f
._IO_buf_base
!= sf
.overflow_buf
)
66 *sf
.f
._sbf
._f
._IO_write_ptr
= '\0';
69 ldbl_hidden_def (___vsnprintf_chk
, __vsnprintf_chk
)
70 ldbl_strong_alias (___vsnprintf_chk
, __vsnprintf_chk
)