1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 1994, 1995, 1996, 1997 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>
25 #if !defined __need_FILE
35 #include <bits/types.h>
36 #endif /* Don't need FILE. */
40 #ifndef __FILE_defined
42 /* The opaque type of streams. */
43 typedef struct _IO_FILE
FILE;
45 #define __FILE_defined 1
46 #endif /* FILE not defined. */
50 #define _STDIO_USES_IOSTREAM
55 # define __STDIO_INLINE inline
57 # define __STDIO_INLINE extern __inline
60 /* The type of the second argument to `fgetpos' and `fsetpos'. */
61 typedef _G_fpos_t
fpos_t;
64 /* Generate a unique file name (and possibly open it with mode "w+b"). */
65 extern char *__stdio_gen_tempname
__P ((char *__buf
, size_t __bufsize
,
73 /* Print out MESSAGE on the error output and abort. */
74 extern void __libc_fatal
__P ((__const
char *__message
))
75 __attribute__ ((__noreturn__
));
78 /* The possibilities for the third argument to `setvbuf'. */
79 #define _IOFBF 0 /* Fully buffered. */
80 #define _IOLBF 1 /* Line buffered. */
81 #define _IONBF 2 /* No buffering. */
84 /* Default buffer size. */
86 #define BUFSIZ _IO_BUFSIZ
90 /* End of file character.
91 Some things throughout the library rely on this being -1. */
97 /* The possibilities for the third argument to `fseek'.
98 These values should not be changed. */
99 #define SEEK_SET 0 /* Seek from beginning of file. */
100 #define SEEK_CUR 1 /* Seek from current position. */
101 #define SEEK_END 2 /* Seek from end of file. */
105 /* Default path prefix for `tempnam' and `tmpnam'. */
106 #define P_tmpdir "/tmp"
111 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
112 TMP_MAX The minimum number of unique filenames generated by tmpnam
113 (and tempnam when it uses tmpnam's name space),
114 or tempnam (the two are separate).
115 L_ctermid How long an array to pass to `ctermid'.
116 L_cuserid How long an array to pass to `cuserid'.
117 FOPEN_MAX Minimum number of files that can be open at once.
118 FILENAME_MAX Maximum length of a filename. */
119 #include <bits/stdio_lim.h>
122 /* Standard streams. */
123 extern FILE *stdin
, *stdout
, *stderr
;
124 /* Refer to the real names by default. */
125 #define stdin _IO_stdin
126 #define stdout _IO_stdout
127 #define stderr _IO_stderr
130 /* Remove file FILENAME. */
131 extern int remove
__P ((__const
char *__filename
));
132 /* Rename file OLD to NEW. */
133 extern int rename
__P ((__const
char *__old
, __const
char *__new
));
136 /* Create a temporary file and open it read/write. */
137 extern FILE *tmpfile
__P ((void));
138 /* Generate a temporary filename. */
139 extern char *tmpnam
__P ((char *__s
));
142 /* This is the reentrant variant of `tmpnam'. The only difference is
143 that it does not allow S to be NULL. */
144 extern char *tmpnam_r
__P ((char *__s
));
148 #if defined __USE_SVID || defined __USE_XOPEN
149 /* Generate a unique temporary filename using up to five characters of PFX
150 if it is not NULL. The directory to put this file in is searched for
151 as follows: First the environment variable "TMPDIR" is checked.
152 If it contains the name of a writable directory, that directory is used.
153 If not and if DIR is not NULL, that value is checked. If that fails,
154 P_tmpdir is tried and finally "/tmp". The storage for the filename
155 is allocated by `malloc'. */
156 extern char *tempnam
__P ((__const
char *__dir
, __const
char *__pfx
));
161 extern int fclose
__P ((FILE *__stream
));
162 /* Flush STREAM, or all streams if STREAM is NULL. */
163 extern int fflush
__P ((FILE *__stream
));
166 /* Faster versions when locking is not required. */
167 extern int fclose_unlocked
__P ((FILE *__stream
));
168 extern int fflush_unlocked
__P ((FILE *__stream
));
172 /* Close all streams. */
173 extern int __fcloseall
__P ((void));
174 extern int fcloseall
__P ((void));
178 /* Open a file and create a new stream for it. */
179 extern FILE *fopen
__P ((__const
char *__filename
, __const
char *__modes
));
180 /* Open a file, replacing an existing stream with it. */
181 extern FILE *freopen
__P ((__const
char *__restrict __filename
,
182 __const
char *__restrict __modes
,
183 FILE *__restrict __stream
));
186 /* Create a new stream that refers to an existing system file descriptor. */
187 extern FILE *fdopen
__P ((int __fd
, __const
char *__modes
));
191 /* Create a new stream that refers to the given magic cookie,
192 and uses the given functions for input and output. */
193 extern FILE *fopencookie
__P ((void *__magic_cookie
, __const
char *__modes
,
194 _IO_cookie_io_functions_t __io_funcs
));
196 /* Open a stream that writes into a malloc'd buffer that is expanded as
197 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
198 and the number of characters written on fflush or fclose. */
199 extern FILE *open_memstream
__P ((char **__bufloc
, size_t *__sizeloc
));
203 /* If BUF is NULL, make STREAM unbuffered.
204 Else make it use buffer BUF, of size BUFSIZ. */
205 extern void setbuf
__P ((FILE *__restrict __stream
, char *__restrict __buf
));
206 /* Make STREAM use buffering mode MODE.
207 If BUF is not NULL, use N bytes of it for buffering;
208 else allocate an internal buffer N bytes long. */
209 extern int setvbuf
__P ((FILE *__restrict __stream
, char *__restrict __buf
,
210 int __modes
, size_t __n
));
213 /* If BUF is NULL, make STREAM unbuffered.
214 Else make it use SIZE bytes of BUF for buffering. */
215 extern void setbuffer
__P ((FILE *__stream
, char *__buf
, size_t __size
));
217 /* Make STREAM line-buffered. */
218 extern void setlinebuf
__P ((FILE *__stream
));
222 /* Write formatted output to STREAM. */
223 extern int fprintf
__P ((FILE *__restrict __stream
,
224 __const
char *__restrict __format
, ...));
225 /* Write formatted output to stdout. */
226 extern int printf
__P ((__const
char *__restrict __format
, ...));
227 /* Write formatted output to S. */
228 extern int sprintf
__P ((char *__restrict __s
,
229 __const
char *__restrict __format
, ...));
231 /* Write formatted output to S from argument list ARG. */
232 extern int vfprintf
__P ((FILE *__restrict __s
,
233 __const
char *__restrict __format
,
235 /* Write formatted output to stdout from argument list ARG. */
236 extern int vprintf
__P ((__const
char *__restrict __format
,
238 /* Write formatted output to S from argument list ARG. */
239 extern int vsprintf
__P ((char *__restrict __s
,
240 __const
char *__restrict __format
,
245 vprintf (const char *__restrict __fmt
, _G_va_list __arg
)
247 return vfprintf (stdout
, __fmt
, __arg
);
249 #endif /* Optimizing. */
251 #if defined __USE_BSD || defined __USE_ISOC9X
252 /* Maximum chars of output to write in MAXLEN. */
253 extern int __snprintf
__P ((char *__restrict __s
, size_t __maxlen
,
254 __const
char *__restrict __format
, ...))
255 __attribute__ ((__format__ (__printf__
, 3, 4)));
256 extern int snprintf
__P ((char *__restrict __s
, size_t __maxlen
,
257 __const
char *__restrict __format
, ...))
258 __attribute__ ((__format__ (__printf__
, 3, 4)));
260 extern int __vsnprintf
__P ((char *__restrict __s
, size_t __maxlen
,
261 __const
char *__restrict __format
,
263 __attribute__ ((__format__ (__printf__
, 3, 0)));
264 extern int vsnprintf
__P ((char *__restrict __s
, size_t __maxlen
,
265 __const
char *__restrict __format
,
267 __attribute__ ((__format__ (__printf__
, 3, 0)));
271 /* Write formatted output to a string dynamically allocated with `malloc'.
272 Store the address of the string in *PTR. */
273 extern int vasprintf
__P ((char **__restrict __ptr
,
274 __const
char *__restrict __f
, _G_va_list __arg
))
275 __attribute__ ((__format__ (__printf__
, 2, 0)));
276 extern int asprintf
__P ((char **__restrict __ptr
,
277 __const
char *__restrict __fmt
, ...))
278 __attribute__ ((__format__ (__printf__
, 2, 3)));
280 /* Write formatted output to a file descriptor. */
281 extern int vdprintf
__P ((int __fd
, __const
char *__restrict __fmt
,
283 __attribute__ ((__format__ (__printf__
, 2, 0)));
284 extern int dprintf
__P ((int __fd
, __const
char *__restrict __fmt
, ...))
285 __attribute__ ((__format__ (__printf__
, 2, 3)));
289 /* Read formatted input from STREAM. */
290 extern int fscanf
__P ((FILE *__restrict __stream
,
291 __const
char *__restrict __format
, ...));
292 /* Read formatted input from stdin. */
293 extern int scanf
__P ((__const
char *__restrict __format
, ...));
294 /* Read formatted input from S. */
295 extern int sscanf
__P ((__const
char *__restrict __s
,
296 __const
char *__restrict __format
, ...));
299 /* Read formatted input from S into argument list ARG. */
300 extern int __vfscanf
__P ((FILE *__restrict __s
,
301 __const
char *__restrict __format
,
303 __attribute__ ((__format__ (__scanf__
, 2, 0)));
304 extern int vfscanf
__P ((FILE *__restrict __s
,
305 __const
char *__restrict __format
,
307 __attribute__ ((__format__ (__scanf__
, 2, 0)));
309 /* Read formatted input from stdin into argument list ARG. */
310 extern int __vscanf
__P ((__const
char *__restrict __format
,
312 __attribute__ ((__format__ (__scanf__
, 1, 0)));
313 extern int vscanf
__P ((__const
char *__restrict __format
, _G_va_list __arg
))
314 __attribute__ ((__format__ (__scanf__
, 1, 0)));
316 /* Read formatted input from S into argument list ARG. */
317 extern int __vsscanf
__P ((__const
char *__restrict __s
,
318 __const
char *__restrict __format
,
320 __attribute__ ((__format__ (__scanf__
, 2, 0)));
321 extern int vsscanf
__P ((__const
char *__restrict __s
,
322 __const
char *__restrict __format
,
324 __attribute__ ((__format__ (__scanf__
, 2, 0)));
325 #endif /* Use GNU. */
328 /* Read a character from STREAM. */
329 extern int fgetc
__P ((FILE *__stream
));
330 extern int getc
__P ((FILE *__stream
));
332 /* Read a character from stdin. */
333 extern int getchar
__P ((void));
335 /* The C standard explicitly says this is a macro, so we always do the
336 optimization for it. */
337 #define getc(_fp) _IO_getc (_fp)
343 return _IO_getc (stdin
);
345 #endif /* Optimizing. */
347 #if defined __USE_POSIX || defined __USE_MISC
348 /* These are defined in POSIX.1:1996. */
349 extern int getc_unlocked
__P ((FILE *__stream
));
350 extern int getchar_unlocked
__P ((void));
354 getc_unlocked (FILE *__fp
)
356 return _IO_getc_unlocked (__fp
);
360 getchar_unlocked (void)
362 return _IO_getc_unlocked (stdin
);
364 #endif /* Optimizing. */
365 #endif /* Use POSIX or MISC. */
368 /* Write a character to STREAM. */
369 extern int fputc
__P ((int __c
, FILE *__stream
));
370 extern int putc
__P ((int __c
, FILE *__stream
));
372 /* Write a character to stdout. */
373 extern int putchar
__P ((int __c
));
375 /* The C standard explicitly says this can be a macro,
376 so we always do the optimization for it. */
377 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
383 return _IO_putc (__c
, stdout
);
388 /* Faster version when locking is not necessary. */
389 extern int fputc_unlocked
__P ((int __c
, FILE *__stream
));
393 fputc_unlocked (int __c
, FILE *__stream
)
395 return _IO_putc_unlocked (__c
, __stream
);
397 #endif /* Optimizing. */
398 #endif /* Use MISC. */
400 #if defined __USE_POSIX || defined __USE_MISC
401 /* These are defined in POSIX.1:1996. */
402 extern int putc_unlocked
__P ((int __c
, FILE *__stream
));
403 extern int putchar_unlocked
__P ((int __c
));
407 putc_unlocked (int __c
, FILE *__stream
)
409 return _IO_putc_unlocked (__c
, __stream
);
413 putchar_unlocked (int __c
)
415 return _IO_putc_unlocked (__c
, stdout
);
417 #endif /* Optimizing. */
418 #endif /* Use POSIX or MISc. */
421 #if defined __USE_SVID || defined __USE_MISC
422 /* Get a word (int) from STREAM. */
423 extern int getw
__P ((FILE *__stream
));
425 /* Write a word (int) to STREAM. */
426 extern int putw
__P ((int __w
, FILE *__stream
));
430 /* Get a newline-terminated string of finite length from STREAM. */
431 extern char *fgets
__P ((char *__restrict __s
, int __n
,
432 FILE *__restrict __stream
));
434 /* Get a newline-terminated string from stdin, removing the newline.
435 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
436 extern char *gets
__P ((char *__s
));
440 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
441 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
442 NULL), pointing to *N characters of space. It is realloc'd as
443 necessary. Returns the number of characters read (not including the
444 null terminator), or -1 on error or EOF. */
445 _IO_ssize_t __getdelim
__P ((char **__lineptr
, size_t *__n
,
446 int __delimiter
, FILE *__stream
));
447 _IO_ssize_t getdelim
__P ((char **__lineptr
, size_t *__n
,
448 int __delimiter
, FILE *__stream
));
450 /* Like `getdelim', but reads up to a newline. */
451 _IO_ssize_t __getline
__P ((char **__lineptr
, size_t *__n
, FILE *__stream
));
452 _IO_ssize_t getline
__P ((char **__lineptr
, size_t *__n
, FILE *__stream
));
455 __STDIO_INLINE _IO_ssize_t
456 getline (char **__lineptr
, size_t *__n
, FILE *__stream
)
458 return __getdelim (__lineptr
, __n
, '\n', __stream
);
460 #endif /* Optimizing. */
464 /* Write a string to STREAM. */
465 extern int fputs
__P ((__const
char *__restrict __s
,
466 FILE *__restrict __stream
));
467 /* Write a string, followed by a newline, to stdout. */
468 extern int puts
__P ((__const
char *__s
));
471 /* Push a character back onto the input buffer of STREAM. */
472 extern int ungetc
__P ((int __c
, FILE *__stream
));
475 /* Read chunks of generic data from STREAM. */
476 extern size_t fread
__P ((void *__restrict __ptr
, size_t __size
,
477 size_t __n
, FILE *__restrict __stream
));
478 /* Write chunks of generic data to STREAM. */
479 extern size_t fwrite
__P ((__const
void *__restrict __ptr
, size_t __size
,
480 size_t __n
, FILE *__restrict __s
));
483 /* Faster versions when locking is not necessary. */
484 extern size_t fread_unlocked
__P ((void *__restrict __ptr
, size_t __size
,
485 size_t __n
, FILE *__restrict __stream
));
486 extern size_t fwrite_unlocked
__P ((__const
void *__restrict __ptr
,
487 size_t __size
, size_t __n
,
488 FILE *__restrict __stream
));
492 /* Seek to a certain position on STREAM. */
493 extern int fseek
__P ((FILE *__stream
, long int __off
, int __whence
));
494 /* Return the current position of STREAM. */
495 extern long int ftell
__P ((FILE *__stream
));
496 /* Rewind to the beginning of STREAM. */
497 extern void rewind
__P ((FILE *__stream
));
500 /* The Single Unix Specification, Version 2, specifies an alternative,
501 more adequate interface for the two functions above which deal with
502 file offset. `long int' is not the right type. */
504 /* Seek to a certain position on STREAM. */
505 extern int fseeko
__P ((FILE *__stream
, __off_t __off
, int __whence
));
506 /* Return the current position of STREAM. */
507 extern __off_t ftello
__P ((FILE *__stream
));
510 /* Get STREAM's position. */
511 extern int fgetpos
__P ((FILE *__restrict __stream
,
512 fpos_t *__restrict __pos
));
513 /* Set STREAM's position. */
514 extern int fsetpos
__P ((FILE *__stream
, __const
fpos_t *__pos
));
517 /* Clear the error and EOF indicators for STREAM. */
518 extern void clearerr
__P ((FILE *__stream
));
519 /* Return the EOF indicator for STREAM. */
520 extern int feof
__P ((FILE *__stream
));
521 /* Return the error indicator for STREAM. */
522 extern int ferror
__P ((FILE *__stream
));
525 /* Faster versions when locking is not required. */
526 extern void clearerr_unlocked
__P ((FILE *__stream
));
527 extern int feof_unlocked
__P ((FILE *__stream
));
528 extern int ferror_unlocked
__P ((FILE *__stream
));
532 feof_unlocked (FILE *__stream
)
534 return _IO_feof_unlocked (__stream
);
538 ferror_unlocked (FILE *__stream
)
540 return _IO_ferror_unlocked (__stream
);
542 #endif /* Optimizing. */
546 /* Print a message describing the meaning of the value of errno. */
547 extern void perror
__P ((__const
char *__s
));
549 /* These variables normally should not be used directly. The `strftime'
550 function provides all the needed functionality. */
553 extern __const
char *__const sys_errlist
[];
556 extern int _sys_nerr
;
557 extern __const
char *__const _sys_errlist
[];
562 /* Return the system file descriptor for STREAM. */
563 extern int fileno
__P ((FILE *__stream
));
564 #endif /* Use POSIX. */
567 /* Faster version when locking is not required. */
568 extern int fileno_unlocked
__P ((FILE *__stream
));
572 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
574 /* Create a new stream connected to a pipe running the given command. */
575 extern FILE *popen
__P ((__const
char *__command
, __const
char *__modes
));
577 /* Close a stream opened by popen and return the status of its child. */
578 extern int pclose
__P ((FILE *__stream
));
583 /* Return the name of the controlling terminal. */
584 extern char *ctermid
__P ((char *__s
));
585 #endif /* Use POSIX. */
589 /* Return the name of the current user. */
590 extern char *cuserid
__P ((char *__s
));
591 #endif /* Use X/Open. */
595 struct obstack
; /* See <obstack.h>. */
597 /* Write formatted output to an obstack. */
598 extern int obstack_printf
__P ((struct obstack
*__obstack
,
599 __const
char *__format
, ...));
600 extern int obstack_vprintf
__P ((struct obstack
*__obstack
,
601 __const
char *__format
,
603 #endif /* Use GNU. */
606 #if defined __USE_POSIX || defined __USE_MISC
607 /* These are defined in POSIX.1:1996. */
609 /* Acquire ownership of STREAM. */
610 extern void flockfile
__P ((FILE *__stream
));
612 /* Try to acquire ownership of STREAM but do not block if it is not
614 extern int ftrylockfile
__P ((FILE *__stream
));
616 /* Relinquish the ownership granted for STREAM. */
617 extern void funlockfile
__P ((FILE *__stream
));
618 #endif /* POSIX || misc */
622 /* Define helper macro. */
623 #undef __STDIO_INLINE
625 #endif /* <stdio.h> included. */
627 #endif /* !_STDIO_H */