1stdio.h(0P) POSIX Programmer's Manual stdio.h(0P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 stdio.h — standard buffered input/output
13
15 #include <stdio.h>
16
18 Some of the functionality described on this reference page extends the
19 ISO C standard. Applications shall define the appropriate feature test
20 macro (see the System Interfaces volume of POSIX.1‐2017, Section 2.2,
21 The Compilation Environment) to enable the visibility of these symbols
22 in this header.
23
24 The <stdio.h> header shall define the following data types through
25 typedef:
26
27 FILE A structure containing information about a file.
28
29 fpos_t A non-array type containing all information needed to
30 specify uniquely every position within a file.
31
32 off_t As described in <sys/types.h>.
33
34 size_t As described in <stddef.h>.
35
36 ssize_t As described in <sys/types.h>.
37
38 va_list As described in <stdarg.h>.
39
40 The <stdio.h> header shall define the following macros which shall
41 expand to integer constant expressions:
42
43 BUFSIZ Size of <stdio.h> buffers. This shall expand to a posi‐
44 tive value.
45
46 L_ctermid Maximum size of character array to hold ctermid() output.
47
48 L_tmpnam Maximum size of character array to hold tmpnam() output.
49
50 The <stdio.h> header shall define the following macros which shall
51 expand to integer constant expressions with distinct values:
52
53 _IOFBF Input/output fully buffered.
54
55 _IOLBF Input/output line buffered.
56
57 _IONBF Input/output unbuffered.
58
59 The <stdio.h> header shall define the following macros which shall
60 expand to integer constant expressions with distinct values:
61
62 SEEK_CUR Seek relative to current position.
63
64 SEEK_END Seek relative to end-of-file.
65
66 SEEK_SET Seek relative to start-of-file.
67
68 The <stdio.h> header shall define the following macros which shall
69 expand to integer constant expressions denoting implementation limits:
70
71 {FILENAME_MAX}
72 Maximum size in bytes of the longest pathname that the
73 implementation guarantees can be opened.
74
75 {FOPEN_MAX} Number of streams which the implementation guarantees can
76 be open simultaneously. The value is at least eight.
77
78 {TMP_MAX} Minimum number of unique filenames generated by tmpnam().
79 Maximum number of times an application can call tmpnam()
80 reliably. The value of {TMP_MAX} is at least 25.
81
82 On XSI-conformant systems, the value of {TMP_MAX} is at
83 least 10000.
84
85 The <stdio.h> header shall define the following macro which shall
86 expand to an integer constant expression with type int and a negative
87 value:
88
89 EOF End-of-file return value.
90
91 The <stdio.h> header shall define NULL as described in <stddef.h>.
92
93 The <stdio.h> header shall define the following macro which shall
94 expand to a string constant:
95
96 P_tmpdir Default directory prefix for tempnam().
97
98 The <stdio.h> header shall define the following macros which shall
99 expand to expressions of type ``pointer to FILE'' that point to the
100 FILE objects associated, respectively, with the standard error, input,
101 and output streams:
102
103 stderr Standard error output stream.
104
105 stdin Standard input stream.
106
107 stdout Standard output stream.
108
109 The following shall be declared as functions and may also be defined as
110 macros. Function prototypes shall be provided.
111
112
113 void clearerr(FILE *);
114 char *ctermid(char *);
115 int dprintf(int, const char *restrict, ...)
116 int fclose(FILE *);
117 FILE *fdopen(int, const char *);
118 int feof(FILE *);
119 int ferror(FILE *);
120 int fflush(FILE *);
121 int fgetc(FILE *);
122 int fgetpos(FILE *restrict, fpos_t *restrict);
123 char *fgets(char *restrict, int, FILE *restrict);
124 int fileno(FILE *);
125 void flockfile(FILE *);
126 FILE *fmemopen(void *restrict, size_t, const char *restrict);
127 FILE *fopen(const char *restrict, const char *restrict);
128 int fprintf(FILE *restrict, const char *restrict, ...);
129 int fputc(int, FILE *);
130 int fputs(const char *restrict, FILE *restrict);
131 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
132 FILE *freopen(const char *restrict, const char *restrict,
133 FILE *restrict);
134 int fscanf(FILE *restrict, const char *restrict, ...);
135 int fseek(FILE *, long, int);
136 int fseeko(FILE *, off_t, int);
137 int fsetpos(FILE *, const fpos_t *);
138 long ftell(FILE *);
139 off_t ftello(FILE *);
140 int ftrylockfile(FILE *);
141 void funlockfile(FILE *);
142 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
143 int getc(FILE *);
144 int getchar(void);
145 int getc_unlocked(FILE *);
146 int getchar_unlocked(void);
147 ssize_t getdelim(char **restrict, size_t *restrict, int,
148 FILE *restrict);
149 ssize_t getline(char **restrict, size_t *restrict, FILE *restrict);
150 char *gets(char *);
151 FILE *open_memstream(char **, size_t *);
152 int pclose(FILE *);
153 void perror(const char *);
154 FILE *popen(const char *, const char *);
155 int printf(const char *restrict, ...);
156 int putc(int, FILE *);
157 int putchar(int);
158 int putc_unlocked(int, FILE *);
159 int putchar_unlocked(int);
160 int puts(const char *);
161 int remove(const char *);
162 int rename(const char *, const char *);
163 int renameat(int, const char *, int, const char *);
164 void rewind(FILE *);
165 int scanf(const char *restrict, ...);
166 void setbuf(FILE *restrict, char *restrict);
167 int setvbuf(FILE *restrict, char *restrict, int, size_t);
168 int snprintf(char *restrict, size_t, const char *restrict, ...);
169 int sprintf(char *restrict, const char *restrict, ...);
170 int sscanf(const char *restrict, const char *restrict, ...);
171 char *tempnam(const char *, const char *);
172 FILE *tmpfile(void);
173 char *tmpnam(char *);
174 int ungetc(int, FILE *);
175 int vdprintf(int, const char *restrict, va_list);
176 int vfprintf(FILE *restrict, const char *restrict, va_list);
177 int vfscanf(FILE *restrict, const char *restrict, va_list);
178 int vprintf(const char *restrict, va_list);
179 int vscanf(const char *restrict, va_list);
180 int vsnprintf(char *restrict, size_t, const char *restrict,
181 va_list);
182 int vsprintf(char *restrict, const char *restrict, va_list);
183 int vsscanf(const char *restrict, const char *restrict, va_list);
184
185 Inclusion of the <stdio.h> header may also make visible all symbols
186 from <stddef.h>.
187
188 The following sections are informative.
189
191 Since standard I/O streams may use an underlying file descriptor to
192 access the file associated with a stream, application developers need
193 to be aware that {FOPEN_MAX} streams may not be available if file
194 descriptors are being used to access files that are not associated with
195 streams.
196
198 There is a conflict between the ISO C standard and the POSIX definition
199 of the {TMP_MAX} macro that is addressed by ISO/IEC 9899:1999 standard,
200 Defect Report 336. The POSIX standard is in alignment with the public
201 record of the response to the Defect Report. This change has not yet
202 been published as part of the ISO C standard.
203
205 None.
206
208 <stdarg.h>, <stddef.h>, <sys_types.h>
209
210 The System Interfaces volume of POSIX.1‐2017, Section 2.2, The Compila‐
211 tion Environment, clearerr(), ctermid(), fclose(), fdopen(), feof(),
212 ferror(), fflush(), fgetc(), fgetpos(), fgets(), fileno(), flockfile(),
213 fmemopen(), fopen(), fprintf(), fputc(), fputs(), fread(), freopen(),
214 fscanf(), fseek(), fsetpos(), ftell(), fwrite(), getc(), getchar(),
215 getc_unlocked(), getdelim(), getopt(), gets(), open_memstream(),
216 pclose(), perror(), popen(), putc(), putchar(), puts(), remove(),
217 rename(), rewind(), setbuf(), setvbuf(), stdin, system(), tempnam(),
218 tmpfile(), tmpnam(), ungetc(), vfprintf(), vfscanf()
219
221 Portions of this text are reprinted and reproduced in electronic form
222 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
223 table Operating System Interface (POSIX), The Open Group Base Specifi‐
224 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
225 Electrical and Electronics Engineers, Inc and The Open Group. In the
226 event of any discrepancy between this version and the original IEEE and
227 The Open Group Standard, the original IEEE and The Open Group Standard
228 is the referee document. The original Standard can be obtained online
229 at http://www.opengroup.org/unix/online.html .
230
231 Any typographical or formatting errors that appear in this page are
232 most likely to have been introduced during the conversion of the source
233 files to man page format. To report such errors, see https://www.ker‐
234 nel.org/doc/man-pages/reporting_bugs.html .
235
236
237
238IEEE/The Open Group 2017 stdio.h(0P)