1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 94, 95, 96, 97, 98, 99 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
59 /* The type of the second argument to `fgetpos' and `fsetpos'. */
60 #ifndef __USE_FILE_OFFSET64
61 typedef _G_fpos_t
fpos_t;
63 typedef _G_fpos64_t
fpos_t;
65 #ifdef __USE_LARGEFILE64
66 typedef _G_fpos64_t fpos64_t
;
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. */
77 # define BUFSIZ _IO_BUFSIZ
81 /* End of file character.
82 Some things throughout the library rely on this being -1. */
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"
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/C9x say they're macros. Make them happy. */
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
;
133 extern FILE *__REDIRECT (tmpfile
, (void) __THROW
, tmpfile64
);
135 # define tmpfile tmpfile64
138 #ifdef __USE_LARGEFILE64
139 extern FILE *tmpfile64 (void) __THROW
;
141 /* Generate a temporary filename. */
142 extern char *tmpnam (char *__s
) __THROW
;
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
;
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
) __THROW
;
164 extern int fclose (FILE *__stream
) __THROW
;
165 /* Flush STREAM, or all streams if STREAM is NULL. */
166 extern int fflush (FILE *__stream
) __THROW
;
169 /* Faster versions when locking is not required. */
170 extern int fflush_unlocked (FILE *__stream
) __THROW
;
174 /* Close all streams. */
175 extern int fcloseall (void) __THROW
;
179 #ifndef __USE_FILE_OFFSET64
180 /* Open a file and create a new stream for it. */
181 extern FILE *fopen (__const
char *__restrict __filename
,
182 __const
char *__restrict __modes
) __THROW
;
183 /* Open a file, replacing an existing stream with it. */
184 extern FILE *freopen (__const
char *__restrict __filename
,
185 __const
char *__restrict __modes
,
186 FILE *__restrict __stream
) __THROW
;
189 extern FILE *__REDIRECT (fopen
, (__const
char *__restrict __filename
,
190 __const
char *__restrict __modes
) __THROW
,
192 extern FILE *__REDIRECT (freopen
, (__const
char *__restrict __filename
,
193 __const
char *__restrict __modes
,
194 FILE *__restrict __stream
) __THROW
,
197 # define fopen fopen64
198 # define freopen freopen64
201 #ifdef __USE_LARGEFILE64
202 extern FILE *fopen64 (__const
char *__restrict __filename
,
203 __const
char *__restrict __modes
) __THROW
;
204 extern FILE *freopen64 (__const
char *__restrict __filename
,
205 __const
char *__restrict __modes
,
206 FILE *__restrict __stream
) __THROW
;
210 /* Create a new stream that refers to an existing system file descriptor. */
211 extern FILE *fdopen (int __fd
, __const
char *__modes
) __THROW
;
215 /* Create a new stream that refers to the given magic cookie,
216 and uses the given functions for input and output. */
217 extern FILE *fopencookie (void *__restrict __magic_cookie
,
218 __const
char *__restrict __modes
,
219 _IO_cookie_io_functions_t __io_funcs
) __THROW
;
221 /* Open a stream that writes into a malloc'd buffer that is expanded as
222 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
223 and the number of characters written on fflush or fclose. */
224 extern FILE *open_memstream (char **__restrict __bufloc
,
225 size_t *__restrict __sizeloc
) __THROW
;
229 /* If BUF is NULL, make STREAM unbuffered.
230 Else make it use buffer BUF, of size BUFSIZ. */
231 extern void setbuf (FILE *__restrict __stream
, char *__restrict __buf
) __THROW
;
232 /* Make STREAM use buffering mode MODE.
233 If BUF is not NULL, use N bytes of it for buffering;
234 else allocate an internal buffer N bytes long. */
235 extern int setvbuf (FILE *__restrict __stream
, char *__restrict __buf
,
236 int __modes
, size_t __n
) __THROW
;
239 /* If BUF is NULL, make STREAM unbuffered.
240 Else make it use SIZE bytes of BUF for buffering. */
241 extern void setbuffer (FILE *__restrict __stream
, char *__restrict __buf
,
242 size_t __size
) __THROW
;
244 /* Make STREAM line-buffered. */
245 extern void setlinebuf (FILE *__stream
) __THROW
;
249 /* Write formatted output to STREAM. */
250 extern int fprintf (FILE *__restrict __stream
,
251 __const
char *__restrict __format
, ...) __THROW
;
252 /* Write formatted output to stdout. */
253 extern int printf (__const
char *__restrict __format
, ...) __THROW
;
254 /* Write formatted output to S. */
255 extern int sprintf (char *__restrict __s
,
256 __const
char *__restrict __format
, ...) __THROW
;
258 /* Write formatted output to S from argument list ARG. */
259 extern int vfprintf (FILE *__restrict __s
, __const
char *__restrict __format
,
260 _G_va_list __arg
) __THROW
;
261 /* Write formatted output to stdout from argument list ARG. */
262 extern int vprintf (__const
char *__restrict __format
, _G_va_list __arg
)
264 /* Write formatted output to S from argument list ARG. */
265 extern int vsprintf (char *__restrict __s
, __const
char *__restrict __format
,
266 _G_va_list __arg
) __THROW
;
268 #if defined __USE_BSD || defined __USE_ISOC9X || defined __USE_UNIX98
269 /* Maximum chars of output to write in MAXLEN. */
270 extern int snprintf (char *__restrict __s
, size_t __maxlen
,
271 __const
char *__restrict __format
, ...)
272 __THROW
__attribute__ ((__format__ (__printf__
, 3, 4)));
274 extern int __vsnprintf (char *__restrict __s
, size_t __maxlen
,
275 __const
char *__restrict __format
, _G_va_list __arg
)
276 __THROW
__attribute__ ((__format__ (__printf__
, 3, 0)));
277 extern int vsnprintf (char *__restrict __s
, size_t __maxlen
,
278 __const
char *__restrict __format
, _G_va_list __arg
)
279 __THROW
__attribute__ ((__format__ (__printf__
, 3, 0)));
283 /* Write formatted output to a string dynamically allocated with `malloc'.
284 Store the address of the string in *PTR. */
285 extern int vasprintf (char **__restrict __ptr
, __const
char *__restrict __f
,
287 __THROW
__attribute__ ((__format__ (__printf__
, 2, 0)));
288 extern int __asprintf (char **__restrict __ptr
,
289 __const
char *__restrict __fmt
, ...)
290 __THROW
__attribute__ ((__format__ (__printf__
, 2, 3)));
291 extern int asprintf (char **__restrict __ptr
,
292 __const
char *__restrict __fmt
, ...)
293 __THROW
__attribute__ ((__format__ (__printf__
, 2, 3)));
295 /* Write formatted output to a file descriptor. */
296 extern int vdprintf (int __fd
, __const
char *__restrict __fmt
,
298 __THROW
__attribute__ ((__format__ (__printf__
, 2, 0)));
299 extern int dprintf (int __fd
, __const
char *__restrict __fmt
, ...)
300 __THROW
__attribute__ ((__format__ (__printf__
, 2, 3)));
304 /* Read formatted input from STREAM. */
305 extern int fscanf (FILE *__restrict __stream
,
306 __const
char *__restrict __format
, ...) __THROW
;
307 /* Read formatted input from stdin. */
308 extern int scanf (__const
char *__restrict __format
, ...) __THROW
;
309 /* Read formatted input from S. */
310 extern int sscanf (__const
char *__restrict __s
,
311 __const
char *__restrict __format
, ...) __THROW
;
314 /* Read formatted input from S into argument list ARG. */
315 extern int vfscanf (FILE *__restrict __s
, __const
char *__restrict __format
,
317 __THROW
__attribute__ ((__format__ (__scanf__
, 2, 0)));
319 /* Read formatted input from stdin into argument list ARG. */
320 extern int vscanf (__const
char *__restrict __format
, _G_va_list __arg
)
321 __THROW
__attribute__ ((__format__ (__scanf__
, 1, 0)));
323 /* Read formatted input from S into argument list ARG. */
324 extern int vsscanf (__const
char *__restrict __s
,
325 __const
char *__restrict __format
, _G_va_list __arg
)
326 __THROW
__attribute__ ((__format__ (__scanf__
, 2, 0)));
327 #endif /* Use ISO C9x. */
330 /* Read a character from STREAM. */
331 extern int fgetc (FILE *__stream
) __THROW
;
332 extern int getc (FILE *__stream
) __THROW
;
334 /* Read a character from stdin. */
335 extern int getchar (void) __THROW
;
337 /* The C standard explicitly says this is a macro, so we always do the
338 optimization for it. */
339 #define getc(_fp) _IO_getc (_fp)
341 #if defined __USE_POSIX || defined __USE_MISC
342 /* These are defined in POSIX.1:1996. */
343 extern int getc_unlocked (FILE *__stream
) __THROW
;
344 extern int getchar_unlocked (void) __THROW
;
345 #endif /* Use POSIX or MISC. */
348 /* Faster version when locking is not necessary. */
349 extern int fgetc_unlocked (FILE *__stream
) __THROW
;
350 #endif /* Use MISC. */
353 /* Write a character to STREAM. */
354 extern int fputc (int __c
, FILE *__stream
) __THROW
;
355 extern int putc (int __c
, FILE *__stream
) __THROW
;
357 /* Write a character to stdout. */
358 extern int putchar (int __c
) __THROW
;
360 /* The C standard explicitly says this can be a macro,
361 so we always do the optimization for it. */
362 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
365 /* Faster version when locking is not necessary. */
366 extern int fputc_unlocked (int __c
, FILE *__stream
) __THROW
;
367 #endif /* Use MISC. */
369 #if defined __USE_POSIX || defined __USE_MISC
370 /* These are defined in POSIX.1:1996. */
371 extern int putc_unlocked (int __c
, FILE *__stream
) __THROW
;
372 extern int putchar_unlocked (int __c
) __THROW
;
373 #endif /* Use POSIX or MISC. */
376 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
377 /* Get a word (int) from STREAM. */
378 extern int getw (FILE *__stream
) __THROW
;
380 /* Write a word (int) to STREAM. */
381 extern int putw (int __w
, FILE *__stream
) __THROW
;
385 /* Get a newline-terminated string of finite length from STREAM. */
386 extern char *fgets (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
390 /* This function does the same as `fgets' but does not lock the stream. */
391 extern char *fgets_unlocked (char *__restrict __s
, int __n
,
392 FILE *__restrict __stream
) __THROW
;
395 /* Get a newline-terminated string from stdin, removing the newline.
396 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
397 extern char *gets (char *__s
) __THROW
;
401 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
402 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
403 NULL), pointing to *N characters of space. It is realloc'd as
404 necessary. Returns the number of characters read (not including the
405 null terminator), or -1 on error or EOF. */
406 extern _IO_ssize_t
__getdelim (char **__restrict __lineptr
,
407 size_t *__restrict __n
, int __delimiter
,
408 FILE *__restrict __stream
) __THROW
;
409 extern _IO_ssize_t
getdelim (char **__restrict __lineptr
,
410 size_t *__restrict __n
, int __delimiter
,
411 FILE *__restrict __stream
) __THROW
;
413 /* Like `getdelim', but reads up to a newline. */
414 extern _IO_ssize_t
getline (char **__restrict __lineptr
,
415 size_t *__restrict __n
,
416 FILE *__restrict __stream
) __THROW
;
420 /* Write a string to STREAM. */
421 extern int fputs (__const
char *__restrict __s
, FILE *__restrict __stream
)
425 /* This function does the same as `fputs' but does not lock the stream. */
426 extern int fputs_unlocked (__const
char *__restrict __s
,
427 FILE *__restrict __stream
) __THROW
;
430 /* Write a string, followed by a newline, to stdout. */
431 extern int puts (__const
char *__s
) __THROW
;
434 /* Push a character back onto the input buffer of STREAM. */
435 extern int ungetc (int __c
, FILE *__stream
) __THROW
;
438 /* Read chunks of generic data from STREAM. */
439 extern size_t fread (void *__restrict __ptr
, size_t __size
,
440 size_t __n
, FILE *__restrict __stream
) __THROW
;
441 /* Write chunks of generic data to STREAM. */
442 extern size_t fwrite (__const
void *__restrict __ptr
, size_t __size
,
443 size_t __n
, FILE *__restrict __s
) __THROW
;
446 /* Faster versions when locking is not necessary. */
447 extern size_t fread_unlocked (void *__restrict __ptr
, size_t __size
,
448 size_t __n
, FILE *__restrict __stream
) __THROW
;
449 extern size_t fwrite_unlocked (__const
void *__restrict __ptr
, size_t __size
,
450 size_t __n
, FILE *__restrict __stream
) __THROW
;
454 /* Seek to a certain position on STREAM. */
455 extern int fseek (FILE *__stream
, long int __off
, int __whence
) __THROW
;
456 /* Return the current position of STREAM. */
457 extern long int ftell (FILE *__stream
) __THROW
;
458 /* Rewind to the beginning of STREAM. */
459 extern void rewind (FILE *__stream
) __THROW
;
461 /* The Single Unix Specification, Version 2, specifies an alternative,
462 more adequate interface for the two functions above which deal with
463 file offset. `long int' is not the right type. These definitions
464 are originally defined in the Large File Support API. */
466 /* Types needed in these functions. */
467 #ifndef __off_t_defined
468 # ifndef __USE_FILE_OFFSET64
469 typedef __off_t off_t
;
471 typedef __off64_t off_t
;
473 # define __off_t_defined
476 #if defined __USE_LARGEFILE64 && !defined __off64_t_defined
477 typedef __off64_t off64_t
;
478 # define __off64_t_defined
482 #ifndef __USE_FILE_OFFSET64
484 /* Seek to a certain position on STREAM. */
485 extern int fseeko (FILE *__stream
, __off_t __off
, int __whence
) __THROW
;
486 /* Return the current position of STREAM. */
487 extern __off_t
ftello (FILE *__stream
) __THROW
;
490 /* Get STREAM's position. */
491 extern int fgetpos (FILE *__restrict __stream
, fpos_t *__restrict __pos
)
493 /* Set STREAM's position. */
494 extern int fsetpos (FILE *__stream
, __const
fpos_t *__pos
) __THROW
;
498 extern int __REDIRECT (fseeko
,
499 (FILE *__stream
, __off64_t __off
, int __whence
) __THROW
,
501 extern __off64_t
__REDIRECT (ftello
, (FILE *__stream
) __THROW
, ftello64
);
503 extern int __REDIRECT (fgetpos
, (FILE *__restrict __stream
,
504 fpos_t *__restrict __pos
) __THROW
, fgetpos64
);
505 extern int __REDIRECT (fsetpos
,
506 (FILE *__stream
, __const
fpos_t *__pos
) __THROW
,
510 # define fseeko fseeko64
511 # define ftello ftello64
513 # define fgetpos fgetpos64
514 # define fsetpos fsetpos64
518 #ifdef __USE_LARGEFILE64
520 extern int fseeko64 (FILE *__stream
, __off64_t __off
, int __whence
) __THROW
;
521 extern __off64_t
ftello64 (FILE *__stream
) __THROW
;
523 extern int fgetpos64 (FILE *__restrict __stream
, fpos64_t
*__restrict __pos
)
525 extern int fsetpos64 (FILE *__stream
, __const fpos64_t
*__pos
) __THROW
;
528 /* Clear the error and EOF indicators for STREAM. */
529 extern void clearerr (FILE *__stream
) __THROW
;
530 /* Return the EOF indicator for STREAM. */
531 extern int feof (FILE *__stream
) __THROW
;
532 /* Return the error indicator for STREAM. */
533 extern int ferror (FILE *__stream
) __THROW
;
536 /* Faster versions when locking is not required. */
537 extern void clearerr_unlocked (FILE *__stream
) __THROW
;
538 extern int feof_unlocked (FILE *__stream
) __THROW
;
539 extern int ferror_unlocked (FILE *__stream
) __THROW
;
543 /* Print a message describing the meaning of the value of errno. */
544 extern void perror (__const
char *__s
) __THROW
;
546 /* These variables normally should not be used directly. The `strerror'
547 function provides all the needed functionality. */
550 extern __const
char *__const sys_errlist
[];
553 extern int _sys_nerr
;
554 extern __const
char *__const _sys_errlist
[];
559 /* Return the system file descriptor for STREAM. */
560 extern int fileno (FILE *__stream
) __THROW
;
561 #endif /* Use POSIX. */
564 /* Faster version when locking is not required. */
565 extern int fileno_unlocked (FILE *__stream
) __THROW
;
569 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
571 /* Create a new stream connected to a pipe running the given command. */
572 extern FILE *popen (__const
char *__command
, __const
char *__modes
) __THROW
;
574 /* Close a stream opened by popen and return the status of its child. */
575 extern int pclose (FILE *__stream
) __THROW
;
580 /* Return the name of the controlling terminal. */
581 extern char *ctermid (char *__s
) __THROW
;
582 #endif /* Use POSIX. */
585 #if defined __USE_XOPEN && !defined __USE_XOPEN2K
586 /* Return the name of the current user. */
587 extern char *cuserid (char *__s
) __THROW
;
588 #endif /* Use X/Open, but not issue 6. */
592 struct obstack
; /* See <obstack.h>. */
594 /* Write formatted output to an obstack. */
595 extern int obstack_printf (struct obstack
*__restrict __obstack
,
596 __const
char *__restrict __format
, ...) __THROW
;
597 extern int obstack_vprintf (struct obstack
*__restrict __obstack
,
598 __const
char *__restrict __format
,
599 _G_va_list __args
) __THROW
;
600 #endif /* Use GNU. */
603 #if defined __USE_POSIX || defined __USE_MISC
604 /* These are defined in POSIX.1:1996. */
606 /* Acquire ownership of STREAM. */
607 extern void flockfile (FILE *__stream
) __THROW
;
609 /* Try to acquire ownership of STREAM but do not block if it is not
611 extern int ftrylockfile (FILE *__stream
) __THROW
;
613 /* Relinquish the ownership granted for STREAM. */
614 extern void funlockfile (FILE *__stream
) __THROW
;
615 #endif /* POSIX || misc */
617 #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
618 /* The X/Open standard requires some functions and variables to be
619 declared here which do not belong into this header. But we have to
620 follow. In GNU mode we don't do this nonsense. */
621 # define __need_getopt
623 #endif /* X/Open, but not issue 6 and not for GNU. */
625 /* If we are compiling with optimizing read this file. It contains
626 several optizing inline functions and macros. */
627 #ifdef __USE_EXTERN_INLINES
628 # include <bits/stdio.h>
633 #endif /* <stdio.h> included. */
635 #endif /* !_STDIO_H */