]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/libio.h
stdlib/Makefile: Remove deleted test's libm dependency
[thirdparty/glibc.git] / libio / libio.h
CommitLineData
26420023 1/* Copyright (C) 1991-2025 Free Software Foundation, Inc.
48a8f832 2 This file is part of the GNU C Library.
48a8f832
ZW
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
5a82c748 16 <https://www.gnu.org/licenses/>.
48a8f832
ZW
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
6c6c962a
ZW
27#ifndef _LIBIO_H
28#define _LIBIO_H 1
29
30#ifndef _LIBC
31# error "libio.h should only be included when building glibc itself"
32#endif
33#ifdef _ISOMAC
34# error "libio.h should not be included under _ISOMAC"
35#endif
48a8f832 36
a4fea3f2 37#include <stdio.h>
48a8f832 38
6c6c962a
ZW
39#if defined _IO_MTSAFE_IO && !defined _IO_lock_t_defined
40# error "Someone forgot to include stdio-lock.h"
41#endif
42
63fb8f9a
ZW
43#define __need_wchar_t
44#include <stddef.h>
45
46#include <bits/types/__mbstate_t.h>
47#include <bits/types/wint_t.h>
48#include <gconv.h>
49
70c6e156 50typedef struct
63fb8f9a 51{
70c6e156
FW
52 struct __gconv_step *step;
53 struct __gconv_step_data step_data;
63fb8f9a
ZW
54} _IO_iconv_t;
55
6c6c962a
ZW
56#include <shlib-compat.h>
57
df6c012b 58/* _IO_seekoff modes */
48a8f832
ZW
59#define _IOS_INPUT 1
60#define _IOS_OUTPUT 2
48a8f832 61
df6c012b
ZW
62/* Magic number and bits for the _flags field. The magic number is
63 mostly vestigial, but preserved for compatibility. It occupies the
64 high 16 bits of _flags; the low 16 bits are actual flag bits. */
65
66#define _IO_MAGIC 0xFBAD0000 /* Magic number */
67#define _IO_MAGIC_MASK 0xFFFF0000
68#define _IO_USER_BUF 0x0001 /* Don't deallocate buffer on close. */
69#define _IO_UNBUFFERED 0x0002
70#define _IO_NO_READS 0x0004 /* Reading not allowed. */
71#define _IO_NO_WRITES 0x0008 /* Writing not allowed. */
72#define _IO_EOF_SEEN 0x0010
73#define _IO_ERR_SEEN 0x0020
74#define _IO_DELETE_DONT_CLOSE 0x0040 /* Don't call close(_fileno) on close. */
75#define _IO_LINKED 0x0080 /* In the list of all open files. */
76#define _IO_IN_BACKUP 0x0100
77#define _IO_LINE_BUF 0x0200
78#define _IO_TIED_PUT_GET 0x0400 /* Put and get pointer move in unison. */
79#define _IO_CURRENTLY_PUTTING 0x0800
80#define _IO_IS_APPENDING 0x1000
81#define _IO_IS_FILEBUF 0x2000
82 /* 0x4000 No longer used, reserved for compat. */
83#define _IO_USER_LOCK 0x8000
84
85/* Bits for the _flags2 field. */
48a8f832
ZW
86#define _IO_FLAGS2_MMAP 1
87#define _IO_FLAGS2_NOTCANCEL 2
48a8f832 88#define _IO_FLAGS2_USER_WBUF 8
34957904
ZW
89#define _IO_FLAGS2_NOCLOSE 32
90#define _IO_FLAGS2_CLOEXEC 64
91#define _IO_FLAGS2_NEED_LOCK 128
48a8f832 92
30bfee26
ZW
93/* _IO_pos_BAD is an off64_t value indicating error, unknown, or EOF. */
94#define _IO_pos_BAD ((off64_t) -1)
95
96/* _IO_pos_adjust adjusts an off64_t by some number of bytes. */
97#define _IO_pos_adjust(pos, delta) ((pos) += (delta))
98
99/* _IO_pos_0 is an off64_t value indicating beginning of file. */
100#define _IO_pos_0 ((off64_t) 0)
48a8f832 101
a4fea3f2 102struct _IO_jump_t;
48a8f832
ZW
103
104/* A streammarker remembers a position in a buffer. */
48a8f832
ZW
105struct _IO_marker {
106 struct _IO_marker *_next;
9964a145 107 FILE *_sbuf;
48a8f832
ZW
108 /* If _pos >= 0
109 it points to _buf->Gbase()+_pos. FIXME comment */
110 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
111 int _pos;
48a8f832
ZW
112};
113
48a8f832
ZW
114struct _IO_codecvt
115{
48a8f832
ZW
116 _IO_iconv_t __cd_in;
117 _IO_iconv_t __cd_out;
118};
119
120/* Extra data for wide character streams. */
121struct _IO_wide_data
122{
123 wchar_t *_IO_read_ptr; /* Current read pointer */
124 wchar_t *_IO_read_end; /* End of get area. */
125 wchar_t *_IO_read_base; /* Start of putback+get area. */
126 wchar_t *_IO_write_base; /* Start of put area. */
127 wchar_t *_IO_write_ptr; /* Current put pointer. */
128 wchar_t *_IO_write_end; /* End of put area. */
129 wchar_t *_IO_buf_base; /* Start of reserve area. */
130 wchar_t *_IO_buf_end; /* End of reserve area. */
131 /* The following fields are used to support backing up and undo. */
132 wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */
133 wchar_t *_IO_backup_base; /* Pointer to first valid character of
134 backup area */
135 wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
136
137 __mbstate_t _IO_state;
138 __mbstate_t _IO_last_state;
139 struct _IO_codecvt _codecvt;
140
141 wchar_t _shortbuf[1];
142
143 const struct _IO_jump_t *_wide_vtable;
144};
48a8f832 145
48a8f832
ZW
146struct _IO_FILE_plus;
147
148extern struct _IO_FILE_plus _IO_2_1_stdin_;
149extern struct _IO_FILE_plus _IO_2_1_stdout_;
150extern struct _IO_FILE_plus _IO_2_1_stderr_;
48a8f832
ZW
151
152struct _IO_cookie_file;
153
154/* Initialize one of those. */
155extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
9964a145 156 void *__cookie, cookie_io_functions_t __fns);
48a8f832 157
9964a145
ZW
158extern int __underflow (FILE *);
159extern wint_t __wunderflow (FILE *);
160extern wint_t __wuflow (FILE *);
161extern wint_t __woverflow (FILE *, wint_t);
48a8f832 162
a4fea3f2 163#define _IO_getc_unlocked(_fp) __getc_unlocked_body (_fp)
177aad3f
ZW
164#define _IO_peekc_unlocked(_fp) \
165 (__glibc_unlikely ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end) \
166 && __underflow (_fp) == EOF \
167 ? EOF \
168 : *(unsigned char *) (_fp)->_IO_read_ptr)
a4fea3f2 169#define _IO_putc_unlocked(_ch, _fp) __putc_unlocked_body (_ch, _fp)
48a8f832 170
177aad3f
ZW
171# define _IO_getwc_unlocked(_fp) \
172 (__glibc_unlikely ((_fp)->_wide_data == NULL \
173 || ((_fp)->_wide_data->_IO_read_ptr \
174 >= (_fp)->_wide_data->_IO_read_end)) \
9964a145 175 ? __wuflow (_fp) : (wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
177aad3f
ZW
176# define _IO_putwc_unlocked(_wch, _fp) \
177 (__glibc_unlikely ((_fp)->_wide_data == NULL \
178 || ((_fp)->_wide_data->_IO_write_ptr \
179 >= (_fp)->_wide_data->_IO_write_end)) \
48a8f832 180 ? __woverflow (_fp, _wch) \
9964a145 181 : (wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
48a8f832 182
a4fea3f2
ZW
183#define _IO_feof_unlocked(_fp) __feof_unlocked_body (_fp)
184#define _IO_ferror_unlocked(_fp) __ferror_unlocked_body (_fp)
48a8f832 185
9964a145
ZW
186extern int _IO_getc (FILE *__fp);
187extern int _IO_putc (int __c, FILE *__fp);
188extern int _IO_feof (FILE *__fp) __THROW;
189extern int _IO_ferror (FILE *__fp) __THROW;
48a8f832 190
9964a145 191extern int _IO_peekc_locked (FILE *__fp);
48a8f832
ZW
192
193/* This one is for Emacs. */
194#define _IO_PENDING_OUTPUT_COUNT(_fp) \
195 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
196
9964a145
ZW
197extern void _IO_flockfile (FILE *) __THROW;
198extern void _IO_funlockfile (FILE *) __THROW;
199extern int _IO_ftrylockfile (FILE *) __THROW;
48a8f832
ZW
200
201#define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
202#define _IO_flockfile(_fp) /**/
05383720 203#define _IO_funlockfile(_fp) ((void) 0)
48a8f832
ZW
204#define _IO_ftrylockfile(_fp) /**/
205#ifndef _IO_cleanup_region_start
206#define _IO_cleanup_region_start(_fct, _fp) /**/
207#endif
208#ifndef _IO_cleanup_region_end
209#define _IO_cleanup_region_end(_Doit) /**/
210#endif
211
212#define _IO_need_lock(_fp) \
213 (((_fp)->_flags2 & _IO_FLAGS2_NEED_LOCK) != 0)
214
9964a145
ZW
215extern int _IO_vfscanf (FILE * __restrict, const char * __restrict,
216 __gnuc_va_list, int *__restrict);
9964a145
ZW
217extern __ssize_t _IO_padn (FILE *, int, __ssize_t);
218extern size_t _IO_sgetn (FILE *, void *, size_t);
48a8f832 219
9964a145
ZW
220extern off64_t _IO_seekoff (FILE *, off64_t, int, int);
221extern off64_t _IO_seekpos (FILE *, off64_t, int);
48a8f832 222
9964a145 223extern void _IO_free_backup_area (FILE *) __THROW;
48a8f832 224
6c6c962a 225
9964a145
ZW
226extern wint_t _IO_getwc (FILE *__fp);
227extern wint_t _IO_putwc (wchar_t __wc, FILE *__fp);
228extern int _IO_fwide (FILE *__fp, int __mode) __THROW;
6c6c962a 229
6c6c962a
ZW
230#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
231# define _IO_fwide_maybe_incompatible \
177aad3f 232 (__glibc_unlikely (&_IO_stdin_used == NULL))
48a8f832
ZW
233extern const int _IO_stdin_used;
234weak_extern (_IO_stdin_used);
6c6c962a
ZW
235#else
236# define _IO_fwide_maybe_incompatible (0)
237#endif
238
48a8f832
ZW
239/* A special optimized version of the function above. It optimizes the
240 case of initializing an unoriented byte stream. */
6c6c962a 241#define _IO_fwide(__fp, __mode) \
48a8f832
ZW
242 ({ int __result = (__mode); \
243 if (__result < 0 && ! _IO_fwide_maybe_incompatible) \
244 { \
245 if ((__fp)->_mode == 0) \
246 /* We know that all we have to do is to set the flag. */ \
247 (__fp)->_mode = -1; \
248 __result = (__fp)->_mode; \
249 } \
250 else if (__builtin_constant_p (__mode) && (__mode) == 0) \
251 __result = _IO_fwide_maybe_incompatible ? -1 : (__fp)->_mode; \
252 else \
253 __result = _IO_fwide (__fp, __result); \
254 __result; })
48a8f832 255
9964a145
ZW
256extern __ssize_t _IO_wpadn (FILE *, wint_t, __ssize_t);
257extern void _IO_free_wbackup_area (FILE *) __THROW;
48a8f832
ZW
258
259#ifdef __LDBL_COMPAT
6c6c962a 260__LDBL_REDIR_DECL (_IO_vfscanf)
48a8f832
ZW
261#endif
262
6c6c962a
ZW
263libc_hidden_proto (__overflow)
264libc_hidden_proto (__underflow)
265libc_hidden_proto (__uflow)
266libc_hidden_proto (__woverflow)
267libc_hidden_proto (__wunderflow)
268libc_hidden_proto (__wuflow)
269libc_hidden_proto (_IO_free_backup_area)
270libc_hidden_proto (_IO_free_wbackup_area)
271libc_hidden_proto (_IO_padn)
272libc_hidden_proto (_IO_putc)
273libc_hidden_proto (_IO_sgetn)
6c6c962a
ZW
274
275#ifdef _IO_MTSAFE_IO
276# undef _IO_peekc
277# undef _IO_flockfile
278# undef _IO_funlockfile
279# undef _IO_ftrylockfile
280
281# define _IO_peekc(_fp) _IO_peekc_locked (_fp)
57094e57 282# define _IO_flockfile(_fp) \
6c6c962a 283 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock)
57094e57 284# define _IO_funlockfile(_fp) \
6c6c962a 285 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock)
6c6c962a
ZW
286#endif /* _IO_MTSAFE_IO */
287
6c6c962a 288#endif /* _LIBIO_H */