1 | /* Copyright (C) 1993-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) any later version. |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, see |
16 | <https://www.gnu.org/licenses/>. |
17 | |
18 | As a special exception, if you link the code in this file with |
19 | files compiled with a GNU compiler to produce an executable, |
20 | that does not cause the resulting executable to be covered by |
21 | the GNU Lesser General Public License. This exception does not |
22 | however invalidate any other reasons why the executable file |
23 | might be covered by the GNU Lesser General Public License. |
24 | This exception applies to code released by its copyright holders |
25 | in files containing the exception. */ |
26 | |
27 | #ifndef STRFILE_H_ |
28 | #define STRFILE_H_ |
29 | |
30 | #include "libioP.h" |
31 | |
32 | typedef void *(*_IO_alloc_type) (size_t); |
33 | typedef void (*_IO_free_type) (void*); |
34 | |
35 | struct _IO_str_fields |
36 | { |
37 | /* These members are preserved for ABI compatibility. The glibc |
38 | implementation always calls malloc/free for user buffers if |
39 | _IO_USER_BUF or _IO_FLAGS2_USER_WBUF are not set. */ |
40 | _IO_alloc_type _allocate_buffer_unused; |
41 | _IO_free_type _free_buffer_unused; |
42 | }; |
43 | |
44 | /* This is needed for the Irix6 N32 ABI, which has a 64 bit off_t type, |
45 | but a 32 bit pointer type. In this case, we get 4 bytes of padding |
46 | after the vtable pointer. Putting them in a structure together solves |
47 | this problem. */ |
48 | |
49 | struct _IO_streambuf |
50 | { |
51 | FILE _f; |
52 | const struct _IO_jump_t *vtable; |
53 | }; |
54 | |
55 | typedef struct _IO_strfile_ |
56 | { |
57 | struct _IO_streambuf _sbf; |
58 | struct _IO_str_fields _s; |
59 | } _IO_strfile; |
60 | |
61 | /* frozen: set when the program has requested that the array object not |
62 | be altered, reallocated, or freed. */ |
63 | #define _IO_STR_FROZEN(FP) ((FP)->_f._flags & _IO_USER_BUF) |
64 | |
65 | typedef struct |
66 | { |
67 | _IO_strfile f; |
68 | /* This is used for the characters which do not fit in the buffer |
69 | provided by the user. */ |
70 | char overflow_buf[64]; |
71 | } _IO_strnfile; |
72 | |
73 | extern const struct _IO_jump_t _IO_strn_jumps attribute_hidden; |
74 | |
75 | |
76 | typedef struct |
77 | { |
78 | _IO_strfile f; |
79 | /* This is used for the characters which do not fit in the buffer |
80 | provided by the user. */ |
81 | wchar_t overflow_buf[64]; |
82 | } _IO_wstrnfile; |
83 | |
84 | extern const struct _IO_jump_t _IO_wstrn_jumps attribute_hidden; |
85 | |
86 | /* Initialize an _IO_strfile SF to read from narrow string STRING, and |
87 | return the corresponding FILE object. It is not necessary to fclose |
88 | the FILE when it is no longer needed. */ |
89 | static inline FILE * |
90 | _IO_strfile_read (_IO_strfile *sf, const char *string) |
91 | { |
92 | sf->_sbf._f._lock = NULL; |
93 | _IO_no_init (&sf->_sbf._f, _IO_USER_LOCK, -1, NULL, NULL); |
94 | _IO_JUMPS (&sf->_sbf) = &_IO_str_jumps; |
95 | _IO_str_init_static_internal (sf, (char*)string, 0, NULL); |
96 | return &sf->_sbf._f; |
97 | } |
98 | |
99 | /* Initialize an _IO_strfile SF and _IO_wide_data WD to read from wide |
100 | string STRING, and return the corresponding FILE object. It is not |
101 | necessary to fclose the FILE when it is no longer needed. */ |
102 | static inline FILE * |
103 | _IO_strfile_readw (_IO_strfile *sf, struct _IO_wide_data *wd, |
104 | const wchar_t *string) |
105 | { |
106 | sf->_sbf._f._lock = NULL; |
107 | _IO_no_init (&sf->_sbf._f, _IO_USER_LOCK, 0, wd, &_IO_wstr_jumps); |
108 | _IO_fwide (&sf->_sbf._f, 1); |
109 | _IO_wstr_init_static (&sf->_sbf._f, (wchar_t *)string, 0, NULL); |
110 | return &sf->_sbf._f; |
111 | } |
112 | |
113 | #endif /* strfile.h. */ |
114 | |