Update.
[glibc.git] / libio / stdio.h
blob6056652bf95ad17b457c3f257eff6114a01c87de
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>
23 #ifndef _STDIO_H
25 #ifndef __need_FILE
26 # define _STDIO_H 1
27 # include <features.h>
29 __BEGIN_DECLS
31 # define __need_size_t
32 # define __need_NULL
33 # include <stddef.h>
35 # ifndef __USE_XOPEN
36 # define __need___va_list
37 # endif
38 # include <stdarg.h>
40 # include <bits/types.h>
41 #endif /* Don't need FILE. */
42 #undef __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. */
54 #ifdef _STDIO_H
55 #define _STDIO_USES_IOSTREAM
57 #include <libio.h>
59 /* The type of the second argument to `fgetpos' and `fsetpos'. */
60 #ifndef __USE_FILE_OFFSET64
61 typedef _G_fpos_t fpos_t;
62 #else
63 typedef _G_fpos64_t fpos_t;
64 #endif
65 #ifdef __USE_LARGEFILE64
66 typedef _G_fpos64_t fpos64_t;
67 #endif
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. */
76 #ifndef BUFSIZ
77 # define BUFSIZ _IO_BUFSIZ
78 #endif
81 /* End of file character.
82 Some things throughout the library rely on this being -1. */
83 #ifndef EOF
84 # define EOF (-1)
85 #endif
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"
98 #endif
101 /* Get the values:
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. */
119 /* Remove file FILENAME. */
120 extern int remove __P ((__const char *__filename));
121 /* Rename file OLD to NEW. */
122 extern int rename __P ((__const char *__old, __const char *__new));
125 /* Create a temporary file and open it read/write. */
126 #ifndef __USE_FILE_OFFSET64
127 extern FILE *tmpfile __P ((void));
128 #else
129 # ifdef __REDIRECT
130 extern FILE *__REDIRECT (tmpfile, __P ((void)), tmpfile64);
131 # else
132 # define tmpfile tmpfile64
133 # endif
134 #endif
135 #ifdef __USE_LARGEFILE64
136 extern FILE *tmpfile64 __P ((void));
137 #endif
138 /* Generate a temporary filename. */
139 extern char *tmpnam __P ((char *__s));
141 #ifdef __USE_MISC
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));
145 #endif
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));
157 #endif
160 /* Close STREAM. */
161 extern int fclose __P ((FILE *__stream));
162 /* Flush STREAM, or all streams if STREAM is NULL. */
163 extern int fflush __P ((FILE *__stream));
165 #ifdef __USE_MISC
166 /* Faster versions when locking is not required. */
167 extern int fflush_unlocked __P ((FILE *__stream));
168 #endif
170 #ifdef __USE_GNU
171 /* Close all streams. */
172 extern int fcloseall __P ((void));
173 #endif
176 #ifndef __USE_FILE_OFFSET64
177 /* Open a file and create a new stream for it. */
178 extern FILE *fopen __P ((__const char *__restrict __filename,
179 __const char *__restrict __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));
184 #else
185 # ifdef __REDIRECT
186 extern FILE *__REDIRECT (fopen, __P ((__const char *__restrict __filename,
187 __const char *__restrict __modes)),
188 fopen64);
189 extern FILE *__REDIRECT (freopen, __P ((__const char *__restrict __filename,
190 __const char *__restrict __modes,
191 FILE *__restrict __stream)),
192 freopen64);
193 # else
194 # define fopen fopen64
195 # define freopen freopen64
196 # endif
197 #endif
198 #ifdef __USE_LARGEFILE64
199 extern FILE *fopen64 __P ((__const char *__restrict __filename,
200 __const char *__restrict __modes));
201 extern FILE *freopen64 __P ((__const char *__restrict __filename,
202 __const char *__restrict __modes,
203 FILE *__restrict __stream));
204 #endif
206 #ifdef __USE_POSIX
207 /* Create a new stream that refers to an existing system file descriptor. */
208 extern FILE *fdopen __P ((int __fd, __const char *__modes));
209 #endif
211 #ifdef __USE_GNU
212 /* Create a new stream that refers to the given magic cookie,
213 and uses the given functions for input and output. */
214 extern FILE *fopencookie __P ((void *__restrict __magic_cookie,
215 __const char *__restrict __modes,
216 _IO_cookie_io_functions_t __io_funcs));
218 /* Open a stream that writes into a malloc'd buffer that is expanded as
219 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
220 and the number of characters written on fflush or fclose. */
221 extern FILE *open_memstream __P ((char **__restrict __bufloc,
222 size_t *__restrict __sizeloc));
223 #endif
226 /* If BUF is NULL, make STREAM unbuffered.
227 Else make it use buffer BUF, of size BUFSIZ. */
228 extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
229 /* Make STREAM use buffering mode MODE.
230 If BUF is not NULL, use N bytes of it for buffering;
231 else allocate an internal buffer N bytes long. */
232 extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
233 int __modes, size_t __n));
235 #ifdef __USE_BSD
236 /* If BUF is NULL, make STREAM unbuffered.
237 Else make it use SIZE bytes of BUF for buffering. */
238 extern void setbuffer __P ((FILE *__restrict __stream, char *__restrict __buf,
239 size_t __size));
241 /* Make STREAM line-buffered. */
242 extern void setlinebuf __P ((FILE *__stream));
243 #endif
246 /* Write formatted output to STREAM. */
247 extern int fprintf __P ((FILE *__restrict __stream,
248 __const char *__restrict __format, ...));
249 /* Write formatted output to stdout. */
250 extern int printf __P ((__const char *__restrict __format, ...));
251 /* Write formatted output to S. */
252 extern int sprintf __P ((char *__restrict __s,
253 __const char *__restrict __format, ...));
255 /* Write formatted output to S from argument list ARG. */
256 extern int vfprintf __P ((FILE *__restrict __s,
257 __const char *__restrict __format,
258 _G_va_list __arg));
259 /* Write formatted output to stdout from argument list ARG. */
260 extern int vprintf __P ((__const char *__restrict __format,
261 _G_va_list __arg));
262 /* Write formatted output to S from argument list ARG. */
263 extern int vsprintf __P ((char *__restrict __s,
264 __const char *__restrict __format,
265 _G_va_list __arg));
267 #if defined __USE_BSD || defined __USE_ISOC9X || defined __USE_UNIX98
268 /* Maximum chars of output to write in MAXLEN. */
269 extern int snprintf __P ((char *__restrict __s, size_t __maxlen,
270 __const char *__restrict __format, ...))
271 __attribute__ ((__format__ (__printf__, 3, 4)));
273 extern int __vsnprintf __P ((char *__restrict __s, size_t __maxlen,
274 __const char *__restrict __format,
275 _G_va_list __arg))
276 __attribute__ ((__format__ (__printf__, 3, 0)));
277 extern int vsnprintf __P ((char *__restrict __s, size_t __maxlen,
278 __const char *__restrict __format,
279 _G_va_list __arg))
280 __attribute__ ((__format__ (__printf__, 3, 0)));
281 #endif
283 #ifdef __USE_GNU
284 /* Write formatted output to a string dynamically allocated with `malloc'.
285 Store the address of the string in *PTR. */
286 extern int vasprintf __P ((char **__restrict __ptr,
287 __const char *__restrict __f, _G_va_list __arg))
288 __attribute__ ((__format__ (__printf__, 2, 0)));
289 extern int __asprintf __P ((char **__restrict __ptr,
290 __const char *__restrict __fmt, ...))
291 __attribute__ ((__format__ (__printf__, 2, 3)));
292 extern int asprintf __P ((char **__restrict __ptr,
293 __const char *__restrict __fmt, ...))
294 __attribute__ ((__format__ (__printf__, 2, 3)));
296 /* Write formatted output to a file descriptor. */
297 extern int vdprintf __P ((int __fd, __const char *__restrict __fmt,
298 _G_va_list __arg))
299 __attribute__ ((__format__ (__printf__, 2, 0)));
300 extern int dprintf __P ((int __fd, __const char *__restrict __fmt, ...))
301 __attribute__ ((__format__ (__printf__, 2, 3)));
302 #endif
305 /* Read formatted input from STREAM. */
306 extern int fscanf __P ((FILE *__restrict __stream,
307 __const char *__restrict __format, ...));
308 /* Read formatted input from stdin. */
309 extern int scanf __P ((__const char *__restrict __format, ...));
310 /* Read formatted input from S. */
311 extern int sscanf __P ((__const char *__restrict __s,
312 __const char *__restrict __format, ...));
314 #ifdef __USE_ISOC9X
315 /* Read formatted input from S into argument list ARG. */
316 extern int vfscanf __P ((FILE *__restrict __s,
317 __const char *__restrict __format,
318 _G_va_list __arg))
319 __attribute__ ((__format__ (__scanf__, 2, 0)));
321 /* Read formatted input from stdin into argument list ARG. */
322 extern int vscanf __P ((__const char *__restrict __format, _G_va_list __arg))
323 __attribute__ ((__format__ (__scanf__, 1, 0)));
325 /* Read formatted input from S into argument list ARG. */
326 extern int vsscanf __P ((__const char *__restrict __s,
327 __const char *__restrict __format,
328 _G_va_list __arg))
329 __attribute__ ((__format__ (__scanf__, 2, 0)));
330 #endif /* Use ISO C9x. */
333 /* Read a character from STREAM. */
334 extern int fgetc __P ((FILE *__stream));
335 extern int getc __P ((FILE *__stream));
337 /* Read a character from stdin. */
338 extern int getchar __P ((void));
340 /* The C standard explicitly says this is a macro, so we always do the
341 optimization for it. */
342 #define getc(_fp) _IO_getc (_fp)
344 #if defined __USE_POSIX || defined __USE_MISC
345 /* These are defined in POSIX.1:1996. */
346 extern int getc_unlocked __P ((FILE *__stream));
347 extern int getchar_unlocked __P ((void));
348 #endif /* Use POSIX or MISC. */
350 #ifdef __USE_MISC
351 /* Faster version when locking is not necessary. */
352 extern int fgetc_unlocked __P ((FILE *__stream));
353 #endif /* Use MISC. */
356 /* Write a character to STREAM. */
357 extern int fputc __P ((int __c, FILE *__stream));
358 extern int putc __P ((int __c, FILE *__stream));
360 /* Write a character to stdout. */
361 extern int putchar __P ((int __c));
363 /* The C standard explicitly says this can be a macro,
364 so we always do the optimization for it. */
365 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
367 #ifdef __USE_MISC
368 /* Faster version when locking is not necessary. */
369 extern int fputc_unlocked __P ((int __c, FILE *__stream));
370 #endif /* Use MISC. */
372 #if defined __USE_POSIX || defined __USE_MISC
373 /* These are defined in POSIX.1:1996. */
374 extern int putc_unlocked __P ((int __c, FILE *__stream));
375 extern int putchar_unlocked __P ((int __c));
376 #endif /* Use POSIX or MISC. */
379 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
380 /* Get a word (int) from STREAM. */
381 extern int getw __P ((FILE *__stream));
383 /* Write a word (int) to STREAM. */
384 extern int putw __P ((int __w, FILE *__stream));
385 #endif
388 /* Get a newline-terminated string of finite length from STREAM. */
389 extern char *fgets __P ((char *__restrict __s, int __n,
390 FILE *__restrict __stream));
392 #ifdef __USE_GNU
393 /* This function does the same as `fgets' but does not lock the stream. */
394 extern char *fgets_unlocked __P ((char *__restrict __s, int __n,
395 FILE *__restrict __stream));
396 #endif
398 /* Get a newline-terminated string from stdin, removing the newline.
399 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
400 extern char *gets __P ((char *__s));
403 #ifdef __USE_GNU
404 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
405 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
406 NULL), pointing to *N characters of space. It is realloc'd as
407 necessary. Returns the number of characters read (not including the
408 null terminator), or -1 on error or EOF. */
409 extern _IO_ssize_t __getdelim __P ((char **__restrict __lineptr,
410 size_t *__restrict __n, int __delimiter,
411 FILE *__restrict __stream));
412 extern _IO_ssize_t getdelim __P ((char **__restrict __lineptr,
413 size_t *__restrict __n, int __delimiter,
414 FILE *__restrict __stream));
416 /* Like `getdelim', but reads up to a newline. */
417 extern _IO_ssize_t getline __P ((char **__restrict __lineptr,
418 size_t *__restrict __n,
419 FILE *__restrict __stream));
420 #endif
423 /* Write a string to STREAM. */
424 extern int fputs __P ((__const char *__restrict __s,
425 FILE *__restrict __stream));
427 #ifdef __USE_GNU
428 /* This function does the same as `fputs' but does not lock the stream. */
429 extern int fputs_unlocked __P ((__const char *__restrict __s,
430 FILE *__restrict __stream));
431 #endif
433 /* Write a string, followed by a newline, to stdout. */
434 extern int puts __P ((__const char *__s));
437 /* Push a character back onto the input buffer of STREAM. */
438 extern int ungetc __P ((int __c, FILE *__stream));
441 /* Read chunks of generic data from STREAM. */
442 extern size_t fread __P ((void *__restrict __ptr, size_t __size,
443 size_t __n, FILE *__restrict __stream));
444 /* Write chunks of generic data to STREAM. */
445 extern size_t fwrite __P ((__const void *__restrict __ptr, size_t __size,
446 size_t __n, FILE *__restrict __s));
448 #ifdef __USE_MISC
449 /* Faster versions when locking is not necessary. */
450 extern size_t fread_unlocked __P ((void *__restrict __ptr, size_t __size,
451 size_t __n, FILE *__restrict __stream));
452 extern size_t fwrite_unlocked __P ((__const void *__restrict __ptr,
453 size_t __size, size_t __n,
454 FILE *__restrict __stream));
455 #endif
458 /* Seek to a certain position on STREAM. */
459 extern int fseek __P ((FILE *__stream, long int __off, int __whence));
460 /* Return the current position of STREAM. */
461 extern long int ftell __P ((FILE *__stream));
462 /* Rewind to the beginning of STREAM. */
463 extern void rewind __P ((FILE *__stream));
465 /* The Single Unix Specification, Version 2, specifies an alternative,
466 more adequate interface for the two functions above which deal with
467 file offset. `long int' is not the right type. These definitions
468 are originally defined in the Large File Support API. */
470 /* Types needed in these functions. */
471 #ifndef off_t
472 # ifndef __USE_FILE_OFFSET64
473 typedef __off_t off_t;
474 # else
475 typedef __off64_t off_t;
476 # endif
477 # define off_t off_t
478 #endif
480 #if defined __USE_LARGEFILE64 && !defined off64_t
481 typedef __off64_t off64_t;
482 # define off64_t off64_t
483 #endif
486 #ifndef __USE_FILE_OFFSET64
487 # ifdef __USE_UNIX98
488 /* Seek to a certain position on STREAM. */
489 extern int fseeko __P ((FILE *__stream, __off_t __off, int __whence));
490 /* Return the current position of STREAM. */
491 extern __off_t ftello __P ((FILE *__stream));
492 # endif
494 /* Get STREAM's position. */
495 extern int fgetpos __P ((FILE *__restrict __stream,
496 fpos_t *__restrict __pos));
497 /* Set STREAM's position. */
498 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
499 #else
500 # ifdef __REDIRECT
501 # ifdef __USE_UNIX98
502 extern int __REDIRECT (fseeko,
503 __P ((FILE *__stream, __off64_t __off, int __whence)),
504 fseeko64);
505 extern __off64_t __REDIRECT (ftello, __P ((FILE *__stream)), ftello64);
506 # endif
507 extern int __REDIRECT (fgetpos, __P ((FILE *__restrict __stream,
508 fpos_t *__restrict __pos)), fgetpos64);
509 extern int __REDIRECT (fsetpos, __P ((FILE *__stream, __const fpos_t *__pos)),
510 fsetpos64);
511 # else
512 # ifdef __USE_UNIX98
513 # define fseeko fseeko64
514 # define ftello ftello64
515 # endif
516 # define fgetpos fgetpos64
517 # define fsetpos fsetpos64
518 # endif
519 #endif
521 #ifdef __USE_LARGEFILE64
522 # ifdef __USE_UNIX98
523 extern int fseeko64 __P ((FILE *__stream, __off64_t __off, int __whence));
524 extern __off64_t ftello64 __P ((FILE *__stream));
525 # endif
526 extern int fgetpos64 __P ((FILE *__restrict __stream,
527 fpos64_t *__restrict __pos));
528 extern int fsetpos64 __P ((FILE *__stream, __const fpos64_t *__pos));
529 #endif
531 /* Clear the error and EOF indicators for STREAM. */
532 extern void clearerr __P ((FILE *__stream));
533 /* Return the EOF indicator for STREAM. */
534 extern int feof __P ((FILE *__stream));
535 /* Return the error indicator for STREAM. */
536 extern int ferror __P ((FILE *__stream));
538 #ifdef __USE_MISC
539 /* Faster versions when locking is not required. */
540 extern void clearerr_unlocked __P ((FILE *__stream));
541 extern int feof_unlocked __P ((FILE *__stream));
542 extern int ferror_unlocked __P ((FILE *__stream));
543 #endif
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 `strerror'
550 function provides all the needed functionality. */
551 #ifdef __USE_BSD
552 extern int sys_nerr;
553 extern __const char *__const sys_errlist[];
554 #endif
555 #ifdef __USE_GNU
556 extern int _sys_nerr;
557 extern __const char *__const _sys_errlist[];
558 #endif
561 #ifdef __USE_POSIX
562 /* Return the system file descriptor for STREAM. */
563 extern int fileno __P ((FILE *__stream));
564 #endif /* Use POSIX. */
566 #ifdef __USE_MISC
567 /* Faster version when locking is not required. */
568 extern int fileno_unlocked __P ((FILE *__stream));
569 #endif
572 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
573 defined __USE_MISC)
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));
579 #endif
582 #ifdef __USE_POSIX
583 /* Return the name of the controlling terminal. */
584 extern char *ctermid __P ((char *__s));
585 #endif /* Use POSIX. */
588 #ifdef __USE_XOPEN
589 /* Return the name of the current user. */
590 extern char *cuserid __P ((char *__s));
591 #endif /* Use X/Open. */
594 #ifdef __USE_GNU
595 struct obstack; /* See <obstack.h>. */
597 /* Write formatted output to an obstack. */
598 extern int obstack_printf __P ((struct obstack *__restrict __obstack,
599 __const char *__restrict __format, ...));
600 extern int obstack_vprintf __P ((struct obstack *__restrict __obstack,
601 __const char *__restrict __format,
602 _G_va_list __args));
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
613 possible. */
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 */
620 #if defined __USE_XOPEN && !defined __USE_GNU
621 /* The X/Open standard requires some functions and variables to be
622 declared here which do not belong into this header. But we have to
623 follow. In GNU mode we don't do this nonsense. */
624 # define __need_getopt
625 # include <getopt.h>
626 #endif
628 /* If we are compiling with optimizing read this file. It contains
629 several optizing inline functions and macros. */
630 #ifdef __USE_EXTERN_INLINES
631 # include <bits/stdio.h>
632 #endif
634 __END_DECLS
636 #endif /* <stdio.h> included. */
638 #endif /* !_STDIO_H */