1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 94, 95, 96, 97, 98 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>
27 # include <features.h>
31 # define __need_size_t
36 # define __need___va_list
40 # include <bits/types.h>
41 #endif /* Don't 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. */
55 #define _STDIO_USES_IOSTREAM
60 # define __STDIO_INLINE inline
62 # define __STDIO_INLINE extern __inline
65 /* The type of the second argument to `fgetpos' and `fsetpos'. */
66 #ifndef __USE_FILE_OFFSET64
67 typedef _G_fpos_t
fpos_t;
69 typedef _G_fpos64_t
fpos_t;
71 #ifdef __USE_LARGEFILE64
72 typedef _G_fpos64_t fpos64_t
;
75 /* The possibilities for the third argument to `setvbuf'. */
76 #define _IOFBF 0 /* Fully buffered. */
77 #define _IOLBF 1 /* Line buffered. */
78 #define _IONBF 2 /* No buffering. */
81 /* Default buffer size. */
83 # define BUFSIZ _IO_BUFSIZ
87 /* End of file character.
88 Some things throughout the library rely on this being -1. */
94 /* The possibilities for the third argument to `fseek'.
95 These values should not be changed. */
96 #define SEEK_SET 0 /* Seek from beginning of file. */
97 #define SEEK_CUR 1 /* Seek from current position. */
98 #define SEEK_END 2 /* Seek from end of file. */
101 #if defined __USE_SVID || defined __USE_XOPEN
102 /* Default path prefix for `tempnam' and `tmpnam'. */
103 # define P_tmpdir "/tmp"
108 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
109 TMP_MAX The minimum number of unique filenames generated by tmpnam
110 (and tempnam when it uses tmpnam's name space),
111 or tempnam (the two are separate).
112 L_ctermid How long an array to pass to `ctermid'.
113 L_cuserid How long an array to pass to `cuserid'.
114 FOPEN_MAX Minimum number of files that can be open at once.
115 FILENAME_MAX Maximum length of a filename. */
116 #include <bits/stdio_lim.h>
119 /* Standard streams. */
120 extern FILE *stdin
; /* Standard input stream. */
121 extern FILE *stdout
; /* Standard output stream. */
122 extern FILE *stderr
; /* Standard error output stream. */
125 /* Remove file FILENAME. */
126 extern int remove
__P ((__const
char *__filename
));
127 /* Rename file OLD to NEW. */
128 extern int rename
__P ((__const
char *__old
, __const
char *__new
));
131 /* Create a temporary file and open it read/write. */
132 #ifndef __USE_FILE_OFFSET64
133 extern FILE *tmpfile
__P ((void));
136 extern FILE *__REDIRECT (tmpfile
, __P ((void)), tmpfile64
);
138 # define tmpfile tmpfile64
141 #ifdef __USE_LARGEFILE64
142 extern FILE *tmpfile64
__P ((void));
144 /* Generate a temporary filename. */
145 extern char *tmpnam
__P ((char *__s
));
148 /* This is the reentrant variant of `tmpnam'. The only difference is
149 that it does not allow S to be NULL. */
150 extern char *tmpnam_r
__P ((char *__s
));
154 #if defined __USE_SVID || defined __USE_XOPEN
155 /* Generate a unique temporary filename using up to five characters of PFX
156 if it is not NULL. The directory to put this file in is searched for
157 as follows: First the environment variable "TMPDIR" is checked.
158 If it contains the name of a writable directory, that directory is used.
159 If not and if DIR is not NULL, that value is checked. If that fails,
160 P_tmpdir is tried and finally "/tmp". The storage for the filename
161 is allocated by `malloc'. */
162 extern char *tempnam
__P ((__const
char *__dir
, __const
char *__pfx
));
167 extern int fclose
__P ((FILE *__stream
));
168 /* Flush STREAM, or all streams if STREAM is NULL. */
169 extern int fflush
__P ((FILE *__stream
));
172 /* Faster versions when locking is not required. */
173 extern int fflush_unlocked
__P ((FILE *__stream
));
177 /* Close all streams. */
178 extern int fcloseall
__P ((void));
182 #ifndef __USE_FILE_OFFSET64
183 /* Open a file and create a new stream for it. */
184 extern FILE *fopen
__P ((__const
char *__restrict __filename
,
185 __const
char *__restrict __modes
));
186 /* Open a file, replacing an existing stream with it. */
187 extern FILE *freopen
__P ((__const
char *__restrict __filename
,
188 __const
char *__restrict __modes
,
189 FILE *__restrict __stream
));
192 extern FILE *__REDIRECT (fopen
, __P ((__const
char *__restrict __filename
,
193 __const
char *__restrict __modes
)),
195 extern FILE *__REDIRECT (freopen
, __P ((__const
char *__restrict __filename
,
196 __const
char *__restrict __modes
,
197 FILE *__restrict __stream
)),
200 # define fopen fopen64
201 # define freopen freopen64
204 #ifdef __USE_LARGEFILE64
205 extern FILE *fopen64
__P ((__const
char *__restrict __filename
,
206 __const
char *__restrict __modes
));
207 extern FILE *freopen64
__P ((__const
char *__restrict __filename
,
208 __const
char *__restrict __modes
,
209 FILE *__restrict __stream
));
213 /* Create a new stream that refers to an existing system file descriptor. */
214 extern FILE *fdopen
__P ((int __fd
, __const
char *__modes
));
218 /* Create a new stream that refers to the given magic cookie,
219 and uses the given functions for input and output. */
220 extern FILE *fopencookie
__P ((void *__magic_cookie
, __const
char *__modes
,
221 _IO_cookie_io_functions_t __io_funcs
));
223 /* Open a stream that writes into a malloc'd buffer that is expanded as
224 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
225 and the number of characters written on fflush or fclose. */
226 extern FILE *open_memstream
__P ((char **__bufloc
, size_t *__sizeloc
));
230 /* If BUF is NULL, make STREAM unbuffered.
231 Else make it use buffer BUF, of size BUFSIZ. */
232 extern void setbuf
__P ((FILE *__restrict __stream
, char *__restrict __buf
));
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
__P ((FILE *__restrict __stream
, char *__restrict __buf
,
237 int __modes
, size_t __n
));
240 /* If BUF is NULL, make STREAM unbuffered.
241 Else make it use SIZE bytes of BUF for buffering. */
242 extern void setbuffer
__P ((FILE *__stream
, char *__buf
, size_t __size
));
244 /* Make STREAM line-buffered. */
245 extern void setlinebuf
__P ((FILE *__stream
));
249 /* Write formatted output to STREAM. */
250 extern int fprintf
__P ((FILE *__restrict __stream
,
251 __const
char *__restrict __format
, ...));
252 /* Write formatted output to stdout. */
253 extern int printf
__P ((__const
char *__restrict __format
, ...));
254 /* Write formatted output to S. */
255 extern int sprintf
__P ((char *__restrict __s
,
256 __const
char *__restrict __format
, ...));
258 /* Write formatted output to S from argument list ARG. */
259 extern int vfprintf
__P ((FILE *__restrict __s
,
260 __const
char *__restrict __format
,
262 /* Write formatted output to stdout from argument list ARG. */
263 extern int vprintf
__P ((__const
char *__restrict __format
,
265 /* Write formatted output to S from argument list ARG. */
266 extern int vsprintf
__P ((char *__restrict __s
,
267 __const
char *__restrict __format
,
270 #ifdef __USE_EXTERN_INLINES
272 vprintf (__const
char *__restrict __fmt
, _G_va_list __arg
) __THROW
274 return vfprintf (stdout
, __fmt
, __arg
);
276 #endif /* Use extern inlines. */
278 #if defined __USE_BSD || defined __USE_ISOC9X || defined __USE_UNIX98
279 /* Maximum chars of output to write in MAXLEN. */
280 extern int snprintf
__P ((char *__restrict __s
, size_t __maxlen
,
281 __const
char *__restrict __format
, ...))
282 __attribute__ ((__format__ (__printf__
, 3, 4)));
284 extern int __vsnprintf
__P ((char *__restrict __s
, size_t __maxlen
,
285 __const
char *__restrict __format
,
287 __attribute__ ((__format__ (__printf__
, 3, 0)));
288 extern int vsnprintf
__P ((char *__restrict __s
, size_t __maxlen
,
289 __const
char *__restrict __format
,
291 __attribute__ ((__format__ (__printf__
, 3, 0)));
295 /* Write formatted output to a string dynamically allocated with `malloc'.
296 Store the address of the string in *PTR. */
297 extern int vasprintf
__P ((char **__restrict __ptr
,
298 __const
char *__restrict __f
, _G_va_list __arg
))
299 __attribute__ ((__format__ (__printf__
, 2, 0)));
300 extern int __asprintf
__P ((char **__restrict __ptr
,
301 __const
char *__restrict __fmt
, ...))
302 __attribute__ ((__format__ (__printf__
, 2, 3)));
303 extern int asprintf
__P ((char **__restrict __ptr
,
304 __const
char *__restrict __fmt
, ...))
305 __attribute__ ((__format__ (__printf__
, 2, 3)));
307 /* Write formatted output to a file descriptor. */
308 extern int vdprintf
__P ((int __fd
, __const
char *__restrict __fmt
,
310 __attribute__ ((__format__ (__printf__
, 2, 0)));
311 extern int dprintf
__P ((int __fd
, __const
char *__restrict __fmt
, ...))
312 __attribute__ ((__format__ (__printf__
, 2, 3)));
316 /* Read formatted input from STREAM. */
317 extern int fscanf
__P ((FILE *__restrict __stream
,
318 __const
char *__restrict __format
, ...));
319 /* Read formatted input from stdin. */
320 extern int scanf
__P ((__const
char *__restrict __format
, ...));
321 /* Read formatted input from S. */
322 extern int sscanf
__P ((__const
char *__restrict __s
,
323 __const
char *__restrict __format
, ...));
326 /* Read formatted input from S into argument list ARG. */
327 extern int vfscanf
__P ((FILE *__restrict __s
,
328 __const
char *__restrict __format
,
330 __attribute__ ((__format__ (__scanf__
, 2, 0)));
332 /* Read formatted input from stdin into argument list ARG. */
333 extern int vscanf
__P ((__const
char *__restrict __format
, _G_va_list __arg
))
334 __attribute__ ((__format__ (__scanf__
, 1, 0)));
336 /* Read formatted input from S into argument list ARG. */
337 extern int vsscanf
__P ((__const
char *__restrict __s
,
338 __const
char *__restrict __format
,
340 __attribute__ ((__format__ (__scanf__
, 2, 0)));
341 #endif /* Use ISO C9x. */
344 /* Read a character from STREAM. */
345 extern int fgetc
__P ((FILE *__stream
));
346 extern int getc
__P ((FILE *__stream
));
348 /* Read a character from stdin. */
349 extern int getchar
__P ((void));
351 /* The C standard explicitly says this is a macro, so we always do the
352 optimization for it. */
353 #define getc(_fp) _IO_getc (_fp)
355 #ifdef __USE_EXTERN_INLINES
357 getchar (void) __THROW
359 return _IO_getc (stdin
);
361 #endif /* Use extern inlines. */
363 #if defined __USE_POSIX || defined __USE_MISC
364 /* These are defined in POSIX.1:1996. */
365 extern int getc_unlocked
__P ((FILE *__stream
));
366 extern int getchar_unlocked
__P ((void));
368 # ifdef __USE_EXTERN_INLINES
370 getc_unlocked (FILE *__fp
) __THROW
372 return _IO_getc_unlocked (__fp
);
376 getchar_unlocked (void) __THROW
378 return _IO_getc_unlocked (stdin
);
380 # endif /* Use extern inlines. */
381 #endif /* Use POSIX or MISC. */
384 /* Write a character to STREAM. */
385 extern int fputc
__P ((int __c
, FILE *__stream
));
386 extern int putc
__P ((int __c
, FILE *__stream
));
388 /* Write a character to stdout. */
389 extern int putchar
__P ((int __c
));
391 /* The C standard explicitly says this can be a macro,
392 so we always do the optimization for it. */
393 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
395 #ifdef __USE_EXTERN_INLINES
397 putchar (int __c
) __THROW
399 return _IO_putc (__c
, stdout
);
401 #endif /* Use extern inlines. */
404 /* Faster version when locking is not necessary. */
405 extern int fputc_unlocked
__P ((int __c
, FILE *__stream
));
407 # ifdef __USE_EXTERN_INLINES
409 fputc_unlocked (int __c
, FILE *__stream
) __THROW
411 return _IO_putc_unlocked (__c
, __stream
);
413 # endif /* Use extern inlines. */
414 #endif /* Use MISC. */
416 #if defined __USE_POSIX || defined __USE_MISC
417 /* These are defined in POSIX.1:1996. */
418 extern int putc_unlocked
__P ((int __c
, FILE *__stream
));
419 extern int putchar_unlocked
__P ((int __c
));
421 # ifdef __USE_EXTERN_INLINES
423 putc_unlocked (int __c
, FILE *__stream
) __THROW
425 return _IO_putc_unlocked (__c
, __stream
);
429 putchar_unlocked (int __c
) __THROW
431 return _IO_putc_unlocked (__c
, stdout
);
433 # endif /* Use extern inlines. */
434 #endif /* Use POSIX or MISC. */
437 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
438 /* Get a word (int) from STREAM. */
439 extern int getw
__P ((FILE *__stream
));
441 /* Write a word (int) to STREAM. */
442 extern int putw
__P ((int __w
, FILE *__stream
));
446 /* Get a newline-terminated string of finite length from STREAM. */
447 extern char *fgets
__P ((char *__restrict __s
, int __n
,
448 FILE *__restrict __stream
));
451 /* This function does the same as `fgets' but does not lock the stream. */
452 extern char *fgets_unlocked
__P ((char *__restrict __s
, int __n
,
453 FILE *__restrict __stream
));
456 /* Get a newline-terminated string from stdin, removing the newline.
457 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
458 extern char *gets
__P ((char *__s
));
462 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
463 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
464 NULL), pointing to *N characters of space. It is realloc'd as
465 necessary. Returns the number of characters read (not including the
466 null terminator), or -1 on error or EOF. */
467 extern _IO_ssize_t __getdelim
__P ((char **__lineptr
, size_t *__n
,
468 int __delimiter
, FILE *__stream
));
469 extern _IO_ssize_t getdelim
__P ((char **__lineptr
, size_t *__n
,
470 int __delimiter
, FILE *__stream
));
472 /* Like `getdelim', but reads up to a newline. */
473 extern _IO_ssize_t getline
__P ((char **__lineptr
, size_t *__n
,
476 # ifdef __USE_EXTERN_INLINES
477 __STDIO_INLINE _IO_ssize_t
478 getline (char **__lineptr
, size_t *__n
, FILE *__stream
) __THROW
480 return __getdelim (__lineptr
, __n
, '\n', __stream
);
482 # endif /* Use extern inlines. */
486 /* Write a string to STREAM. */
487 extern int fputs
__P ((__const
char *__restrict __s
,
488 FILE *__restrict __stream
));
491 /* This function does the same as `fputs' but does not lock the stream. */
492 extern int fputs_unlocked
__P ((__const
char *__restrict __s
,
493 FILE *__restrict __stream
));
496 /* Write a string, followed by a newline, to stdout. */
497 extern int puts
__P ((__const
char *__s
));
500 /* Push a character back onto the input buffer of STREAM. */
501 extern int ungetc
__P ((int __c
, FILE *__stream
));
504 /* Read chunks of generic data from STREAM. */
505 extern size_t fread
__P ((void *__restrict __ptr
, size_t __size
,
506 size_t __n
, FILE *__restrict __stream
));
507 /* Write chunks of generic data to STREAM. */
508 extern size_t fwrite
__P ((__const
void *__restrict __ptr
, size_t __size
,
509 size_t __n
, FILE *__restrict __s
));
512 /* Faster versions when locking is not necessary. */
513 extern size_t fread_unlocked
__P ((void *__restrict __ptr
, size_t __size
,
514 size_t __n
, FILE *__restrict __stream
));
515 extern size_t fwrite_unlocked
__P ((__const
void *__restrict __ptr
,
516 size_t __size
, size_t __n
,
517 FILE *__restrict __stream
));
521 /* Seek to a certain position on STREAM. */
522 extern int fseek
__P ((FILE *__stream
, long int __off
, int __whence
));
523 /* Return the current position of STREAM. */
524 extern long int ftell
__P ((FILE *__stream
));
525 /* Rewind to the beginning of STREAM. */
526 extern void rewind
__P ((FILE *__stream
));
528 /* The Single Unix Specification, Version 2, specifies an alternative,
529 more adequate interface for the two functions above which deal with
530 file offset. `long int' is not the right type. These definitions
531 are originally defined in the Large File Support API. */
533 /* Types needed in these functions. */
535 # ifndef __USE_FILE_OFFSET64
536 typedef __off_t off_t
;
538 typedef __off64_t off_t
;
543 #if defined __USE_LARGEFILE64 && !defined off64_t
544 typedef __off64_t off64_t
;
545 # define off64_t off64_t
549 #ifndef __USE_FILE_OFFSET64
551 /* Seek to a certain position on STREAM. */
552 extern int fseeko
__P ((FILE *__stream
, __off_t __off
, int __whence
));
553 /* Return the current position of STREAM. */
554 extern __off_t ftello
__P ((FILE *__stream
));
557 /* Get STREAM's position. */
558 extern int fgetpos
__P ((FILE *__restrict __stream
,
559 fpos_t *__restrict __pos
));
560 /* Set STREAM's position. */
561 extern int fsetpos
__P ((FILE *__stream
, __const
fpos_t *__pos
));
565 extern int __REDIRECT (fseeko
,
566 __P ((FILE *__stream
, __off64_t __off
, int __whence
)),
568 extern __off64_t
__REDIRECT (ftello
, __P ((FILE *__stream
)), ftello64
);
570 extern int __REDIRECT (fgetpos
, __P ((FILE *__restrict __stream
,
571 fpos_t *__restrict __pos
)), fgetpos64
);
572 extern int __REDIRECT (fsetpos
, __P ((FILE *__stream
, __const
fpos_t *__pos
)),
576 # define fseeko fseeko64
577 # define ftello ftello64
579 # define fgetpos fgetpos64
580 # define fsetpos fsetpos64
584 #ifdef __USE_LARGEFILE64
586 extern int fseeko64
__P ((FILE *__stream
, __off64_t __off
, int __whence
));
587 extern __off64_t ftello64
__P ((FILE *__stream
));
589 extern int fgetpos64
__P ((FILE *__restrict __stream
,
590 fpos64_t
*__restrict __pos
));
591 extern int fsetpos64
__P ((FILE *__stream
, __const fpos64_t
*__pos
));
594 /* Clear the error and EOF indicators for STREAM. */
595 extern void clearerr
__P ((FILE *__stream
));
596 /* Return the EOF indicator for STREAM. */
597 extern int feof
__P ((FILE *__stream
));
598 /* Return the error indicator for STREAM. */
599 extern int ferror
__P ((FILE *__stream
));
602 /* Faster versions when locking is not required. */
603 extern void clearerr_unlocked
__P ((FILE *__stream
));
604 extern int feof_unlocked
__P ((FILE *__stream
));
605 extern int ferror_unlocked
__P ((FILE *__stream
));
607 # ifdef __USE_EXTERN_INLINES
609 feof_unlocked (FILE *__stream
) __THROW
611 return _IO_feof_unlocked (__stream
);
615 ferror_unlocked (FILE *__stream
) __THROW
617 return _IO_ferror_unlocked (__stream
);
619 # endif /* Use extern inlines. */
623 /* Print a message describing the meaning of the value of errno. */
624 extern void perror
__P ((__const
char *__s
));
626 /* These variables normally should not be used directly. The `strerror'
627 function provides all the needed functionality. */
630 extern __const
char *__const sys_errlist
[];
633 extern int _sys_nerr
;
634 extern __const
char *__const _sys_errlist
[];
639 /* Return the system file descriptor for STREAM. */
640 extern int fileno
__P ((FILE *__stream
));
641 #endif /* Use POSIX. */
644 /* Faster version when locking is not required. */
645 extern int fileno_unlocked
__P ((FILE *__stream
));
649 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
651 /* Create a new stream connected to a pipe running the given command. */
652 extern FILE *popen
__P ((__const
char *__command
, __const
char *__modes
));
654 /* Close a stream opened by popen and return the status of its child. */
655 extern int pclose
__P ((FILE *__stream
));
660 /* Return the name of the controlling terminal. */
661 extern char *ctermid
__P ((char *__s
));
662 #endif /* Use POSIX. */
666 /* Return the name of the current user. */
667 extern char *cuserid
__P ((char *__s
));
668 #endif /* Use X/Open. */
672 struct obstack
; /* See <obstack.h>. */
674 /* Write formatted output to an obstack. */
675 extern int obstack_printf
__P ((struct obstack
*__obstack
,
676 __const
char *__format
, ...));
677 extern int obstack_vprintf
__P ((struct obstack
*__obstack
,
678 __const
char *__format
,
680 #endif /* Use GNU. */
683 #if defined __USE_POSIX || defined __USE_MISC
684 /* These are defined in POSIX.1:1996. */
686 /* Acquire ownership of STREAM. */
687 extern void flockfile
__P ((FILE *__stream
));
689 /* Try to acquire ownership of STREAM but do not block if it is not
691 extern int ftrylockfile
__P ((FILE *__stream
));
693 /* Relinquish the ownership granted for STREAM. */
694 extern void funlockfile
__P ((FILE *__stream
));
695 #endif /* POSIX || misc */
697 #if defined __USE_XOPEN && !defined __USE_GNU
698 /* The X/Open standard requires some functions and variables to be
699 declared here which do not belong into this header. But we have to
700 follow. In GNU mode we don't do this nonsense. */
701 # define __need_getopt
707 /* Define helper macro. */
708 #undef __STDIO_INLINE
710 #endif /* <stdio.h> included. */
712 #endif /* !_STDIO_H */