1 /* Copyright (C) 2005-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>.
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, see
17 <https://www.gnu.org/licenses/>. */
27 locked_vfxprintf (FILE *fp
, const char *fmt
, va_list ap
,
28 unsigned int mode_flags
)
30 if (_IO_fwide (fp
, 0) <= 0)
31 return __vfprintf_internal (fp
, fmt
, ap
, mode_flags
);
33 /* We must convert the narrow format string to a wide one.
34 Each byte can produce at most one wide character. */
39 size_t len
= strlen (fmt
) + 1;
41 if (__glibc_unlikely (len
> SIZE_MAX
/ sizeof (wchar_t)))
43 __set_errno (EOVERFLOW
);
46 if (__libc_use_alloca (len
* sizeof (wchar_t)))
47 wfmt
= alloca (len
* sizeof (wchar_t));
48 else if ((wfmt
= malloc (len
* sizeof (wchar_t))) == NULL
)
53 memset (&mbstate
, 0, sizeof mbstate
);
54 res
= __mbsrtowcs (wfmt
, &fmt
, len
, &mbstate
);
57 res
= __vfwprintf_internal (fp
, wfmt
, ap
, mode_flags
);
66 __vfxprintf (FILE *fp
, const char *fmt
, va_list ap
,
67 unsigned int mode_flags
)
72 int res
= locked_vfxprintf (fp
, fmt
, ap
, mode_flags
);
78 __fxprintf (FILE *fp
, const char *fmt
, ...)
82 int res
= __vfxprintf (fp
, fmt
, ap
, 0);
88 __fxprintf_nocancel (FILE *fp
, const char *fmt
, ...)
96 int save_flags2
= fp
->_flags2
;
97 fp
->_flags2
|= _IO_FLAGS2_NOTCANCEL
;
99 int res
= locked_vfxprintf (fp
, fmt
, ap
, 0);
101 fp
->_flags2
= save_flags2
;
102 _IO_funlockfile (fp
);