libio: Convert __vsprintf_internal to buffers
[glibc.git] / stdio-common / printf_buffer_flush.c
blobf44c8b887f76e9ca20a7a9eaacb652dc64c733b6
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.
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/>. */
19 #include <errno.h>
20 #include <printf_buffer.h>
22 #include "printf_buffer-char.h"
23 #include "Xprintf_buffer_flush.c"
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 */
35 static void
36 __printf_buffer_do_flush (struct __printf_buffer *buf)
38 switch (buf->mode)
40 case __printf_buffer_mode_failed:
41 case __printf_buffer_mode_sprintf:
42 return;
43 case __printf_buffer_mode_snprintf:
44 __printf_buffer_flush_snprintf ((struct __printf_buffer_snprintf *) buf);
45 return;
46 case __printf_buffer_mode_sprintf_chk:
47 __chk_fail ();
48 break;
49 case __printf_buffer_mode_to_file:
50 __printf_buffer_flush_to_file ((struct __printf_buffer_to_file *) buf);
51 return;
52 case __printf_buffer_mode_strfmon:
53 __set_errno (E2BIG);
54 __printf_buffer_mark_failed (buf);
55 return;
56 case __printf_buffer_mode_fp:
57 __printf_buffer_flush_fp ((struct __printf_buffer_fp *) buf);
58 return;
59 case __printf_buffer_mode_fp_to_wide:
60 __printf_buffer_flush_fp_to_wide
61 ((struct __printf_buffer_fp_to_wide *) buf);
62 return;
63 case __printf_buffer_mode_fphex_to_wide:
64 __printf_buffer_flush_fphex_to_wide
65 ((struct __printf_buffer_fphex_to_wide *) buf);
66 return;
68 __builtin_trap ();