| 1 | /* Flush a struct __printf_buffer. Multibyte version. |
|---|---|
| 2 | Copyright (C) 2022-2023 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_asprintf |
| 31 | # pragma weak __printf_buffer_flush_dprintf |
| 32 | # pragma weak __printf_buffer_flush_fp |
| 33 | # pragma weak __printf_buffer_flush_fp_to_wide |
| 34 | # pragma weak __printf_buffer_flush_fphex_to_wide |
| 35 | # pragma weak __printf_buffer_flush_obstack |
| 36 | #endif /* !SHARED */ |
| 37 | |
| 38 | static void |
| 39 | __printf_buffer_do_flush (struct __printf_buffer *buf) |
| 40 | { |
| 41 | switch (buf->mode) |
| 42 | { |
| 43 | case __printf_buffer_mode_failed: |
| 44 | case __printf_buffer_mode_sprintf: |
| 45 | return; |
| 46 | case __printf_buffer_mode_snprintf: |
| 47 | __printf_buffer_flush_snprintf ((struct __printf_buffer_snprintf *) buf); |
| 48 | return; |
| 49 | case __printf_buffer_mode_sprintf_chk: |
| 50 | __chk_fail (); |
| 51 | break; |
| 52 | case __printf_buffer_mode_to_file: |
| 53 | __printf_buffer_flush_to_file ((struct __printf_buffer_to_file *) buf); |
| 54 | return; |
| 55 | case __printf_buffer_mode_asprintf: |
| 56 | __printf_buffer_flush_asprintf ((struct __printf_buffer_asprintf *) buf); |
| 57 | return; |
| 58 | case __printf_buffer_mode_dprintf: |
| 59 | __printf_buffer_flush_dprintf ((struct __printf_buffer_dprintf *) buf); |
| 60 | return; |
| 61 | case __printf_buffer_mode_strfmon: |
| 62 | __set_errno (E2BIG); |
| 63 | __printf_buffer_mark_failed (buf); |
| 64 | return; |
| 65 | case __printf_buffer_mode_fp: |
| 66 | __printf_buffer_flush_fp ((struct __printf_buffer_fp *) buf); |
| 67 | return; |
| 68 | case __printf_buffer_mode_fp_to_wide: |
| 69 | __printf_buffer_flush_fp_to_wide |
| 70 | ((struct __printf_buffer_fp_to_wide *) buf); |
| 71 | return; |
| 72 | case __printf_buffer_mode_fphex_to_wide: |
| 73 | __printf_buffer_flush_fphex_to_wide |
| 74 | ((struct __printf_buffer_fphex_to_wide *) buf); |
| 75 | return; |
| 76 | case __printf_buffer_mode_obstack: |
| 77 | __printf_buffer_flush_obstack ((struct __printf_buffer_obstack *) buf); |
| 78 | return; |
| 79 | } |
| 80 | __builtin_trap (); |
| 81 | } |
| 82 |