]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/stdio.h
Correct range checking in mallopt/mxfast/tcache [BZ #25194]
[thirdparty/glibc.git] / include / stdio.h
CommitLineData
6796bc80 1#ifndef _STDIO_H
a4fea3f2
ZW
2# if !defined _ISOMAC && defined _IO_MTSAFE_IO
3# include <stdio-lock.h>
4# endif
199fc19d
ZW
5# include <libio/stdio.h>
6# ifndef _ISOMAC
a4fea3f2 7# define _LIBC_STDIO_H 1
6c6c962a 8# include <libio/libio.h>
bdbf022d
UD
9
10/* Now define the internal interfaces. */
b15549e6 11
2e0a6909 12extern int __fcloseall (void) attribute_hidden;
aaa8d85c 13extern int __snprintf (char *__restrict __s, size_t __maxlen,
a784e502 14 const char *__restrict __format, ...)
bdbf022d 15 __attribute__ ((__format__ (__printf__, 3, 4)));
61158ffa 16libc_hidden_proto (__snprintf)
aaa8d85c 17extern int __vfscanf (FILE *__restrict __s,
a784e502 18 const char *__restrict __format,
63fb8f9a 19 __gnuc_va_list __arg)
bdbf022d 20 __attribute__ ((__format__ (__scanf__, 2, 0)));
a20d8dbe 21libc_hidden_proto (__vfscanf)
a784e502 22extern int __vscanf (const char *__restrict __format,
63fb8f9a 23 __gnuc_va_list __arg)
bdbf022d 24 __attribute__ ((__format__ (__scanf__, 1, 0)));
9964a145
ZW
25extern __ssize_t __getline (char **__lineptr, size_t *__n,
26 FILE *__stream) attribute_hidden;
a784e502
UD
27extern int __vsscanf (const char *__restrict __s,
28 const char *__restrict __format,
63fb8f9a 29 __gnuc_va_list __arg)
bfce746a 30 __attribute__ ((__format__ (__scanf__, 2, 0)));
bdbf022d 31
b5cc329c
UD
32extern int __sprintf_chk (char *, int, size_t, const char *, ...) __THROW;
33extern int __snprintf_chk (char *, size_t, int, size_t, const char *, ...)
34 __THROW;
35extern int __vsprintf_chk (char *, int, size_t, const char *,
63fb8f9a 36 __gnuc_va_list) __THROW;
b5cc329c 37extern int __vsnprintf_chk (char *, size_t, int, size_t, const char *,
63fb8f9a 38 __gnuc_va_list) __THROW;
b5cc329c
UD
39extern int __printf_chk (int, const char *, ...);
40extern int __fprintf_chk (FILE *, int, const char *, ...);
63fb8f9a
ZW
41extern int __vprintf_chk (int, const char *, __gnuc_va_list);
42extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_va_list);
553cc5f9
UD
43extern char *__fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp);
44extern char *__fgets_chk (char *buf, size_t size, int n, FILE *fp);
dff37515 45extern int __asprintf_chk (char **, int, const char *, ...) __THROW;
63fb8f9a 46extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW;
dff37515 47extern int __dprintf_chk (int, int, const char *, ...);
63fb8f9a 48extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list);
dff37515
UD
49extern int __obstack_printf_chk (struct obstack *, int, const char *, ...)
50 __THROW;
51extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
63fb8f9a 52 __gnuc_va_list) __THROW;
b5cc329c 53
874aa523 54extern int __isoc99_fscanf (FILE *__restrict __stream,
a784e502
UD
55 const char *__restrict __format, ...) __wur;
56extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
57extern int __isoc99_sscanf (const char *__restrict __s,
58 const char *__restrict __format, ...) __THROW;
874aa523 59extern int __isoc99_vfscanf (FILE *__restrict __s,
a784e502 60 const char *__restrict __format,
63fb8f9a 61 __gnuc_va_list __arg) __wur;
a784e502 62extern int __isoc99_vscanf (const char *__restrict __format,
63fb8f9a 63 __gnuc_va_list __arg) __wur;
a784e502
UD
64extern int __isoc99_vsscanf (const char *__restrict __s,
65 const char *__restrict __format,
63fb8f9a 66 __gnuc_va_list __arg) __THROW;
03992356 67libc_hidden_proto (__isoc99_sscanf)
874aa523
UD
68libc_hidden_proto (__isoc99_vsscanf)
69libc_hidden_proto (__isoc99_vfscanf)
70
03992356
ZW
71/* Internal uses of sscanf should call the C99-compliant version.
72 Unfortunately, symbol redirection is not transitive, so the
73 __REDIRECT in the public header does not link up with the above
74 libc_hidden_proto. Bridge the gap with a macro. */
75# if !__GLIBC_USE (DEPRECATED_SCANF)
76# undef sscanf
77# define sscanf __isoc99_sscanf
78# endif
79
ed073f0e
AJ
80/* Prototypes for compatibility functions. */
81extern FILE *__new_tmpfile (void);
82extern FILE *__old_tmpfile (void);
83
ab58d620
UD
84# define __need_size_t
85# include <stddef.h>
199fc19d
ZW
86
87# include <bits/types/wint_t.h>
88
992af677 89/* Generate a unique file name (and possibly open it). */
aaa8d85c 90extern int __path_search (char *__tmpl, size_t __tmpl_len,
a784e502 91 const char *__dir, const char *__pfx,
2e0a6909 92 int __try_tempdir) attribute_hidden;
992af677 93
7f3146e7 94extern int __gen_tempname (char *__tmpl, int __suffixlen, int __flags,
2e0a6909 95 int __kind) attribute_hidden;
2e65ca2b 96/* The __kind argument to __gen_tempname may be one of: */
ab58d620 97# define __GT_FILE 0 /* create a file */
d7e23b02
UD
98# define __GT_DIR 1 /* create a directory */
99# define __GT_NOCREATE 2 /* just find a name not currently in use */
992af677 100
ed421fca
L
101enum __libc_message_action
102{
103 do_message = 0, /* Print message. */
104 do_abort = 1 << 0, /* Abort. */
ed421fca
L
105};
106
a6e8926f
PP
107/* Print out MESSAGE (which should end with a newline) on the error output
108 and abort. */
a784e502 109extern void __libc_fatal (const char *__message)
992af677 110 __attribute__ ((__noreturn__));
ed421fca 111extern void __libc_message (enum __libc_message_action action,
2e0a6909 112 const char *__fnt, ...) attribute_hidden;
1b0bfc69 113extern void __fortify_fail (const char *msg) __attribute__ ((__noreturn__));
3a50811c 114libc_hidden_proto (__fortify_fail)
992af677 115
d4b0774f 116/* Acquire ownership of STREAM. */
2e0a6909 117extern void __flockfile (FILE *__stream) attribute_hidden;
d4b0774f
AJ
118
119/* Relinquish the ownership granted for STREAM. */
2e0a6909 120extern void __funlockfile (FILE *__stream) attribute_hidden;
d1646309 121
dd040747
AJ
122/* Try to acquire ownership of STREAM but do not block if it is not
123 possible. */
124extern int __ftrylockfile (FILE *__stream);
125
30ac923d 126extern int __getc_unlocked (FILE *__fp) attribute_hidden;
03bac9ac
AJ
127extern wint_t __getwc_unlocked (FILE *__fp);
128
8a259a23 129extern int __fxprintf (FILE *__fp, const char *__fmt, ...)
2e0a6909 130 __attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
544ce845 131extern int __fxprintf_nocancel (FILE *__fp, const char *__fmt, ...)
2e0a6909 132 __attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
f43b8dd5
GG
133int __vfxprintf (FILE *__fp, const char *__fmt, __gnuc_va_list,
134 unsigned int)
fdb16de3 135 attribute_hidden;
03bac9ac 136
3f5e3f5d
FW
137/* Read the next line from FP into BUFFER, of LENGTH bytes. LINE will
138 include the line terminator and a NUL terminator. On success,
139 return the length of the line, including the line terminator, but
140 excluding the NUL termintor. On EOF, return zero and write a NUL
141 terminator. On error, return -1 and set errno. If the total byte
142 count (line and both terminators) exceeds LENGTH, return -1 and set
143 errno to ERANGE (but do not mark the stream as failed).
144
145 The behavior is undefined if FP is not seekable, or if the stream
146 is already in an error state. */
147ssize_t __libc_readline_unlocked (FILE *fp, char *buffer, size_t length);
148libc_hidden_proto (__libc_readline_unlocked);
149
a784e502 150extern const char *const _sys_errlist_internal[] attribute_hidden;
1897bc3f 151extern int _sys_nerr_internal attribute_hidden;
77fe0b9c 152
d18ea0c5 153libc_hidden_proto (__asprintf)
4f41c682 154# if IS_IN (libc)
9964a145 155extern FILE *_IO_new_fopen (const char*, const char*);
3ba06713 156# define fopen(fname, mode) _IO_new_fopen (fname, mode)
9964a145 157extern FILE *_IO_new_fdopen (int, const char*);
3ba06713 158# define fdopen(fd, mode) _IO_new_fdopen (fd, mode)
9964a145 159extern int _IO_new_fclose (FILE*);
3ba06713 160# define fclose(fp) _IO_new_fclose (fp)
9964a145 161extern int _IO_fputs (const char*, FILE*);
3ba06713 162libc_hidden_proto (_IO_fputs)
499b3153
JM
163/* The compiler may optimize calls to fprintf into calls to fputs.
164 Use libc_hidden_proto to ensure that those calls, not redirected by
165 the fputs macro, also do not go through the PLT. */
166libc_hidden_proto (fputs)
3ba06713 167# define fputs(str, fp) _IO_fputs (str, fp)
9964a145 168extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
3ba06713 169# define fsetpos(fp, posp) _IO_new_fsetpos (fp, posp)
9964a145 170extern int _IO_new_fgetpos (FILE *, __fpos_t *);
3ba06713 171# define fgetpos(fp, posp) _IO_new_fgetpos (fp, posp)
6b87a564
UD
172# endif
173
b9b91868 174libc_hidden_proto (dprintf)
be7dc2b7
JM
175extern __typeof (dprintf) __dprintf
176 __attribute__ ((__format__ (__printf__, 2, 3)));
177libc_hidden_proto (__dprintf)
b9b91868
RM
178libc_hidden_proto (fprintf)
179libc_hidden_proto (vfprintf)
180libc_hidden_proto (sprintf)
b9b91868
RM
181libc_hidden_proto (fwrite)
182libc_hidden_proto (perror)
183libc_hidden_proto (remove)
184libc_hidden_proto (rewind)
3ba06713 185libc_hidden_proto (fileno)
5a6fa4d7
JM
186extern __typeof (fileno) __fileno;
187libc_hidden_proto (__fileno)
3ba06713
UD
188libc_hidden_proto (fwrite)
189libc_hidden_proto (fseek)
5a6fa4d7
JM
190extern __typeof (ftello) __ftello;
191libc_hidden_proto (__ftello)
3f5e3f5d
FW
192extern __typeof (fseeko64) __fseeko64;
193libc_hidden_proto (__fseeko64)
194extern __typeof (ftello64) __ftello64;
195libc_hidden_proto (__ftello64)
5182cbc5 196libc_hidden_proto (fflush)
3ba06713 197libc_hidden_proto (fflush_unlocked)
eb1fae6a
JM
198extern __typeof (fflush_unlocked) __fflush_unlocked;
199libc_hidden_proto (__fflush_unlocked)
5a6fa4d7
JM
200extern __typeof (fread_unlocked) __fread_unlocked;
201libc_hidden_proto (__fread_unlocked)
3ba06713
UD
202libc_hidden_proto (fwrite_unlocked)
203libc_hidden_proto (fgets_unlocked)
c4eae752
JM
204extern __typeof (fgets_unlocked) __fgets_unlocked;
205libc_hidden_proto (__fgets_unlocked)
3ba06713 206libc_hidden_proto (fputs_unlocked)
3164bf09
JM
207extern __typeof (fputs_unlocked) __fputs_unlocked;
208libc_hidden_proto (__fputs_unlocked)
7fc03cf3
JM
209libc_hidden_proto (feof_unlocked)
210extern __typeof (feof_unlocked) __feof_unlocked attribute_hidden;
ec481ad8
JM
211libc_hidden_proto (ferror_unlocked)
212extern __typeof (ferror_unlocked) __ferror_unlocked attribute_hidden;
30ac923d 213libc_hidden_proto (getc_unlocked)
039c721a
JM
214libc_hidden_proto (fputc_unlocked)
215libc_hidden_proto (putc_unlocked)
216extern __typeof (putc_unlocked) __putc_unlocked attribute_hidden;
a99e59d7 217libc_hidden_proto (fmemopen)
711f67a7 218/* The prototype needs repeating instead of using __typeof to use
3ac3ff32 219 __THROW in C++ tests. */
711f67a7
JM
220extern FILE *__open_memstream (char **, size_t *) __THROW __wur;
221libc_hidden_proto (__open_memstream)
9d79e037 222libc_hidden_proto (__libc_fatal)
2193ce87 223rtld_hidden_proto (__libc_fatal)
b5cc329c 224libc_hidden_proto (__vsprintf_chk)
b15549e6 225
fdb7d390
AZ
226extern FILE * __fmemopen (void *buf, size_t len, const char *mode);
227libc_hidden_proto (__fmemopen)
228
e0d2eb5a
AZ
229extern int __gen_tempfd (int flags);
230libc_hidden_proto (__gen_tempfd)
231
7fc03cf3
JM
232# ifdef __USE_EXTERN_INLINES
233__extern_inline int
234__NTH (__feof_unlocked (FILE *__stream))
235{
236 return __feof_unlocked_body (__stream);
237}
ec481ad8
JM
238
239__extern_inline int
240__NTH (__ferror_unlocked (FILE *__stream))
241{
242 return __ferror_unlocked_body (__stream);
243}
30ac923d
JM
244
245__extern_inline int
246__getc_unlocked (FILE *__fp)
247{
248 return __getc_unlocked_body (__fp);
249}
039c721a
JM
250
251__extern_inline int
252__putc_unlocked (int __c, FILE *__stream)
253{
254 return __putc_unlocked_body (__c, __stream);
255}
7fc03cf3
JM
256# endif
257
d6da5cb6
FW
258extern __typeof (renameat) __renameat;
259libc_hidden_proto (__renameat)
1b218417
ST
260extern __typeof (renameat2) __renameat2;
261libc_hidden_proto (__renameat2)
d6da5cb6 262
199fc19d
ZW
263# endif /* not _ISOMAC */
264#endif /* stdio.h */