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