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
54 /* The type of the second argument to `fgetpos' and `fsetpos'. */
55 typedef _G_fpos_t
fpos_t;
58 /* Generate a unique file name (and possibly open it with mode "w+b"). */
59 extern char *__stdio_gen_tempname
__P ((char *__buf
, size_t __bufsize
,
67 /* Print out MESSAGE on the error output and abort. */
68 extern void __libc_fatal
__P ((__const
char *__message
))
69 __attribute__ ((__noreturn__
));
72 /* The possibilities for the third argument to `setvbuf'. */
73 #define _IOFBF 0 /* Fully buffered. */
74 #define _IOLBF 1 /* Line buffered. */
75 #define _IONBF 2 /* No buffering. */
78 /* Default buffer size. */
80 #define BUFSIZ _IO_BUFSIZ
84 /* End of file character.
85 Some things throughout the library rely on this being -1. */
91 /* The possibilities for the third argument to `fseek'.
92 These values should not be changed. */
93 #define SEEK_SET 0 /* Seek from beginning of file. */
94 #define SEEK_CUR 1 /* Seek from current position. */
95 #define SEEK_END 2 /* Seek from end of file. */
99 /* Default path prefix for `tempnam' and `tmpnam'. */
100 #define P_tmpdir "/tmp"
105 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
106 TMP_MAX The minimum number of unique filenames generated by tmpnam
107 (and tempnam when it uses tmpnam's name space),
108 or tempnam (the two are separate).
109 L_ctermid How long an array to pass to `ctermid'.
110 L_cuserid How long an array to pass to `cuserid'.
111 FOPEN_MAX Minimum number of files that can be open at once.
112 FILENAME_MAX Maximum length of a filename. */
113 #include <bits/stdio_lim.h>
116 /* Standard streams. */
117 extern FILE *stdin
, *stdout
, *stderr
;
118 /* Refer to the real names by default. */
119 #define stdin _IO_stdin
120 #define stdout _IO_stdout
121 #define stderr _IO_stderr
124 /* Remove file FILENAME. */
125 extern int remove
__P ((__const
char *__filename
));
126 /* Rename file OLD to NEW. */
127 extern int rename
__P ((__const
char *__old
, __const
char *__new
));
130 /* Create a temporary file and open it read/write. */
131 extern FILE *tmpfile
__P ((void));
132 /* Generate a temporary filename. */
133 extern char *tmpnam
__P ((char *__s
));
136 /* This is the reentrant variant of `tmpnam'. The only difference is
137 that it does not allow S to be NULL. */
138 extern char *tmpnam_r
__P ((char *__s
));
142 #if defined __USE_SVID || defined __USE_XOPEN
143 /* Generate a unique temporary filename using up to five characters of PFX
144 if it is not NULL. The directory to put this file in is searched for
145 as follows: First the environment variable "TMPDIR" is checked.
146 If it contains the name of a writable directory, that directory is used.
147 If not and if DIR is not NULL, that value is checked. If that fails,
148 P_tmpdir is tried and finally "/tmp". The storage for the filename
149 is allocated by `malloc'. */
150 extern char *tempnam
__P ((__const
char *__dir
, __const
char *__pfx
));
155 extern int fclose
__P ((FILE *__stream
));
156 /* Flush STREAM, or all streams if STREAM is NULL. */
157 extern int fflush
__P ((FILE *__stream
));
160 /* Faster versions when locking is not required. */
161 extern int fclose_unlocked
__P ((FILE *__stream
));
162 extern int fflush_unlocked
__P ((FILE *__stream
));
166 /* Close all streams. */
167 extern int __fcloseall
__P ((void));
168 extern int fcloseall
__P ((void));
172 /* Open a file and create a new stream for it. */
173 extern FILE *fopen
__P ((__const
char *__filename
, __const
char *__modes
));
174 /* Open a file, replacing an existing stream with it. */
175 extern FILE *freopen
__P ((__const
char *__restrict __filename
,
176 __const
char *__restrict __modes
,
177 FILE *__restrict __stream
));
180 /* Create a new stream that refers to an existing system file descriptor. */
181 extern FILE *fdopen
__P ((int __fd
, __const
char *__modes
));
185 /* Create a new stream that refers to the given magic cookie,
186 and uses the given functions for input and output. */
187 extern FILE *fopencookie
__P ((void *__magic_cookie
, __const
char *__modes
,
188 _IO_cookie_io_functions_t __io_funcs
));
190 /* Open a stream that writes into a malloc'd buffer that is expanded as
191 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
192 and the number of characters written on fflush or fclose. */
193 extern FILE *open_memstream
__P ((char **__bufloc
, size_t *__sizeloc
));
197 /* If BUF is NULL, make STREAM unbuffered.
198 Else make it use buffer BUF, of size BUFSIZ. */
199 extern void setbuf
__P ((FILE *__restrict __stream
, char *__restrict __buf
));
200 /* Make STREAM use buffering mode MODE.
201 If BUF is not NULL, use N bytes of it for buffering;
202 else allocate an internal buffer N bytes long. */
203 extern int setvbuf
__P ((FILE *__restrict __stream
, char *__restrict __buf
,
204 int __modes
, size_t __n
));
207 /* If BUF is NULL, make STREAM unbuffered.
208 Else make it use SIZE bytes of BUF for buffering. */
209 extern void setbuffer
__P ((FILE *__stream
, char *__buf
, size_t __size
));
211 /* Make STREAM line-buffered. */
212 extern void setlinebuf
__P ((FILE *__stream
));
216 /* Write formatted output to STREAM. */
217 extern int fprintf
__P ((FILE *__restrict __stream
,
218 __const
char *__restrict __format
, ...));
219 /* Write formatted output to stdout. */
220 extern int printf
__P ((__const
char *__restrict __format
, ...));
221 /* Write formatted output to S. */
222 extern int sprintf
__P ((char *__restrict __s
,
223 __const
char *__restrict __format
, ...));
225 /* Write formatted output to S from argument list ARG. */
226 extern int vfprintf
__P ((FILE *__restrict __s
,
227 __const
char *__restrict __format
,
229 /* Write formatted output to stdout from argument list ARG. */
230 extern int vprintf
__P ((__const
char *__restrict __format
,
232 /* Write formatted output to S from argument list ARG. */
233 extern int vsprintf
__P ((char *__restrict __s
,
234 __const
char *__restrict __format
,
239 vprintf (const char *__restrict __fmt
, _G_va_list __arg
)
241 return vfprintf (stdout
, __fmt
, __arg
);
243 #endif /* Optimizing. */
246 /* Maximum chars of output to write in MAXLEN. */
247 extern int __snprintf
__P ((char *__s
, size_t __maxlen
,
248 __const
char *__format
, ...));
249 extern int snprintf
__P ((char *__s
, size_t __maxlen
,
250 __const
char *__format
, ...));
252 extern int __vsnprintf
__P ((char *__s
, size_t __maxlen
,
253 __const
char *__format
, _G_va_list __arg
));
254 extern int vsnprintf
__P ((char *__s
, size_t __maxlen
,
255 __const
char *__format
, _G_va_list __arg
));
257 /* Write formatted output to a string dynamically allocated with `malloc'.
258 Store the address of the string in *PTR. */
259 extern int vasprintf
__P ((char **__ptr
, __const
char *__f
,
261 extern int asprintf
__P ((char **__ptr
, __const
char *__fmt
, ...));
263 /* Write formatted output to a file descriptor. */
264 extern int vdprintf
__P ((int __fd
, __const
char *__fmt
, _G_va_list __arg
));
265 extern int dprintf
__P ((int __fd
, __const
char *__fmt
, ...));
269 /* Read formatted input from STREAM. */
270 extern int fscanf
__P ((FILE *__restrict __stream
,
271 __const
char *__restrict __format
, ...));
272 /* Read formatted input from stdin. */
273 extern int scanf
__P ((__const
char *__restrict __format
, ...));
274 /* Read formatted input from S. */
275 extern int sscanf
__P ((__const
char *__restrict __s
,
276 __const
char *__restrict __format
, ...));
279 /* Read formatted input from S into argument list ARG. */
280 extern int __vfscanf
__P ((FILE *__s
, __const
char *__format
,
282 extern int vfscanf
__P ((FILE *__s
, __const
char *__format
,
285 /* Read formatted input from stdin into argument list ARG. */
286 extern int __vscanf
__P ((__const
char *__format
, _G_va_list __arg
));
287 extern int vscanf
__P ((__const
char *__format
, _G_va_list __arg
));
289 /* Read formatted input from S into argument list ARG. */
290 extern int __vsscanf
__P ((__const
char *__s
, __const
char *__format
,
292 extern int vsscanf
__P ((__const
char *__s
, __const
char *__format
,
294 #endif /* Use GNU. */
297 /* Read a character from STREAM. */
298 extern int fgetc
__P ((FILE *__stream
));
299 extern int getc
__P ((FILE *__stream
));
301 /* Read a character from stdin. */
302 extern int getchar
__P ((void));
304 /* The C standard explicitly says this is a macro, so we always do the
305 optimization for it. */
306 #define getc(_fp) _IO_getc (_fp)
312 return _IO_getc (stdin
);
314 #endif /* Optimizing. */
316 #if defined __USE_POSIX || defined __USE_MISC
317 /* These are defined in POSIX.1:1996. */
318 extern int getc_unlocked
__P ((FILE *__stream
));
319 extern int getchar_unlocked
__P ((void));
323 getc_unlocked (FILE *__fp
)
325 return _IO_getc_unlocked (__fp
);
329 getchar_unlocked (void)
331 return _IO_getc_unlocked (stdin
);
333 #endif /* Optimizing. */
334 #endif /* Use POSIX or MISC. */
337 /* Write a character to STREAM. */
338 extern int fputc
__P ((int __c
, FILE *__stream
));
339 extern int putc
__P ((int __c
, FILE *__stream
));
341 /* Write a character to stdout. */
342 extern int putchar
__P ((int __c
));
344 /* The C standard explicitly says this can be a macro,
345 so we always do the optimization for it. */
346 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
352 return _IO_putc (__c
, stdout
);
357 /* Faster version when locking is not necessary. */
358 extern int fputc_unlocked
__P ((int __c
, FILE *__stream
));
362 fputc_unlocked (int __c
, FILE *__stream
)
364 return _IO_putc_unlocked (__c
, __stream
);
366 #endif /* Optimizing. */
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
__P ((int __c
, FILE *__stream
));
372 extern int putchar_unlocked
__P ((int __c
));
376 putc_unlocked (int __c
, FILE *__stream
)
378 return _IO_putc_unlocked (__c
, __stream
);
382 putchar_unlocked (int __c
)
384 return _IO_putc_unlocked (__c
, stdout
);
386 #endif /* Optimizing. */
387 #endif /* Use POSIX or MISc. */
390 #if defined __USE_SVID || defined __USE_MISC
391 /* Get a word (int) from STREAM. */
392 extern int getw
__P ((FILE *__stream
));
394 /* Write a word (int) to STREAM. */
395 extern int putw
__P ((int __w
, FILE *__stream
));
399 /* Get a newline-terminated string of finite length from STREAM. */
400 extern char *fgets
__P ((char *__restrict __s
, int __n
,
401 FILE *__restrict __stream
));
403 /* Get a newline-terminated string from stdin, removing the newline.
404 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
405 extern char *gets
__P ((char *__s
));
409 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
410 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
411 NULL), pointing to *N characters of space. It is realloc'd as
412 necessary. Returns the number of characters read (not including the
413 null terminator), or -1 on error or EOF. */
414 _IO_ssize_t __getdelim
__P ((char **__lineptr
, size_t *__n
,
415 int __delimiter
, FILE *__stream
));
416 _IO_ssize_t getdelim
__P ((char **__lineptr
, size_t *__n
,
417 int __delimiter
, FILE *__stream
));
419 /* Like `getdelim', but reads up to a newline. */
420 _IO_ssize_t __getline
__P ((char **__lineptr
, size_t *__n
, FILE *__stream
));
421 _IO_ssize_t getline
__P ((char **__lineptr
, size_t *__n
, FILE *__stream
));
424 extern __inline _IO_ssize_t
425 getline (char **__lineptr
, size_t *__n
, FILE *__stream
)
427 return __getdelim (__lineptr
, __n
, '\n', __stream
);
429 #endif /* Optimizing. */
433 /* Write a string to STREAM. */
434 extern int fputs
__P ((__const
char *__restrict __s
,
435 FILE *__restrict __stream
));
436 /* Write a string, followed by a newline, to stdout. */
437 extern int puts
__P ((__const
char *__s
));
440 /* Push a character back onto the input buffer of STREAM. */
441 extern int ungetc
__P ((int __c
, FILE *__stream
));
444 /* Read chunks of generic data from STREAM. */
445 extern size_t fread
__P ((void *__restrict __ptr
, size_t __size
,
446 size_t __n
, FILE *__restrict __stream
));
447 /* Write chunks of generic data to STREAM. */
448 extern size_t fwrite
__P ((__const
void *__restrict __ptr
, size_t __size
,
449 size_t __n
, FILE *__restrict __s
));
452 /* Faster versions when locking is not necessary. */
453 extern size_t fread_unlocked
__P ((void *__restrict __ptr
, size_t __size
,
454 size_t __n
, FILE *__restrict __stream
));
455 extern size_t fwrite_unlocked
__P ((__const
void *__restrict __ptr
,
456 size_t __size
, size_t __n
,
457 FILE *__restrict __stream
));
461 /* Seek to a certain position on STREAM. */
462 extern int fseek
__P ((FILE *__stream
, long int __off
, int __whence
));
463 /* Return the current position of STREAM. */
464 extern long int ftell
__P ((FILE *__stream
));
465 /* Rewind to the beginning of STREAM. */
466 extern void rewind
__P ((FILE *__stream
));
468 /* Get STREAM's position. */
469 extern int fgetpos
__P ((FILE *__restrict __stream
,
470 fpos_t *__restrict __pos
));
471 /* Set STREAM's position. */
472 extern int fsetpos
__P ((FILE *__stream
, __const
fpos_t *__pos
));
475 /* Clear the error and EOF indicators for STREAM. */
476 extern void clearerr
__P ((FILE *__stream
));
477 /* Return the EOF indicator for STREAM. */
478 extern int feof
__P ((FILE *__stream
));
479 /* Return the error indicator for STREAM. */
480 extern int ferror
__P ((FILE *__stream
));
483 /* Faster versions when locking is not required. */
484 extern void clearerr_unlocked
__P ((FILE *__stream
));
485 extern int feof_unlocked
__P ((FILE *__stream
));
486 extern int ferror_unlocked
__P ((FILE *__stream
));
490 feof_unlocked (FILE *__stream
)
492 return _IO_feof_unlocked (__stream
);
496 ferror_unlocked (FILE *__stream
)
498 return _IO_ferror_unlocked (__stream
);
500 #endif /* Optimizing. */
504 /* Print a message describing the meaning of the value of errno. */
505 extern void perror
__P ((__const
char *__s
));
507 /* These variables normally should not be used directly. The `strftime'
508 function provides all the needed functionality. */
511 extern __const
char *__const sys_errlist
[];
514 extern int _sys_nerr
;
515 extern __const
char *__const _sys_errlist
[];
520 /* Return the system file descriptor for STREAM. */
521 extern int fileno
__P ((FILE *__stream
));
522 #endif /* Use POSIX. */
525 /* Faster version when locking is not required. */
526 extern int fileno_unlocked
__P ((FILE *__stream
));
530 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
532 /* Create a new stream connected to a pipe running the given command. */
533 extern FILE *popen
__P ((__const
char *__command
, __const
char *__modes
));
535 /* Close a stream opened by popen and return the status of its child. */
536 extern int pclose
__P ((FILE *__stream
));
541 /* Return the name of the controlling terminal. */
542 extern char *ctermid
__P ((char *__s
));
543 #endif /* Use POSIX. */
547 /* Return the name of the current user. */
548 extern char *cuserid
__P ((char *__s
));
549 #endif /* Use X/Open. */
553 struct obstack
; /* See <obstack.h>. */
555 /* Write formatted output to an obstack. */
556 extern int obstack_printf
__P ((struct obstack
*__obstack
,
557 __const
char *__format
, ...));
558 extern int obstack_vprintf
__P ((struct obstack
*__obstack
,
559 __const
char *__format
,
561 #endif /* Use GNU. */
564 #if defined __USE_POSIX || defined __USE_MISC
565 /* These are defined in POSIX.1:1996. */
567 /* Acquire ownership of STREAM. */
568 extern void flockfile
__P ((FILE *__stream
));
570 /* Try to acquire ownership of STREAM but do not block if it is not
572 extern int ftrylockfile
__P ((FILE *__stream
));
574 /* Relinquish the ownership granted for STREAM. */
575 extern void funlockfile
__P ((FILE *__stream
));
576 #endif /* POSIX || misc */
580 #endif /* <stdio.h> included. */
582 #endif /* !_STDIO_H */