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