(_ISwbit): Protext use of parameter with parentheses.
[glibc.git] / libio / stdio.h
blobedbd82b3dc05f04824df3b586d8df7ef03ee28d5
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>
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. */
351 /* Write a character to STREAM. */
352 extern int fputc __P ((int __c, FILE *__stream));
353 extern int putc __P ((int __c, FILE *__stream));
355 /* Write a character to stdout. */
356 extern int putchar __P ((int __c));
358 /* The C standard explicitly says this can be a macro,
359 so we always do the optimization for it. */
360 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
362 #ifdef __USE_MISC
363 /* Faster version when locking is not necessary. */
364 extern int fputc_unlocked __P ((int __c, FILE *__stream));
365 #endif /* Use MISC. */
367 #if defined __USE_POSIX || defined __USE_MISC
368 /* These are defined in POSIX.1:1996. */
369 extern int putc_unlocked __P ((int __c, FILE *__stream));
370 extern int putchar_unlocked __P ((int __c));
371 #endif /* Use POSIX or MISC. */
374 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
375 /* Get a word (int) from STREAM. */
376 extern int getw __P ((FILE *__stream));
378 /* Write a word (int) to STREAM. */
379 extern int putw __P ((int __w, FILE *__stream));
380 #endif
383 /* Get a newline-terminated string of finite length from STREAM. */
384 extern char *fgets __P ((char *__restrict __s, int __n,
385 FILE *__restrict __stream));
387 #ifdef __USE_GNU
388 /* This function does the same as `fgets' but does not lock the stream. */
389 extern char *fgets_unlocked __P ((char *__restrict __s, int __n,
390 FILE *__restrict __stream));
391 #endif
393 /* Get a newline-terminated string from stdin, removing the newline.
394 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
395 extern char *gets __P ((char *__s));
398 #ifdef __USE_GNU
399 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
400 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
401 NULL), pointing to *N characters of space. It is realloc'd as
402 necessary. Returns the number of characters read (not including the
403 null terminator), or -1 on error or EOF. */
404 extern _IO_ssize_t __getdelim __P ((char **__restrict __lineptr,
405 size_t *__restrict __n, int __delimiter,
406 FILE *__restrict __stream));
407 extern _IO_ssize_t getdelim __P ((char **__restrict __lineptr,
408 size_t *__restrict __n, int __delimiter,
409 FILE *__restrict __stream));
411 /* Like `getdelim', but reads up to a newline. */
412 extern _IO_ssize_t getline __P ((char **__restrict __lineptr,
413 size_t *__restrict __n,
414 FILE *__restrict __stream));
415 #endif
418 /* Write a string to STREAM. */
419 extern int fputs __P ((__const char *__restrict __s,
420 FILE *__restrict __stream));
422 #ifdef __USE_GNU
423 /* This function does the same as `fputs' but does not lock the stream. */
424 extern int fputs_unlocked __P ((__const char *__restrict __s,
425 FILE *__restrict __stream));
426 #endif
428 /* Write a string, followed by a newline, to stdout. */
429 extern int puts __P ((__const char *__s));
432 /* Push a character back onto the input buffer of STREAM. */
433 extern int ungetc __P ((int __c, FILE *__stream));
436 /* Read chunks of generic data from STREAM. */
437 extern size_t fread __P ((void *__restrict __ptr, size_t __size,
438 size_t __n, FILE *__restrict __stream));
439 /* Write chunks of generic data to STREAM. */
440 extern size_t fwrite __P ((__const void *__restrict __ptr, size_t __size,
441 size_t __n, FILE *__restrict __s));
443 #ifdef __USE_MISC
444 /* Faster versions when locking is not necessary. */
445 extern size_t fread_unlocked __P ((void *__restrict __ptr, size_t __size,
446 size_t __n, FILE *__restrict __stream));
447 extern size_t fwrite_unlocked __P ((__const void *__restrict __ptr,
448 size_t __size, size_t __n,
449 FILE *__restrict __stream));
450 #endif
453 /* Seek to a certain position on STREAM. */
454 extern int fseek __P ((FILE *__stream, long int __off, int __whence));
455 /* Return the current position of STREAM. */
456 extern long int ftell __P ((FILE *__stream));
457 /* Rewind to the beginning of STREAM. */
458 extern void rewind __P ((FILE *__stream));
460 /* The Single Unix Specification, Version 2, specifies an alternative,
461 more adequate interface for the two functions above which deal with
462 file offset. `long int' is not the right type. These definitions
463 are originally defined in the Large File Support API. */
465 /* Types needed in these functions. */
466 #ifndef off_t
467 # ifndef __USE_FILE_OFFSET64
468 typedef __off_t off_t;
469 # else
470 typedef __off64_t off_t;
471 # endif
472 # define off_t off_t
473 #endif
475 #if defined __USE_LARGEFILE64 && !defined off64_t
476 typedef __off64_t off64_t;
477 # define off64_t off64_t
478 #endif
481 #ifndef __USE_FILE_OFFSET64
482 # ifdef __USE_UNIX98
483 /* Seek to a certain position on STREAM. */
484 extern int fseeko __P ((FILE *__stream, __off_t __off, int __whence));
485 /* Return the current position of STREAM. */
486 extern __off_t ftello __P ((FILE *__stream));
487 # endif
489 /* Get STREAM's position. */
490 extern int fgetpos __P ((FILE *__restrict __stream,
491 fpos_t *__restrict __pos));
492 /* Set STREAM's position. */
493 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
494 #else
495 # ifdef __REDIRECT
496 # ifdef __USE_UNIX98
497 extern int __REDIRECT (fseeko,
498 __P ((FILE *__stream, __off64_t __off, int __whence)),
499 fseeko64);
500 extern __off64_t __REDIRECT (ftello, __P ((FILE *__stream)), ftello64);
501 # endif
502 extern int __REDIRECT (fgetpos, __P ((FILE *__restrict __stream,
503 fpos_t *__restrict __pos)), fgetpos64);
504 extern int __REDIRECT (fsetpos, __P ((FILE *__stream, __const fpos_t *__pos)),
505 fsetpos64);
506 # else
507 # ifdef __USE_UNIX98
508 # define fseeko fseeko64
509 # define ftello ftello64
510 # endif
511 # define fgetpos fgetpos64
512 # define fsetpos fsetpos64
513 # endif
514 #endif
516 #ifdef __USE_LARGEFILE64
517 # ifdef __USE_UNIX98
518 extern int fseeko64 __P ((FILE *__stream, __off64_t __off, int __whence));
519 extern __off64_t ftello64 __P ((FILE *__stream));
520 # endif
521 extern int fgetpos64 __P ((FILE *__restrict __stream,
522 fpos64_t *__restrict __pos));
523 extern int fsetpos64 __P ((FILE *__stream, __const fpos64_t *__pos));
524 #endif
526 /* Clear the error and EOF indicators for STREAM. */
527 extern void clearerr __P ((FILE *__stream));
528 /* Return the EOF indicator for STREAM. */
529 extern int feof __P ((FILE *__stream));
530 /* Return the error indicator for STREAM. */
531 extern int ferror __P ((FILE *__stream));
533 #ifdef __USE_MISC
534 /* Faster versions when locking is not required. */
535 extern void clearerr_unlocked __P ((FILE *__stream));
536 extern int feof_unlocked __P ((FILE *__stream));
537 extern int ferror_unlocked __P ((FILE *__stream));
538 #endif
541 /* Print a message describing the meaning of the value of errno. */
542 extern void perror __P ((__const char *__s));
544 /* These variables normally should not be used directly. The `strerror'
545 function provides all the needed functionality. */
546 #ifdef __USE_BSD
547 extern int sys_nerr;
548 extern __const char *__const sys_errlist[];
549 #endif
550 #ifdef __USE_GNU
551 extern int _sys_nerr;
552 extern __const char *__const _sys_errlist[];
553 #endif
556 #ifdef __USE_POSIX
557 /* Return the system file descriptor for STREAM. */
558 extern int fileno __P ((FILE *__stream));
559 #endif /* Use POSIX. */
561 #ifdef __USE_MISC
562 /* Faster version when locking is not required. */
563 extern int fileno_unlocked __P ((FILE *__stream));
564 #endif
567 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
568 defined __USE_MISC)
569 /* Create a new stream connected to a pipe running the given command. */
570 extern FILE *popen __P ((__const char *__command, __const char *__modes));
572 /* Close a stream opened by popen and return the status of its child. */
573 extern int pclose __P ((FILE *__stream));
574 #endif
577 #ifdef __USE_POSIX
578 /* Return the name of the controlling terminal. */
579 extern char *ctermid __P ((char *__s));
580 #endif /* Use POSIX. */
583 #ifdef __USE_XOPEN
584 /* Return the name of the current user. */
585 extern char *cuserid __P ((char *__s));
586 #endif /* Use X/Open. */
589 #ifdef __USE_GNU
590 struct obstack; /* See <obstack.h>. */
592 /* Write formatted output to an obstack. */
593 extern int obstack_printf __P ((struct obstack *__restrict __obstack,
594 __const char *__restrict __format, ...));
595 extern int obstack_vprintf __P ((struct obstack *__restrict __obstack,
596 __const char *__restrict __format,
597 _G_va_list __args));
598 #endif /* Use GNU. */
601 #if defined __USE_POSIX || defined __USE_MISC
602 /* These are defined in POSIX.1:1996. */
604 /* Acquire ownership of STREAM. */
605 extern void flockfile __P ((FILE *__stream));
607 /* Try to acquire ownership of STREAM but do not block if it is not
608 possible. */
609 extern int ftrylockfile __P ((FILE *__stream));
611 /* Relinquish the ownership granted for STREAM. */
612 extern void funlockfile __P ((FILE *__stream));
613 #endif /* POSIX || misc */
615 #if defined __USE_XOPEN && !defined __USE_GNU
616 /* The X/Open standard requires some functions and variables to be
617 declared here which do not belong into this header. But we have to
618 follow. In GNU mode we don't do this nonsense. */
619 # define __need_getopt
620 # include <getopt.h>
621 #endif
623 /* If we are compiling with optimizing read this file. It contains
624 several optizing inline functions and macros. */
625 #ifdef __USE_EXTERN_INLINES
626 # include <bits/stdio.h>
627 #endif
629 __END_DECLS
631 #endif /* <stdio.h> included. */
633 #endif /* !_STDIO_H */