Update.
[glibc.git] / libio / stdio.h
blobb43826e03725892e4897128a12cc1b0bf892d45c
1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 1994-1999, 2000 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * ISO C Standard: 4.9 INPUT/OUTPUT <stdio.h>
23 #ifndef _STDIO_H
25 #ifndef __need_FILE
26 # define _STDIO_H 1
27 # include <features.h>
29 __BEGIN_DECLS
31 # define __need_size_t
32 # define __need_NULL
33 # include <stddef.h>
35 # ifndef __USE_XOPEN
36 # define __need___va_list
37 # endif
38 # include <stdarg.h>
40 # include <bits/types.h>
41 #endif /* Don't need FILE. */
42 #undef __need_FILE
45 #ifndef __FILE_defined
47 /* The opaque type of streams. */
48 typedef struct _IO_FILE FILE;
50 # define __FILE_defined 1
51 #endif /* FILE not defined. */
54 #ifdef _STDIO_H
55 #define _STDIO_USES_IOSTREAM
57 #include <libio.h>
59 /* The type of the second argument to `fgetpos' and `fsetpos'. */
60 #ifndef __USE_FILE_OFFSET64
61 typedef _G_fpos_t fpos_t;
62 #else
63 typedef _G_fpos64_t fpos_t;
64 #endif
65 #ifdef __USE_LARGEFILE64
66 typedef _G_fpos64_t fpos64_t;
67 #endif
69 /* The possibilities for the third argument to `setvbuf'. */
70 #define _IOFBF 0 /* Fully buffered. */
71 #define _IOLBF 1 /* Line buffered. */
72 #define _IONBF 2 /* No buffering. */
75 /* Default buffer size. */
76 #ifndef BUFSIZ
77 # define BUFSIZ _IO_BUFSIZ
78 #endif
81 /* End of file character.
82 Some things throughout the library rely on this being -1. */
83 #ifndef EOF
84 # define EOF (-1)
85 #endif
88 /* The possibilities for the third argument to `fseek'.
89 These values should not be changed. */
90 #define SEEK_SET 0 /* Seek from beginning of file. */
91 #define SEEK_CUR 1 /* Seek from current position. */
92 #define SEEK_END 2 /* Seek from end of file. */
95 #if defined __USE_SVID || defined __USE_XOPEN
96 /* Default path prefix for `tempnam' and `tmpnam'. */
97 # define P_tmpdir "/tmp"
98 #endif
101 /* Get the values:
102 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
103 TMP_MAX The minimum number of unique filenames generated by tmpnam
104 (and tempnam when it uses tmpnam's name space),
105 or tempnam (the two are separate).
106 L_ctermid How long an array to pass to `ctermid'.
107 L_cuserid How long an array to pass to `cuserid'.
108 FOPEN_MAX Minimum number of files that can be open at once.
109 FILENAME_MAX Maximum length of a filename. */
110 #include <bits/stdio_lim.h>
113 /* Standard streams. */
114 extern FILE *stdin; /* Standard input stream. */
115 extern FILE *stdout; /* Standard output stream. */
116 extern FILE *stderr; /* Standard error output stream. */
117 /* C89/C99 say they're macros. Make them happy. */
118 #define stdin stdin
119 #define stdout stdout
120 #define stderr stderr
122 /* Remove file FILENAME. */
123 extern int remove (__const char *__filename) __THROW;
124 /* Rename file OLD to NEW. */
125 extern int rename (__const char *__old, __const char *__new) __THROW;
128 /* Create a temporary file and open it read/write. */
129 #ifndef __USE_FILE_OFFSET64
130 extern FILE *tmpfile (void) __THROW;
131 #else
132 # ifdef __REDIRECT
133 extern FILE *__REDIRECT (tmpfile, (void) __THROW, tmpfile64);
134 # else
135 # define tmpfile tmpfile64
136 # endif
137 #endif
138 #ifdef __USE_LARGEFILE64
139 extern FILE *tmpfile64 (void) __THROW;
140 #endif
141 /* Generate a temporary filename. */
142 extern char *tmpnam (char *__s) __THROW;
144 #ifdef __USE_MISC
145 /* This is the reentrant variant of `tmpnam'. The only difference is
146 that it does not allow S to be NULL. */
147 extern char *tmpnam_r (char *__s) __THROW;
148 #endif
151 #if defined __USE_SVID || defined __USE_XOPEN
152 /* Generate a unique temporary filename using up to five characters of PFX
153 if it is not NULL. The directory to put this file in is searched for
154 as follows: First the environment variable "TMPDIR" is checked.
155 If it contains the name of a writable directory, that directory is used.
156 If not and if DIR is not NULL, that value is checked. If that fails,
157 P_tmpdir is tried and finally "/tmp". The storage for the filename
158 is allocated by `malloc'. */
159 extern char *tempnam (__const char *__dir, __const char *__pfx)
160 __THROW __attribute_malloc__;
161 #endif
164 /* Close STREAM. */
165 extern int fclose (FILE *__stream) __THROW;
166 /* Flush STREAM, or all streams if STREAM is NULL. */
167 extern int fflush (FILE *__stream) __THROW;
169 #ifdef __USE_MISC
170 /* Faster versions when locking is not required. */
171 extern int fflush_unlocked (FILE *__stream) __THROW;
172 #endif
174 #ifdef __USE_GNU
175 /* Close all streams. */
176 extern int fcloseall (void) __THROW;
177 #endif
180 #ifndef __USE_FILE_OFFSET64
181 /* Open a file and create a new stream for it. */
182 extern FILE *fopen (__const char *__restrict __filename,
183 __const char *__restrict __modes) __THROW;
184 /* Open a file, replacing an existing stream with it. */
185 extern FILE *freopen (__const char *__restrict __filename,
186 __const char *__restrict __modes,
187 FILE *__restrict __stream) __THROW;
188 #else
189 # ifdef __REDIRECT
190 extern FILE *__REDIRECT (fopen, (__const char *__restrict __filename,
191 __const char *__restrict __modes) __THROW,
192 fopen64);
193 extern FILE *__REDIRECT (freopen, (__const char *__restrict __filename,
194 __const char *__restrict __modes,
195 FILE *__restrict __stream) __THROW,
196 freopen64);
197 # else
198 # define fopen fopen64
199 # define freopen freopen64
200 # endif
201 #endif
202 #ifdef __USE_LARGEFILE64
203 extern FILE *fopen64 (__const char *__restrict __filename,
204 __const char *__restrict __modes) __THROW;
205 extern FILE *freopen64 (__const char *__restrict __filename,
206 __const char *__restrict __modes,
207 FILE *__restrict __stream) __THROW;
208 #endif
210 #ifdef __USE_POSIX
211 /* Create a new stream that refers to an existing system file descriptor. */
212 extern FILE *fdopen (int __fd, __const char *__modes) __THROW;
213 #endif
215 #ifdef __USE_GNU
216 /* Create a new stream that refers to the given magic cookie,
217 and uses the given functions for input and output. */
218 extern FILE *fopencookie (void *__restrict __magic_cookie,
219 __const char *__restrict __modes,
220 _IO_cookie_io_functions_t __io_funcs) __THROW;
222 /* Open a stream that writes into a malloc'd buffer that is expanded as
223 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
224 and the number of characters written on fflush or fclose. */
225 extern FILE *open_memstream (char **__restrict __bufloc,
226 size_t *__restrict __sizeloc) __THROW;
227 #endif
230 /* If BUF is NULL, make STREAM unbuffered.
231 Else make it use buffer BUF, of size BUFSIZ. */
232 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
233 /* Make STREAM use buffering mode MODE.
234 If BUF is not NULL, use N bytes of it for buffering;
235 else allocate an internal buffer N bytes long. */
236 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
237 int __modes, size_t __n) __THROW;
239 #ifdef __USE_BSD
240 /* If BUF is NULL, make STREAM unbuffered.
241 Else make it use SIZE bytes of BUF for buffering. */
242 extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
243 size_t __size) __THROW;
245 /* Make STREAM line-buffered. */
246 extern void setlinebuf (FILE *__stream) __THROW;
247 #endif
250 /* Write formatted output to STREAM. */
251 extern int fprintf (FILE *__restrict __stream,
252 __const char *__restrict __format, ...) __THROW;
253 /* Write formatted output to stdout. */
254 extern int printf (__const char *__restrict __format, ...) __THROW;
255 /* Write formatted output to S. */
256 extern int sprintf (char *__restrict __s,
257 __const char *__restrict __format, ...) __THROW;
259 /* Write formatted output to S from argument list ARG. */
260 extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,
261 _G_va_list __arg) __THROW;
262 /* Write formatted output to stdout from argument list ARG. */
263 extern int vprintf (__const char *__restrict __format, _G_va_list __arg)
264 __THROW;
265 /* Write formatted output to S from argument list ARG. */
266 extern int vsprintf (char *__restrict __s, __const char *__restrict __format,
267 _G_va_list __arg) __THROW;
269 #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98
270 /* Maximum chars of output to write in MAXLEN. */
271 extern int snprintf (char *__restrict __s, size_t __maxlen,
272 __const char *__restrict __format, ...)
273 __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
275 extern int __vsnprintf (char *__restrict __s, size_t __maxlen,
276 __const char *__restrict __format, _G_va_list __arg)
277 __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
278 extern int vsnprintf (char *__restrict __s, size_t __maxlen,
279 __const char *__restrict __format, _G_va_list __arg)
280 __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
281 #endif
283 #ifdef __USE_GNU
284 /* Write formatted output to a string dynamically allocated with `malloc'.
285 Store the address of the string in *PTR. */
286 extern int vasprintf (char **__restrict __ptr, __const char *__restrict __f,
287 _G_va_list __arg)
288 __THROW __attribute__ ((__format__ (__printf__, 2, 0)));
289 extern int __asprintf (char **__restrict __ptr,
290 __const char *__restrict __fmt, ...)
291 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
292 extern int asprintf (char **__restrict __ptr,
293 __const char *__restrict __fmt, ...)
294 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
296 /* Write formatted output to a file descriptor. */
297 extern int vdprintf (int __fd, __const char *__restrict __fmt,
298 _G_va_list __arg)
299 __THROW __attribute__ ((__format__ (__printf__, 2, 0)));
300 extern int dprintf (int __fd, __const char *__restrict __fmt, ...)
301 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
302 #endif
305 /* Read formatted input from STREAM. */
306 extern int fscanf (FILE *__restrict __stream,
307 __const char *__restrict __format, ...) __THROW;
308 /* Read formatted input from stdin. */
309 extern int scanf (__const char *__restrict __format, ...) __THROW;
310 /* Read formatted input from S. */
311 extern int sscanf (__const char *__restrict __s,
312 __const char *__restrict __format, ...) __THROW;
314 #ifdef __USE_ISOC99
315 /* Read formatted input from S into argument list ARG. */
316 extern int vfscanf (FILE *__restrict __s, __const char *__restrict __format,
317 _G_va_list __arg)
318 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
320 /* Read formatted input from stdin into argument list ARG. */
321 extern int vscanf (__const char *__restrict __format, _G_va_list __arg)
322 __THROW __attribute__ ((__format__ (__scanf__, 1, 0)));
324 /* Read formatted input from S into argument list ARG. */
325 extern int vsscanf (__const char *__restrict __s,
326 __const char *__restrict __format, _G_va_list __arg)
327 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
328 #endif /* Use ISO C9x. */
331 /* Read a character from STREAM. */
332 extern int fgetc (FILE *__stream) __THROW;
333 extern int getc (FILE *__stream) __THROW;
335 /* Read a character from stdin. */
336 extern int getchar (void) __THROW;
338 /* The C standard explicitly says this is a macro, so we always do the
339 optimization for it. */
340 #define getc(_fp) _IO_getc (_fp)
342 #if defined __USE_POSIX || defined __USE_MISC
343 /* These are defined in POSIX.1:1996. */
344 extern int getc_unlocked (FILE *__stream) __THROW;
345 extern int getchar_unlocked (void) __THROW;
346 #endif /* Use POSIX or MISC. */
348 #ifdef __USE_MISC
349 /* Faster version when locking is not necessary. */
350 extern int fgetc_unlocked (FILE *__stream) __THROW;
351 #endif /* Use MISC. */
354 /* Write a character to STREAM. */
355 extern int fputc (int __c, FILE *__stream) __THROW;
356 extern int putc (int __c, FILE *__stream) __THROW;
358 /* Write a character to stdout. */
359 extern int putchar (int __c) __THROW;
361 /* The C standard explicitly says this can be a macro,
362 so we always do the optimization for it. */
363 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
365 #ifdef __USE_MISC
366 /* Faster version when locking is not necessary. */
367 extern int fputc_unlocked (int __c, FILE *__stream) __THROW;
368 #endif /* Use MISC. */
370 #if defined __USE_POSIX || defined __USE_MISC
371 /* These are defined in POSIX.1:1996. */
372 extern int putc_unlocked (int __c, FILE *__stream) __THROW;
373 extern int putchar_unlocked (int __c) __THROW;
374 #endif /* Use POSIX or MISC. */
377 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
378 /* Get a word (int) from STREAM. */
379 extern int getw (FILE *__stream) __THROW;
381 /* Write a word (int) to STREAM. */
382 extern int putw (int __w, FILE *__stream) __THROW;
383 #endif
386 /* Get a newline-terminated string of finite length from STREAM. */
387 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
388 __THROW;
390 #ifdef __USE_GNU
391 /* This function does the same as `fgets' but does not lock the stream. */
392 extern char *fgets_unlocked (char *__restrict __s, int __n,
393 FILE *__restrict __stream) __THROW;
394 #endif
396 /* Get a newline-terminated string from stdin, removing the newline.
397 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
398 extern char *gets (char *__s) __THROW;
401 #ifdef __USE_GNU
402 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
403 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
404 NULL), pointing to *N characters of space. It is realloc'd as
405 necessary. Returns the number of characters read (not including the
406 null terminator), or -1 on error or EOF. */
407 extern _IO_ssize_t __getdelim (char **__restrict __lineptr,
408 size_t *__restrict __n, int __delimiter,
409 FILE *__restrict __stream) __THROW;
410 extern _IO_ssize_t getdelim (char **__restrict __lineptr,
411 size_t *__restrict __n, int __delimiter,
412 FILE *__restrict __stream) __THROW;
414 /* Like `getdelim', but reads up to a newline. */
415 extern _IO_ssize_t getline (char **__restrict __lineptr,
416 size_t *__restrict __n,
417 FILE *__restrict __stream) __THROW;
418 #endif
421 /* Write a string to STREAM. */
422 extern int fputs (__const char *__restrict __s, FILE *__restrict __stream)
423 __THROW;
425 #ifdef __USE_GNU
426 /* This function does the same as `fputs' but does not lock the stream. */
427 extern int fputs_unlocked (__const char *__restrict __s,
428 FILE *__restrict __stream) __THROW;
429 #endif
431 /* Write a string, followed by a newline, to stdout. */
432 extern int puts (__const char *__s) __THROW;
435 /* Push a character back onto the input buffer of STREAM. */
436 extern int ungetc (int __c, FILE *__stream) __THROW;
439 /* Read chunks of generic data from STREAM. */
440 extern size_t fread (void *__restrict __ptr, size_t __size,
441 size_t __n, FILE *__restrict __stream) __THROW;
442 /* Write chunks of generic data to STREAM. */
443 extern size_t fwrite (__const void *__restrict __ptr, size_t __size,
444 size_t __n, FILE *__restrict __s) __THROW;
446 #ifdef __USE_MISC
447 /* Faster versions when locking is not necessary. */
448 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
449 size_t __n, FILE *__restrict __stream) __THROW;
450 extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size,
451 size_t __n, FILE *__restrict __stream) __THROW;
452 #endif
455 /* Seek to a certain position on STREAM. */
456 extern int fseek (FILE *__stream, long int __off, int __whence) __THROW;
457 /* Return the current position of STREAM. */
458 extern long int ftell (FILE *__stream) __THROW;
459 /* Rewind to the beginning of STREAM. */
460 extern void rewind (FILE *__stream) __THROW;
462 /* The Single Unix Specification, Version 2, specifies an alternative,
463 more adequate interface for the two functions above which deal with
464 file offset. `long int' is not the right type. These definitions
465 are originally defined in the Large File Support API. */
467 /* Types needed in these functions. */
468 #ifndef __off_t_defined
469 # ifndef __USE_FILE_OFFSET64
470 typedef __off_t off_t;
471 # else
472 typedef __off64_t off_t;
473 # endif
474 # define __off_t_defined
475 #endif
477 #if defined __USE_LARGEFILE64 && !defined __off64_t_defined
478 typedef __off64_t off64_t;
479 # define __off64_t_defined
480 #endif
483 #ifndef __USE_FILE_OFFSET64
484 # ifdef __USE_LARGEFILE
485 /* Seek to a certain position on STREAM. */
486 extern int fseeko (FILE *__stream, __off_t __off, int __whence) __THROW;
487 /* Return the current position of STREAM. */
488 extern __off_t ftello (FILE *__stream) __THROW;
489 # endif
491 /* Get STREAM's position. */
492 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos)
493 __THROW;
494 /* Set STREAM's position. */
495 extern int fsetpos (FILE *__stream, __const fpos_t *__pos) __THROW;
496 #else
497 # ifdef __REDIRECT
498 # ifdef __USE_LARGEFILE
499 extern int __REDIRECT (fseeko,
500 (FILE *__stream, __off64_t __off, int __whence) __THROW,
501 fseeko64);
502 extern __off64_t __REDIRECT (ftello, (FILE *__stream) __THROW, ftello64);
503 # endif
504 extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
505 fpos_t *__restrict __pos) __THROW, fgetpos64);
506 extern int __REDIRECT (fsetpos,
507 (FILE *__stream, __const fpos_t *__pos) __THROW,
508 fsetpos64);
509 # else
510 # ifdef __USE_LARGEFILE
511 # define fseeko fseeko64
512 # define ftello ftello64
513 # endif
514 # define fgetpos fgetpos64
515 # define fsetpos fsetpos64
516 # endif
517 #endif
519 #ifdef __USE_LARGEFILE64
520 extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence) __THROW;
521 extern __off64_t ftello64 (FILE *__stream) __THROW;
522 extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos)
523 __THROW;
524 extern int fsetpos64 (FILE *__stream, __const fpos64_t *__pos) __THROW;
525 #endif
527 /* Clear the error and EOF indicators for STREAM. */
528 extern void clearerr (FILE *__stream) __THROW;
529 /* Return the EOF indicator for STREAM. */
530 extern int feof (FILE *__stream) __THROW;
531 /* Return the error indicator for STREAM. */
532 extern int ferror (FILE *__stream) __THROW;
534 #ifdef __USE_MISC
535 /* Faster versions when locking is not required. */
536 extern void clearerr_unlocked (FILE *__stream) __THROW;
537 extern int feof_unlocked (FILE *__stream) __THROW;
538 extern int ferror_unlocked (FILE *__stream) __THROW;
539 #endif
542 /* Print a message describing the meaning of the value of errno. */
543 extern void perror (__const char *__s) __THROW;
545 /* These variables normally should not be used directly. The `strerror'
546 function provides all the needed functionality. */
547 #ifdef __USE_BSD
548 extern int sys_nerr;
549 extern __const char *__const sys_errlist[];
550 #endif
551 #ifdef __USE_GNU
552 extern int _sys_nerr;
553 extern __const char *__const _sys_errlist[];
554 #endif
557 #ifdef __USE_POSIX
558 /* Return the system file descriptor for STREAM. */
559 extern int fileno (FILE *__stream) __THROW;
560 #endif /* Use POSIX. */
562 #ifdef __USE_MISC
563 /* Faster version when locking is not required. */
564 extern int fileno_unlocked (FILE *__stream) __THROW;
565 #endif
568 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
569 defined __USE_MISC)
570 /* Create a new stream connected to a pipe running the given command. */
571 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
573 /* Close a stream opened by popen and return the status of its child. */
574 extern int pclose (FILE *__stream) __THROW;
575 #endif
578 #ifdef __USE_POSIX
579 /* Return the name of the controlling terminal. */
580 extern char *ctermid (char *__s) __THROW;
581 #endif /* Use POSIX. */
584 #if defined __USE_XOPEN && !defined __USE_XOPEN2K
585 /* Return the name of the current user. */
586 extern char *cuserid (char *__s) __THROW;
587 #endif /* Use X/Open, but not issue 6. */
590 #ifdef __USE_GNU
591 struct obstack; /* See <obstack.h>. */
593 /* Write formatted output to an obstack. */
594 extern int obstack_printf (struct obstack *__restrict __obstack,
595 __const char *__restrict __format, ...) __THROW;
596 extern int obstack_vprintf (struct obstack *__restrict __obstack,
597 __const char *__restrict __format,
598 _G_va_list __args) __THROW;
599 #endif /* Use GNU. */
602 #if defined __USE_POSIX || defined __USE_MISC
603 /* These are defined in POSIX.1:1996. */
605 /* Acquire ownership of STREAM. */
606 extern void flockfile (FILE *__stream) __THROW;
608 /* Try to acquire ownership of STREAM but do not block if it is not
609 possible. */
610 extern int ftrylockfile (FILE *__stream) __THROW;
612 /* Relinquish the ownership granted for STREAM. */
613 extern void funlockfile (FILE *__stream) __THROW;
614 #endif /* POSIX || misc */
616 #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
617 /* The X/Open standard requires some functions and variables to be
618 declared here which do not belong into this header. But we have to
619 follow. In GNU mode we don't do this nonsense. */
620 # define __need_getopt
621 # include <getopt.h>
622 #endif /* X/Open, but not issue 6 and not for GNU. */
624 /* If we are compiling with optimizing read this file. It contains
625 several optizing inline functions and macros. */
626 #ifdef __USE_EXTERN_INLINES
627 # include <bits/stdio.h>
628 #endif
630 __END_DECLS
632 #endif /* <stdio.h> included. */
634 #endif /* !_STDIO_H */