1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 1994-1999, 2000, 2001 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 C99 Standard: 7.19 Input/output <stdio.h>
25 #if !defined __need_FILE && !defined __need___FILE
27 # include <features.h>
31 # define __need_size_t
35 # include <bits/types.h>
37 # define __need___FILE
38 #endif /* Don't need FILE. */
41 #if !defined __FILE_defined && defined __need_FILE
43 /* The opaque type of streams. This is the definition used elsewhere. */
44 typedef struct _IO_FILE
FILE;
46 # define __FILE_defined 1
47 #endif /* FILE not defined. */
51 #if !defined ____FILE_defined && defined __need___FILE
53 /* The opaque type of streams. This is the definition used elsewhere. */
54 typedef struct _IO_FILE __FILE
;
56 # define ____FILE_defined 1
57 #endif /* __FILE not defined. */
62 #define _STDIO_USES_IOSTREAM
68 # ifndef _VA_LIST_DEFINED
69 typedef _G_va_list
va_list;
70 # define _VA_LIST_DEFINED
77 /* The type of the second argument to `fgetpos' and `fsetpos'. */
78 #ifndef __USE_FILE_OFFSET64
79 typedef _G_fpos_t
fpos_t;
81 typedef _G_fpos64_t
fpos_t;
83 #ifdef __USE_LARGEFILE64
84 typedef _G_fpos64_t fpos64_t
;
87 /* The possibilities for the third argument to `setvbuf'. */
88 #define _IOFBF 0 /* Fully buffered. */
89 #define _IOLBF 1 /* Line buffered. */
90 #define _IONBF 2 /* No buffering. */
93 /* Default buffer size. */
95 # define BUFSIZ _IO_BUFSIZ
99 /* End of file character.
100 Some things throughout the library rely on this being -1. */
106 /* The possibilities for the third argument to `fseek'.
107 These values should not be changed. */
108 #define SEEK_SET 0 /* Seek from beginning of file. */
109 #define SEEK_CUR 1 /* Seek from current position. */
110 #define SEEK_END 2 /* Seek from end of file. */
113 #if defined __USE_SVID || defined __USE_XOPEN
114 /* Default path prefix for `tempnam' and `tmpnam'. */
115 # define P_tmpdir "/tmp"
120 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
121 TMP_MAX The minimum number of unique filenames generated by tmpnam
122 (and tempnam when it uses tmpnam's name space),
123 or tempnam (the two are separate).
124 L_ctermid How long an array to pass to `ctermid'.
125 L_cuserid How long an array to pass to `cuserid'.
126 FOPEN_MAX Minimum number of files that can be open at once.
127 FILENAME_MAX Maximum length of a filename. */
128 #include <bits/stdio_lim.h>
131 /* Standard streams. */
132 extern FILE *stdin
; /* Standard input stream. */
133 extern FILE *stdout
; /* Standard output stream. */
134 extern FILE *stderr
; /* Standard error output stream. */
135 /* C89/C99 say they're macros. Make them happy. */
137 #define stdout stdout
138 #define stderr stderr
140 /* Remove file FILENAME. */
141 extern int remove (__const
char *__filename
) __THROW
;
142 /* Rename file OLD to NEW. */
143 extern int rename (__const
char *__old
, __const
char *__new
) __THROW
;
146 /* Create a temporary file and open it read/write. */
147 #ifndef __USE_FILE_OFFSET64
148 extern FILE *tmpfile (void) __THROW
;
151 extern FILE *__REDIRECT (tmpfile
, (void) __THROW
, tmpfile64
);
153 # define tmpfile tmpfile64
156 #ifdef __USE_LARGEFILE64
157 extern FILE *tmpfile64 (void) __THROW
;
159 /* Generate a temporary filename. */
160 extern char *tmpnam (char *__s
) __THROW
;
163 /* This is the reentrant variant of `tmpnam'. The only difference is
164 that it does not allow S to be NULL. */
165 extern char *tmpnam_r (char *__s
) __THROW
;
169 #if defined __USE_SVID || defined __USE_XOPEN
170 /* Generate a unique temporary filename using up to five characters of PFX
171 if it is not NULL. The directory to put this file in is searched for
172 as follows: First the environment variable "TMPDIR" is checked.
173 If it contains the name of a writable directory, that directory is used.
174 If not and if DIR is not NULL, that value is checked. If that fails,
175 P_tmpdir is tried and finally "/tmp". The storage for the filename
176 is allocated by `malloc'. */
177 extern char *tempnam (__const
char *__dir
, __const
char *__pfx
)
178 __THROW __attribute_malloc__
;
183 extern int fclose (FILE *__stream
) __THROW
;
184 /* Flush STREAM, or all streams if STREAM is NULL. */
185 extern int fflush (FILE *__stream
) __THROW
;
188 /* Faster versions when locking is not required. */
189 extern int fflush_unlocked (FILE *__stream
) __THROW
;
193 /* Close all streams. */
194 extern int fcloseall (void) __THROW
;
198 #ifndef __USE_FILE_OFFSET64
199 /* Open a file and create a new stream for it. */
200 extern FILE *fopen (__const
char *__restrict __filename
,
201 __const
char *__restrict __modes
) __THROW
;
202 /* Open a file, replacing an existing stream with it. */
203 extern FILE *freopen (__const
char *__restrict __filename
,
204 __const
char *__restrict __modes
,
205 FILE *__restrict __stream
) __THROW
;
208 extern FILE *__REDIRECT (fopen
, (__const
char *__restrict __filename
,
209 __const
char *__restrict __modes
) __THROW
,
211 extern FILE *__REDIRECT (freopen
, (__const
char *__restrict __filename
,
212 __const
char *__restrict __modes
,
213 FILE *__restrict __stream
) __THROW
,
216 # define fopen fopen64
217 # define freopen freopen64
220 #ifdef __USE_LARGEFILE64
221 extern FILE *fopen64 (__const
char *__restrict __filename
,
222 __const
char *__restrict __modes
) __THROW
;
223 extern FILE *freopen64 (__const
char *__restrict __filename
,
224 __const
char *__restrict __modes
,
225 FILE *__restrict __stream
) __THROW
;
229 /* Create a new stream that refers to an existing system file descriptor. */
230 extern FILE *fdopen (int __fd
, __const
char *__modes
) __THROW
;
234 /* Create a new stream that refers to the given magic cookie,
235 and uses the given functions for input and output. */
236 extern FILE *fopencookie (void *__restrict __magic_cookie
,
237 __const
char *__restrict __modes
,
238 _IO_cookie_io_functions_t __io_funcs
) __THROW
;
240 /* Create a new stream that refers to a memory buffer. */
241 extern FILE *fmemopen (void *__s
, size_t __len
, __const
char *__modes
) __THROW
;
243 /* Open a stream that writes into a malloc'd buffer that is expanded as
244 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
245 and the number of characters written on fflush or fclose. */
246 extern FILE *open_memstream (char **__restrict __bufloc
,
247 size_t *__restrict __sizeloc
) __THROW
;
251 /* If BUF is NULL, make STREAM unbuffered.
252 Else make it use buffer BUF, of size BUFSIZ. */
253 extern void setbuf (FILE *__restrict __stream
, char *__restrict __buf
) __THROW
;
254 /* Make STREAM use buffering mode MODE.
255 If BUF is not NULL, use N bytes of it for buffering;
256 else allocate an internal buffer N bytes long. */
257 extern int setvbuf (FILE *__restrict __stream
, char *__restrict __buf
,
258 int __modes
, size_t __n
) __THROW
;
261 /* If BUF is NULL, make STREAM unbuffered.
262 Else make it use SIZE bytes of BUF for buffering. */
263 extern void setbuffer (FILE *__restrict __stream
, char *__restrict __buf
,
264 size_t __size
) __THROW
;
266 /* Make STREAM line-buffered. */
267 extern void setlinebuf (FILE *__stream
) __THROW
;
271 /* Write formatted output to STREAM. */
272 extern int fprintf (FILE *__restrict __stream
,
273 __const
char *__restrict __format
, ...) __THROW
;
274 /* Write formatted output to stdout. */
275 extern int printf (__const
char *__restrict __format
, ...) __THROW
;
276 /* Write formatted output to S. */
277 extern int sprintf (char *__restrict __s
,
278 __const
char *__restrict __format
, ...) __THROW
;
280 /* Write formatted output to S from argument list ARG. */
281 extern int vfprintf (FILE *__restrict __s
, __const
char *__restrict __format
,
282 _G_va_list __arg
) __THROW
;
283 /* Write formatted output to stdout from argument list ARG. */
284 extern int vprintf (__const
char *__restrict __format
, _G_va_list __arg
)
286 /* Write formatted output to S from argument list ARG. */
287 extern int vsprintf (char *__restrict __s
, __const
char *__restrict __format
,
288 _G_va_list __arg
) __THROW
;
290 #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98
291 /* Maximum chars of output to write in MAXLEN. */
292 extern int snprintf (char *__restrict __s
, size_t __maxlen
,
293 __const
char *__restrict __format
, ...)
294 __THROW
__attribute__ ((__format__ (__printf__
, 3, 4)));
296 extern int vsnprintf (char *__restrict __s
, size_t __maxlen
,
297 __const
char *__restrict __format
, _G_va_list __arg
)
298 __THROW
__attribute__ ((__format__ (__printf__
, 3, 0)));
302 /* Write formatted output to a string dynamically allocated with `malloc'.
303 Store the address of the string in *PTR. */
304 extern int vasprintf (char **__restrict __ptr
, __const
char *__restrict __f
,
306 __THROW
__attribute__ ((__format__ (__printf__
, 2, 0)));
307 extern int __asprintf (char **__restrict __ptr
,
308 __const
char *__restrict __fmt
, ...)
309 __THROW
__attribute__ ((__format__ (__printf__
, 2, 3)));
310 extern int asprintf (char **__restrict __ptr
,
311 __const
char *__restrict __fmt
, ...)
312 __THROW
__attribute__ ((__format__ (__printf__
, 2, 3)));
314 /* Write formatted output to a file descriptor. */
315 extern int vdprintf (int __fd
, __const
char *__restrict __fmt
,
317 __THROW
__attribute__ ((__format__ (__printf__
, 2, 0)));
318 extern int dprintf (int __fd
, __const
char *__restrict __fmt
, ...)
319 __THROW
__attribute__ ((__format__ (__printf__
, 2, 3)));
323 /* Read formatted input from STREAM. */
324 extern int fscanf (FILE *__restrict __stream
,
325 __const
char *__restrict __format
, ...) __THROW
;
326 /* Read formatted input from stdin. */
327 extern int scanf (__const
char *__restrict __format
, ...) __THROW
;
328 /* Read formatted input from S. */
329 extern int sscanf (__const
char *__restrict __s
,
330 __const
char *__restrict __format
, ...) __THROW
;
333 /* Read formatted input from S into argument list ARG. */
334 extern int vfscanf (FILE *__restrict __s
, __const
char *__restrict __format
,
336 __THROW
__attribute__ ((__format__ (__scanf__
, 2, 0)));
338 /* Read formatted input from stdin into argument list ARG. */
339 extern int vscanf (__const
char *__restrict __format
, _G_va_list __arg
)
340 __THROW
__attribute__ ((__format__ (__scanf__
, 1, 0)));
342 /* Read formatted input from S into argument list ARG. */
343 extern int vsscanf (__const
char *__restrict __s
,
344 __const
char *__restrict __format
, _G_va_list __arg
)
345 __THROW
__attribute__ ((__format__ (__scanf__
, 2, 0)));
346 #endif /* Use ISO C9x. */
349 /* Read a character from STREAM. */
350 extern int fgetc (FILE *__stream
) __THROW
;
351 extern int getc (FILE *__stream
) __THROW
;
353 /* Read a character from stdin. */
354 extern int getchar (void) __THROW
;
356 /* The C standard explicitly says this is a macro, so we always do the
357 optimization for it. */
358 #define getc(_fp) _IO_getc (_fp)
360 #if defined __USE_POSIX || defined __USE_MISC
361 /* These are defined in POSIX.1:1996. */
362 extern int getc_unlocked (FILE *__stream
) __THROW
;
363 extern int getchar_unlocked (void) __THROW
;
364 #endif /* Use POSIX or MISC. */
367 /* Faster version when locking is not necessary. */
368 extern int fgetc_unlocked (FILE *__stream
) __THROW
;
369 #endif /* Use MISC. */
372 /* Write a character to STREAM. */
373 extern int fputc (int __c
, FILE *__stream
) __THROW
;
374 extern int putc (int __c
, FILE *__stream
) __THROW
;
376 /* Write a character to stdout. */
377 extern int putchar (int __c
) __THROW
;
379 /* The C standard explicitly says this can be a macro,
380 so we always do the optimization for it. */
381 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
384 /* Faster version when locking is not necessary. */
385 extern int fputc_unlocked (int __c
, FILE *__stream
) __THROW
;
386 #endif /* Use MISC. */
388 #if defined __USE_POSIX || defined __USE_MISC
389 /* These are defined in POSIX.1:1996. */
390 extern int putc_unlocked (int __c
, FILE *__stream
) __THROW
;
391 extern int putchar_unlocked (int __c
) __THROW
;
392 #endif /* Use POSIX or MISC. */
395 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
396 /* Get a word (int) from STREAM. */
397 extern int getw (FILE *__stream
) __THROW
;
399 /* Write a word (int) to STREAM. */
400 extern int putw (int __w
, FILE *__stream
) __THROW
;
404 /* Get a newline-terminated string of finite length from STREAM. */
405 extern char *fgets (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
409 /* This function does the same as `fgets' but does not lock the stream. */
410 extern char *fgets_unlocked (char *__restrict __s
, int __n
,
411 FILE *__restrict __stream
) __THROW
;
414 /* Get a newline-terminated string from stdin, removing the newline.
415 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
416 extern char *gets (char *__s
) __THROW
;
420 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
421 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
422 NULL), pointing to *N characters of space. It is realloc'd as
423 necessary. Returns the number of characters read (not including the
424 null terminator), or -1 on error or EOF. */
425 extern _IO_ssize_t
__getdelim (char **__restrict __lineptr
,
426 size_t *__restrict __n
, int __delimiter
,
427 FILE *__restrict __stream
) __THROW
;
428 extern _IO_ssize_t
getdelim (char **__restrict __lineptr
,
429 size_t *__restrict __n
, int __delimiter
,
430 FILE *__restrict __stream
) __THROW
;
432 /* Like `getdelim', but reads up to a newline. */
433 extern _IO_ssize_t
getline (char **__restrict __lineptr
,
434 size_t *__restrict __n
,
435 FILE *__restrict __stream
) __THROW
;
439 /* Write a string to STREAM. */
440 extern int fputs (__const
char *__restrict __s
, FILE *__restrict __stream
)
444 /* This function does the same as `fputs' but does not lock the stream. */
445 extern int fputs_unlocked (__const
char *__restrict __s
,
446 FILE *__restrict __stream
) __THROW
;
449 /* Write a string, followed by a newline, to stdout. */
450 extern int puts (__const
char *__s
) __THROW
;
453 /* Push a character back onto the input buffer of STREAM. */
454 extern int ungetc (int __c
, FILE *__stream
) __THROW
;
457 /* Read chunks of generic data from STREAM. */
458 extern size_t fread (void *__restrict __ptr
, size_t __size
,
459 size_t __n
, FILE *__restrict __stream
) __THROW
;
460 /* Write chunks of generic data to STREAM. */
461 extern size_t fwrite (__const
void *__restrict __ptr
, size_t __size
,
462 size_t __n
, FILE *__restrict __s
) __THROW
;
465 /* Faster versions when locking is not necessary. */
466 extern size_t fread_unlocked (void *__restrict __ptr
, size_t __size
,
467 size_t __n
, FILE *__restrict __stream
) __THROW
;
468 extern size_t fwrite_unlocked (__const
void *__restrict __ptr
, size_t __size
,
469 size_t __n
, FILE *__restrict __stream
) __THROW
;
473 /* Seek to a certain position on STREAM. */
474 extern int fseek (FILE *__stream
, long int __off
, int __whence
) __THROW
;
475 /* Return the current position of STREAM. */
476 extern long int ftell (FILE *__stream
) __THROW
;
477 /* Rewind to the beginning of STREAM. */
478 extern void rewind (FILE *__stream
) __THROW
;
480 /* The Single Unix Specification, Version 2, specifies an alternative,
481 more adequate interface for the two functions above which deal with
482 file offset. `long int' is not the right type. These definitions
483 are originally defined in the Large File Support API. */
485 #ifndef __USE_FILE_OFFSET64
486 # ifdef __USE_LARGEFILE
487 /* Seek to a certain position on STREAM. */
488 extern int fseeko (FILE *__stream
, __off_t __off
, int __whence
) __THROW
;
489 /* Return the current position of STREAM. */
490 extern __off_t
ftello (FILE *__stream
) __THROW
;
493 /* Get STREAM's position. */
494 extern int fgetpos (FILE *__restrict __stream
, fpos_t *__restrict __pos
)
496 /* Set STREAM's position. */
497 extern int fsetpos (FILE *__stream
, __const
fpos_t *__pos
) __THROW
;
500 # ifdef __USE_LARGEFILE
501 extern int __REDIRECT (fseeko
,
502 (FILE *__stream
, __off64_t __off
, int __whence
) __THROW
,
504 extern __off64_t
__REDIRECT (ftello
, (FILE *__stream
) __THROW
, ftello64
);
506 extern int __REDIRECT (fgetpos
, (FILE *__restrict __stream
,
507 fpos_t *__restrict __pos
) __THROW
, fgetpos64
);
508 extern int __REDIRECT (fsetpos
,
509 (FILE *__stream
, __const
fpos_t *__pos
) __THROW
,
512 # ifdef __USE_LARGEFILE
513 # define fseeko fseeko64
514 # define ftello ftello64
516 # define fgetpos fgetpos64
517 # define fsetpos fsetpos64
521 #ifdef __USE_LARGEFILE64
522 extern int fseeko64 (FILE *__stream
, __off64_t __off
, int __whence
) __THROW
;
523 extern __off64_t
ftello64 (FILE *__stream
) __THROW
;
524 extern int fgetpos64 (FILE *__restrict __stream
, fpos64_t
*__restrict __pos
)
526 extern int fsetpos64 (FILE *__stream
, __const fpos64_t
*__pos
) __THROW
;
529 /* Clear the error and EOF indicators for STREAM. */
530 extern void clearerr (FILE *__stream
) __THROW
;
531 /* Return the EOF indicator for STREAM. */
532 extern int feof (FILE *__stream
) __THROW
;
533 /* Return the error indicator for STREAM. */
534 extern int ferror (FILE *__stream
) __THROW
;
537 /* Faster versions when locking is not required. */
538 extern void clearerr_unlocked (FILE *__stream
) __THROW
;
539 extern int feof_unlocked (FILE *__stream
) __THROW
;
540 extern int ferror_unlocked (FILE *__stream
) __THROW
;
544 /* Print a message describing the meaning of the value of errno. */
545 extern void perror (__const
char *__s
) __THROW
;
547 /* These variables normally should not be used directly. The `strerror'
548 function provides all the needed functionality. */
551 extern __const
char *__const sys_errlist
[];
554 extern int _sys_nerr
;
555 extern __const
char *__const _sys_errlist
[];
560 /* Return the system file descriptor for STREAM. */
561 extern int fileno (FILE *__stream
) __THROW
;
562 #endif /* Use POSIX. */
565 /* Faster version when locking is not required. */
566 extern int fileno_unlocked (FILE *__stream
) __THROW
;
570 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
572 /* Create a new stream connected to a pipe running the given command. */
573 extern FILE *popen (__const
char *__command
, __const
char *__modes
) __THROW
;
575 /* Close a stream opened by popen and return the status of its child. */
576 extern int pclose (FILE *__stream
) __THROW
;
581 /* Return the name of the controlling terminal. */
582 extern char *ctermid (char *__s
) __THROW
;
583 #endif /* Use POSIX. */
587 /* Return the name of the current user. */
588 extern char *cuserid (char *__s
) __THROW
;
589 #endif /* Use X/Open, but not issue 6. */
593 struct obstack
; /* See <obstack.h>. */
595 /* Write formatted output to an obstack. */
596 extern int obstack_printf (struct obstack
*__restrict __obstack
,
597 __const
char *__restrict __format
, ...) __THROW
;
598 extern int obstack_vprintf (struct obstack
*__restrict __obstack
,
599 __const
char *__restrict __format
,
600 _G_va_list __args
) __THROW
;
601 #endif /* Use GNU. */
604 #if defined __USE_POSIX || defined __USE_MISC
605 /* These are defined in POSIX.1:1996. */
607 /* Acquire ownership of STREAM. */
608 extern void flockfile (FILE *__stream
) __THROW
;
610 /* Try to acquire ownership of STREAM but do not block if it is not
612 extern int ftrylockfile (FILE *__stream
) __THROW
;
614 /* Relinquish the ownership granted for STREAM. */
615 extern void funlockfile (FILE *__stream
) __THROW
;
616 #endif /* POSIX || misc */
618 #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
619 /* The X/Open standard requires some functions and variables to be
620 declared here which do not belong into this header. But we have to
621 follow. In GNU mode we don't do this nonsense. */
622 # define __need_getopt
624 #endif /* X/Open, but not issue 6 and not for GNU. */
626 /* If we are compiling with optimizing read this file. It contains
627 several optimizing inline functions and macros. */
628 #ifdef __USE_EXTERN_INLINES
629 # include <bits/stdio.h>
634 #endif /* <stdio.h> included. */
636 #endif /* !_STDIO_H */