1 | /* FILE * interface to a struct __*printf_buffer. |
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 | /* Registered printf format specifier callbacks produce data via a |
20 | FILE * stream. struct __printf_buffer_as_file enables vfprintf to |
21 | create a suitable stdio stream. Likewise struct |
22 | __wprintf_buffer_as_file for vfwprintf. */ |
23 | |
24 | #ifndef PRINTF_BUFFER_AS_FILE_H |
25 | #define PRINTF_BUFFER_AS_FILE_H |
26 | |
27 | #include <libio/libioP.h> |
28 | |
29 | struct __printf_buffer; |
30 | |
31 | struct __printf_buffer_as_file |
32 | { |
33 | /* Interface to libio. */ |
34 | FILE stream; |
35 | const struct _IO_jump_t *vtable; |
36 | |
37 | /* Pointer to the underlying buffer. */ |
38 | struct __printf_buffer *next; |
39 | }; |
40 | |
41 | /* Initialization *FP so that data written to its FILE * stream ends |
42 | up in NEXT. */ |
43 | void __printf_buffer_as_file_init (struct __printf_buffer_as_file *fp, |
44 | struct __printf_buffer *next) |
45 | attribute_hidden; |
46 | |
47 | /* Returns the FILE * that can be used to write data to the |
48 | buffer. */ |
49 | static inline FILE * |
50 | __printf_buffer_as_file_get (struct __printf_buffer_as_file *file) |
51 | { |
52 | return &file->stream; |
53 | } |
54 | |
55 | /* Transfers all pending data from the FILE * to the underlying |
56 | buffer. Returns true if there have been no errors. */ |
57 | bool __printf_buffer_as_file_terminate (struct __printf_buffer_as_file *) |
58 | attribute_hidden; |
59 | |
60 | /* Wide variant follows. */ |
61 | |
62 | struct __wprintf_buffer; |
63 | struct __wprintf_buffer_as_file |
64 | { |
65 | /* Interface to libio. */ |
66 | FILE stream; |
67 | const struct _IO_jump_t *vtable; |
68 | struct _IO_wide_data wide_stream; |
69 | |
70 | /* Pointer to the underlying buffer. */ |
71 | struct __wprintf_buffer *next; |
72 | }; |
73 | |
74 | void __wprintf_buffer_as_file_init (struct __wprintf_buffer_as_file *fp, |
75 | struct __wprintf_buffer *next) |
76 | attribute_hidden; |
77 | |
78 | static inline FILE * |
79 | __wprintf_buffer_as_file_get (struct __wprintf_buffer_as_file *file) |
80 | { |
81 | return &file->stream; |
82 | } |
83 | |
84 | bool __wprintf_buffer_as_file_terminate (struct __wprintf_buffer_as_file *) |
85 | attribute_hidden; |
86 | |
87 | #endif /* PRINTF_BUFFER_AS_FILE_H */ |
88 | |