]> git.ipfire.org Git - thirdparty/glibc.git/blob - stdio-common/printf_buffer_flush.c
stdio-common: Convert vfprintf and related functions to buffers
[thirdparty/glibc.git] / stdio-common / printf_buffer_flush.c
1 /* Flush a struct __printf_buffer. Multibyte version.
2 Copyright (C) 2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <errno.h>
20 #include <printf_buffer.h>
21
22 #include "printf_buffer-char.h"
23 #include "Xprintf_buffer_flush.c"
24
25 /* The __printf_buffer_flush_* functions are defined together with
26 functions that are pulled in by strong references. */
27 #ifndef SHARED
28 # pragma weak __printf_buffer_flush_snprintf
29 # pragma weak __printf_buffer_flush_to_file
30 # pragma weak __printf_buffer_flush_fp
31 # pragma weak __printf_buffer_flush_fp_to_wide
32 # pragma weak __printf_buffer_flush_fphex_to_wide
33 #endif /* !SHARED */
34
35 static void
36 __printf_buffer_do_flush (struct __printf_buffer *buf)
37 {
38 switch (buf->mode)
39 {
40 case __printf_buffer_mode_failed:
41 return;
42 case __printf_buffer_mode_snprintf:
43 __printf_buffer_flush_snprintf ((struct __printf_buffer_snprintf *) buf);
44 return;
45 case __printf_buffer_mode_to_file:
46 __printf_buffer_flush_to_file ((struct __printf_buffer_to_file *) buf);
47 return;
48 case __printf_buffer_mode_strfmon:
49 __set_errno (E2BIG);
50 __printf_buffer_mark_failed (buf);
51 return;
52 case __printf_buffer_mode_fp:
53 __printf_buffer_flush_fp ((struct __printf_buffer_fp *) buf);
54 return;
55 case __printf_buffer_mode_fp_to_wide:
56 __printf_buffer_flush_fp_to_wide
57 ((struct __printf_buffer_fp_to_wide *) buf);
58 return;
59 case __printf_buffer_mode_fphex_to_wide:
60 __printf_buffer_flush_fphex_to_wide
61 ((struct __printf_buffer_fphex_to_wide *) buf);
62 return;
63 }
64 __builtin_trap ();
65 }