]>
Commit | Line | Data |
---|---|---|
688903eb | 1 | /* Copyright (C) 1993-2018 Free Software Foundation, Inc. |
41bdb6e2 | 2 | This file is part of the GNU C Library. |
40a55d20 | 3 | |
41bdb6e2 AJ |
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. | |
40a55d20 | 8 | |
41bdb6e2 AJ |
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 | |
40a55d20 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
41bdb6e2 AJ |
12 | Lesser General Public License for more details. |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. | |
41bdb6e2 AJ |
17 | |
18 | As a special exception, if you link the code in this file with | |
19 | files compiled with a GNU compiler to produce an executable, | |
20 | that does not cause the resulting executable to be covered by | |
21 | the GNU Lesser General Public License. This exception does not | |
22 | however invalidate any other reasons why the executable file | |
23 | might be covered by the GNU Lesser General Public License. | |
24 | This exception applies to code released by its copyright holders | |
25 | in files containing the exception. */ | |
96aa2d94 RM |
26 | |
27 | #include "libioP.h" | |
28 | #include "strfile.h" | |
29 | ||
4e2f43f8 ZW |
30 | static int __THROW |
31 | _IO_str_chk_overflow (FILE *fp, int c) | |
32 | { | |
33 | /* If we get here, the user-supplied buffer would be overrun by | |
34 | further output. */ | |
35 | __chk_fail (); | |
36 | } | |
37 | ||
38 | static const struct _IO_jump_t _IO_str_chk_jumps libio_vtable = | |
39 | { | |
40 | JUMP_INIT_DUMMY, | |
41 | JUMP_INIT(finish, _IO_str_finish), | |
42 | JUMP_INIT(overflow, _IO_str_chk_overflow), | |
43 | JUMP_INIT(underflow, _IO_str_underflow), | |
44 | JUMP_INIT(uflow, _IO_default_uflow), | |
45 | JUMP_INIT(pbackfail, _IO_str_pbackfail), | |
46 | JUMP_INIT(xsputn, _IO_default_xsputn), | |
47 | JUMP_INIT(xsgetn, _IO_default_xsgetn), | |
48 | JUMP_INIT(seekoff, _IO_str_seekoff), | |
49 | JUMP_INIT(seekpos, _IO_default_seekpos), | |
50 | JUMP_INIT(setbuf, _IO_default_setbuf), | |
51 | JUMP_INIT(sync, _IO_default_sync), | |
52 | JUMP_INIT(doallocate, _IO_default_doallocate), | |
53 | JUMP_INIT(read, _IO_default_read), | |
54 | JUMP_INIT(write, _IO_default_write), | |
55 | JUMP_INIT(seek, _IO_default_seek), | |
56 | JUMP_INIT(close, _IO_default_close), | |
57 | JUMP_INIT(stat, _IO_default_stat), | |
58 | JUMP_INIT(showmanyc, _IO_default_showmanyc), | |
59 | JUMP_INIT(imbue, _IO_default_imbue) | |
60 | }; | |
61 | ||
62 | /* This function is called by regular vsprintf with maxlen set to -1, | |
63 | and by vsprintf_chk with maxlen set to the size of the output | |
64 | string. In the former case, _IO_str_chk_overflow will never be | |
65 | called; in the latter case it will crash the program if the buffer | |
66 | overflows. */ | |
67 | ||
96aa2d94 | 68 | int |
4e2f43f8 ZW |
69 | __vsprintf_internal (char *string, size_t maxlen, |
70 | const char *format, va_list args, | |
698fb75b | 71 | unsigned int mode_flags) |
96aa2d94 RM |
72 | { |
73 | _IO_strfile sf; | |
74 | int ret; | |
edf5b2d7 | 75 | |
499e7464 | 76 | #ifdef _IO_MTSAFE_IO |
c020d48c | 77 | sf._sbf._f._lock = NULL; |
499e7464 | 78 | #endif |
c020d48c | 79 | _IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL); |
4e2f43f8 ZW |
80 | _IO_JUMPS (&sf._sbf) = &_IO_str_chk_jumps; |
81 | string[0] = '\0'; | |
82 | _IO_str_init_static_internal (&sf, string, | |
83 | (maxlen == -1) ? -1 : maxlen - 1, | |
84 | string); | |
85 | ||
698fb75b | 86 | ret = __vfprintf_internal (&sf._sbf._f, format, args, mode_flags); |
4e2f43f8 ZW |
87 | |
88 | *sf._sbf._f._IO_write_ptr = '\0'; | |
96aa2d94 RM |
89 | return ret; |
90 | } | |
91 | ||
698fb75b ZW |
92 | int |
93 | __vsprintf (char *string, const char *format, va_list args) | |
94 | { | |
4e2f43f8 | 95 | return __vsprintf_internal (string, -1, format, args, 0); |
698fb75b ZW |
96 | } |
97 | ||
98 | ldbl_strong_alias (__vsprintf, _IO_vsprintf) | |
99 | ldbl_weak_alias (__vsprintf, vsprintf) |