1 | /* Copyright (C) 1991-2025 Free Software Foundation, Inc. |
2 | Copyright The GNU Toolchain Authors. |
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 | #ifndef __struct_FILE_defined |
20 | #define __struct_FILE_defined 1 |
21 | |
22 | /* Caution: The contents of this file are not part of the official |
23 | stdio.h API. However, much of it is part of the official *binary* |
24 | interface, and therefore cannot be changed. */ |
25 | |
26 | #if defined _IO_USE_OLD_IO_FILE && !defined _LIBC |
27 | # error "_IO_USE_OLD_IO_FILE should only be defined when building libc itself" |
28 | #endif |
29 | |
30 | #if defined _IO_lock_t_defined && !defined _LIBC |
31 | # error "_IO_lock_t_defined should only be defined when building libc itself" |
32 | #endif |
33 | |
34 | #include <bits/types.h> |
35 | |
36 | struct _IO_FILE; |
37 | struct _IO_marker; |
38 | struct _IO_codecvt; |
39 | struct _IO_wide_data; |
40 | |
41 | /* During the build of glibc itself, _IO_lock_t will already have been |
42 | defined by internal headers. */ |
43 | #ifndef _IO_lock_t_defined |
44 | typedef void _IO_lock_t; |
45 | #endif |
46 | |
47 | /* The tag name of this struct is _IO_FILE to preserve historic |
48 | C++ mangled names for functions taking FILE* arguments. |
49 | That name should not be used in new code. */ |
50 | struct _IO_FILE |
51 | { |
52 | int _flags; /* High-order word is _IO_MAGIC; rest is flags. */ |
53 | |
54 | /* The following pointers correspond to the C++ streambuf protocol. */ |
55 | char *_IO_read_ptr; /* Current read pointer */ |
56 | char *_IO_read_end; /* End of get area. */ |
57 | char *_IO_read_base; /* Start of putback+get area. */ |
58 | char *_IO_write_base; /* Start of put area. */ |
59 | char *_IO_write_ptr; /* Current put pointer. */ |
60 | char *_IO_write_end; /* End of put area. */ |
61 | char *_IO_buf_base; /* Start of reserve area. */ |
62 | char *_IO_buf_end; /* End of reserve area. */ |
63 | |
64 | /* The following fields are used to support backing up and undo. */ |
65 | char *_IO_save_base; /* Pointer to start of non-current get area. */ |
66 | char *_IO_backup_base; /* Pointer to first valid character of backup area */ |
67 | char *_IO_save_end; /* Pointer to end of non-current get area. */ |
68 | |
69 | struct _IO_marker *_markers; |
70 | |
71 | struct _IO_FILE *_chain; |
72 | |
73 | int _fileno; |
74 | int _flags2:24; |
75 | /* Fallback buffer to use when malloc fails to allocate one. */ |
76 | char _short_backupbuf[1]; |
77 | __off_t _old_offset; /* This used to be _offset but it's too small. */ |
78 | |
79 | /* 1+column number of pbase(); 0 is unknown. */ |
80 | unsigned short _cur_column; |
81 | signed char _vtable_offset; |
82 | char _shortbuf[1]; |
83 | |
84 | _IO_lock_t *_lock; |
85 | #ifdef _IO_USE_OLD_IO_FILE |
86 | }; |
87 | |
88 | struct _IO_FILE_complete |
89 | { |
90 | struct _IO_FILE _file; |
91 | #endif |
92 | __off64_t _offset; |
93 | /* Wide character stream stuff. */ |
94 | struct _IO_codecvt *_codecvt; |
95 | struct _IO_wide_data *_wide_data; |
96 | struct _IO_FILE *_freeres_list; |
97 | void *_freeres_buf; |
98 | struct _IO_FILE **_prevchain; |
99 | int _mode; |
100 | /* Make sure we don't get into trouble again. */ |
101 | char _unused2[15 * sizeof (int) - 5 * sizeof (void *)]; |
102 | }; |
103 | |
104 | /* These macros are used by bits/stdio.h and internal headers. */ |
105 | #define __getc_unlocked_body(_fp) \ |
106 | (__glibc_unlikely ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end) \ |
107 | ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++) |
108 | |
109 | #define __putc_unlocked_body(_ch, _fp) \ |
110 | (__glibc_unlikely ((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \ |
111 | ? __overflow (_fp, (unsigned char) (_ch)) \ |
112 | : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch))) |
113 | |
114 | #define _IO_EOF_SEEN 0x0010 |
115 | #define __feof_unlocked_body(_fp) (((_fp)->_flags & _IO_EOF_SEEN) != 0) |
116 | |
117 | #define _IO_ERR_SEEN 0x0020 |
118 | #define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) |
119 | |
120 | #define _IO_USER_LOCK 0x8000 |
121 | /* Many more flag bits are defined internally. */ |
122 | |
123 | #endif |
124 | |