blob: 7c4f9ee499bcf50bca913777c03c03ca35cfce29 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _STDIO_H
2#define _STDIO_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Rich Felkerc1a96582012-09-07 23:13:55 -04008#include <features.h>
Rich Felker400c5e52012-09-06 22:44:55 -04009
Rich Felker0b44a032011-02-12 00:22:29 -050010#define __NEED_FILE
Rich Felkera3e2f3c2013-06-25 22:26:20 -040011#define __NEED___isoc_va_list
Rich Felker0b44a032011-02-12 00:22:29 -050012#define __NEED_size_t
Rich Felker80695b12011-02-14 05:10:10 -050013
14#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
Rich Felker419ae6d2012-05-22 21:52:08 -040015 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
16 || defined(_BSD_SOURCE)
Rich Felker0b44a032011-02-12 00:22:29 -050017#define __NEED_ssize_t
18#define __NEED_off_t
Rich Felkera3e2f3c2013-06-25 22:26:20 -040019#define __NEED_va_list
Rich Felker80695b12011-02-14 05:10:10 -050020#endif
Rich Felker0b44a032011-02-12 00:22:29 -050021
22#include <bits/alltypes.h>
23
Rich Felkerc8a9c222013-11-24 21:42:55 -050024#ifdef __cplusplus
Rich Felker41d7c772013-01-18 20:35:26 -050025#define NULL 0L
Rich Felkerc8a9c222013-11-24 21:42:55 -050026#else
27#define NULL ((void*)0)
28#endif
Rich Felker0b44a032011-02-12 00:22:29 -050029
30#undef EOF
31#define EOF (-1)
32
33#undef SEEK_SET
34#undef SEEK_CUR
35#undef SEEK_END
36#define SEEK_SET 0
37#define SEEK_CUR 1
38#define SEEK_END 2
39
40#define _IOFBF 0
41#define _IOLBF 1
42#define _IONBF 2
43
Rich Felker571312d2011-02-15 19:47:22 -050044#define BUFSIZ 1024
Rich Felkerb823ef22013-07-18 14:15:48 -040045#define FILENAME_MAX 4096
Rich Felker571312d2011-02-15 19:47:22 -050046#define FOPEN_MAX 1000
47#define TMP_MAX 10000
48#define L_tmpnam 20
Rich Felker0b44a032011-02-12 00:22:29 -050049
Rich Felker9448b052013-07-22 11:22:36 -040050typedef union _G_fpos64_t {
Rich Felker0b44a032011-02-12 00:22:29 -050051 char __opaque[16];
52 double __align;
53} fpos_t;
54
55extern FILE *const stdin;
56extern FILE *const stdout;
57extern FILE *const stderr;
58
59#define stdin (stdin)
60#define stdout (stdout)
61#define stderr (stderr)
62
Rich Felker400c5e52012-09-06 22:44:55 -040063FILE *fopen(const char *__restrict, const char *__restrict);
64FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050065int fclose(FILE *);
66
Rich Felker0b44a032011-02-12 00:22:29 -050067int remove(const char *);
68int rename(const char *, const char *);
69
Rich Felker0b44a032011-02-12 00:22:29 -050070int feof(FILE *);
71int ferror(FILE *);
72int fflush(FILE *);
73void clearerr(FILE *);
74
75int fseek(FILE *, long, int);
Rich Felker0b44a032011-02-12 00:22:29 -050076long ftell(FILE *);
Rich Felker0b44a032011-02-12 00:22:29 -050077void rewind(FILE *);
78
Rich Felker400c5e52012-09-06 22:44:55 -040079int fgetpos(FILE *__restrict, fpos_t *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050080int fsetpos(FILE *, const fpos_t *);
81
Rich Felker400c5e52012-09-06 22:44:55 -040082size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
83size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -050084
85int fgetc(FILE *);
86int getc(FILE *);
87int getchar(void);
88int ungetc(int, FILE *);
89
90int fputc(int, FILE *);
91int putc(int, FILE *);
92int putchar(int);
93
Rich Felker400c5e52012-09-06 22:44:55 -040094char *fgets(char *__restrict, int, FILE *__restrict);
Rich Felker9bff7c12012-08-25 23:15:13 -040095#if __STDC_VERSION__ < 201112L
Rich Felker0b44a032011-02-12 00:22:29 -050096char *gets(char *);
Rich Felker9bff7c12012-08-25 23:15:13 -040097#endif
Rich Felker0b44a032011-02-12 00:22:29 -050098
Rich Felker400c5e52012-09-06 22:44:55 -040099int fputs(const char *__restrict, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500100int puts(const char *);
101
Rich Felker400c5e52012-09-06 22:44:55 -0400102int printf(const char *__restrict, ...);
103int fprintf(FILE *__restrict, const char *__restrict, ...);
104int sprintf(char *__restrict, const char *__restrict, ...);
105int snprintf(char *__restrict, size_t, const char *__restrict, ...);
Rich Felker0b44a032011-02-12 00:22:29 -0500106
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400107int vprintf(const char *__restrict, __isoc_va_list);
108int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list);
109int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list);
110int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list);
Rich Felker0b44a032011-02-12 00:22:29 -0500111
Rich Felker400c5e52012-09-06 22:44:55 -0400112int scanf(const char *__restrict, ...);
113int fscanf(FILE *__restrict, const char *__restrict, ...);
114int sscanf(const char *__restrict, const char *__restrict, ...);
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400115int vscanf(const char *__restrict, __isoc_va_list);
116int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list);
117int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list);
Rich Felker0b44a032011-02-12 00:22:29 -0500118
119void perror(const char *);
120
Rich Felker400c5e52012-09-06 22:44:55 -0400121int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
122void setbuf(FILE *__restrict, char *__restrict);
Rich Felker80695b12011-02-14 05:10:10 -0500123
124char *tmpnam(char *);
125FILE *tmpfile(void);
126
127#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
Rich Felker419ae6d2012-05-22 21:52:08 -0400128 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
129 || defined(_BSD_SOURCE)
Rich Felker400c5e52012-09-06 22:44:55 -0400130FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
Rich Felkerb158b322011-09-03 00:45:21 -0400131FILE *open_memstream(char **, size_t *);
Rich Felker80695b12011-02-14 05:10:10 -0500132FILE *fdopen(int, const char *);
133FILE *popen(const char *, const char *);
134int pclose(FILE *);
135int fileno(FILE *);
136int fseeko(FILE *, off_t, int);
137off_t ftello(FILE *);
Rich Felker400c5e52012-09-06 22:44:55 -0400138int dprintf(int, const char *__restrict, ...);
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400139int vdprintf(int, const char *__restrict, __isoc_va_list);
Rich Felker0b44a032011-02-12 00:22:29 -0500140void flockfile(FILE *);
141int ftrylockfile(FILE *);
142void funlockfile(FILE *);
143int getc_unlocked(FILE *);
144int getchar_unlocked(void);
145int putc_unlocked(int, FILE *);
146int putchar_unlocked(int);
Rich Felker400c5e52012-09-06 22:44:55 -0400147ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
148ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
Rich Felker0b44a032011-02-12 00:22:29 -0500149int renameat(int, const char *, int, const char *);
Rich Felker80695b12011-02-14 05:10:10 -0500150char *ctermid(char *);
Rich Felker571312d2011-02-15 19:47:22 -0500151#define L_ctermid 20
Rich Felker80695b12011-02-14 05:10:10 -0500152#endif
153
154
Rich Felker419ae6d2012-05-22 21:52:08 -0400155#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
156 || defined(_BSD_SOURCE)
Rich Felker571312d2011-02-15 19:47:22 -0500157#define P_tmpdir "/tmp"
Rich Felker80695b12011-02-14 05:10:10 -0500158char *tempnam(const char *, const char *);
159#endif
160
Rich Felker419ae6d2012-05-22 21:52:08 -0400161#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Rich Felker571312d2011-02-15 19:47:22 -0500162#define L_cuserid 20
163char *cuserid(char *);
Rich Felkere7218002011-04-05 12:25:31 -0400164void setlinebuf(FILE *);
165void setbuffer(FILE *, char *, size_t);
Rich Felkerce17ea62011-09-11 22:50:02 -0400166int fgetc_unlocked(FILE *);
167int fputc_unlocked(int, FILE *);
Rich Felkerb63cab72012-05-28 22:53:24 -0400168int fflush_unlocked(FILE *);
169size_t fread_unlocked(void *, size_t, size_t, FILE *);
170size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
171void clearerr_unlocked(FILE *);
172int feof_unlocked(FILE *);
173int ferror_unlocked(FILE *);
174int fileno_unlocked(FILE *);
Rich Felker25b88f02012-07-04 12:18:04 -0400175int getw(FILE *);
176int putw(int, FILE *);
Rich Felker61718272012-08-11 18:10:38 -0400177char *fgetln(FILE *, size_t *);
Rich Felkerd18a4102012-12-28 15:39:33 -0500178int asprintf(char **, const char *, ...);
Rich Felkera3e2f3c2013-06-25 22:26:20 -0400179int vasprintf(char **, const char *, __isoc_va_list);
Rich Felker61718272012-08-11 18:10:38 -0400180#endif
181
Rich Felkerb63cab72012-05-28 22:53:24 -0400182#ifdef _GNU_SOURCE
Rich Felkerce17ea62011-09-11 22:50:02 -0400183char *fgets_unlocked(char *, int, FILE *);
184int fputs_unlocked(const char *, FILE *);
William Pitcock06184332017-12-05 16:04:43 -0500185
186typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
187typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
188typedef int (cookie_seek_function_t)(void *, off_t *, int);
189typedef int (cookie_close_function_t)(void *);
190
Rich Felker2488d312017-12-06 13:14:22 -0500191typedef struct _IO_cookie_io_functions_t {
William Pitcock06184332017-12-05 16:04:43 -0500192 cookie_read_function_t *read;
193 cookie_write_function_t *write;
194 cookie_seek_function_t *seek;
195 cookie_close_function_t *close;
196} cookie_io_functions_t;
197
198FILE *fopencookie(void *, const char *, cookie_io_functions_t);
Rich Felker80695b12011-02-14 05:10:10 -0500199#endif
Rich Felker0b44a032011-02-12 00:22:29 -0500200
Rich Felker3b94dab2012-06-04 08:03:56 -0400201#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
Rich Felker2dd8d5e2012-05-04 00:13:23 -0400202#define tmpfile64 tmpfile
203#define fopen64 fopen
204#define freopen64 freopen
205#define fseeko64 fseeko
206#define ftello64 ftello
207#define fgetpos64 fgetpos
208#define fsetpos64 fsetpos
209#define fpos64_t fpos_t
210#define off64_t off_t
211#endif
212
Rich Felker0b44a032011-02-12 00:22:29 -0500213#ifdef __cplusplus
214}
215#endif
216
217#endif