Update.
[glibc.git] / stdio / stdio.h
blob7be0c24c5ca67c94c0294dfb0e66905f22eb9a0a
1 /* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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 #if !defined(__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 #define __need___va_list
36 #include <stdarg.h>
37 #ifndef __GNUC_VA_LIST
38 #define __gnuc_va_list __ptr_t
39 #endif
41 #include <bits/types.h>
42 #endif /* Don't need FILE. */
43 #undef __need_FILE
46 #ifndef __FILE_defined
48 /* The opaque type of streams. */
49 typedef struct __stdio_file FILE;
51 #define __FILE_defined 1
52 #endif /* FILE not defined. */
55 #ifdef _STDIO_H
57 /* The type of the second argument to `fgetpos' and `fsetpos'. */
58 typedef __off_t fpos_t;
60 /* The mode of I/O, as given in the MODE argument to fopen, etc. */
61 typedef struct
63 unsigned int __read:1; /* Open for reading. */
64 unsigned int __write:1; /* Open for writing. */
65 unsigned int __append:1; /* Open for appending. */
66 unsigned int __binary:1; /* Opened binary. */
67 unsigned int __create:1; /* Create the file. */
68 unsigned int __exclusive:1; /* Error if it already exists. */
69 unsigned int __truncate:1; /* Truncate the file on opening. */
70 } __io_mode;
73 /* Functions to do I/O and file management for a stream. */
75 /* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
76 Return number of bytes read. */
77 typedef __ssize_t __io_read_fn (__ptr_t __cookie, char *__buf,
78 size_t __nbytes);
80 /* Write N bytes pointed to by BUF to COOKIE. Write all N bytes
81 unless there is an error. Return number of bytes written, or -1 if
82 there is an error without writing anything. If the file has been
83 opened for append (__mode.__append set), then set the file pointer
84 to the end of the file and then do the write; if not, just write at
85 the current file pointer. */
86 typedef __ssize_t __io_write_fn (__ptr_t __cookie, __const char *__buf,
87 size_t __n);
89 /* Move COOKIE's file position to *POS bytes from the
90 beginning of the file (if W is SEEK_SET),
91 the current position (if W is SEEK_CUR),
92 or the end of the file (if W is SEEK_END).
93 Set *POS to the new file position.
94 Returns zero if successful, nonzero if not. */
95 typedef int __io_seek_fn (__ptr_t __cookie, fpos_t *__pos, int __w);
97 /* Close COOKIE. */
98 typedef int __io_close_fn (__ptr_t __cookie);
100 /* Return the file descriptor associated with COOKIE,
101 or -1 on error. There need not be any associated file descriptor. */
102 typedef int __io_fileno_fn (__ptr_t __cookie);
104 #ifdef __USE_GNU
105 /* User-visible names for the above. */
106 typedef __io_read_fn cookie_read_function_t;
107 typedef __io_write_fn cookie_write_function_t;
108 typedef __io_seek_fn cookie_seek_function_t;
109 typedef __io_close_fn cookie_close_function_t;
110 typedef __io_fileno_fn cookie_fileno_function_t;
111 #endif
113 /* Low level interface, independent of FILE representation. */
114 #if defined __USE_GNU && !defined _LIBC
115 /* Define the user-visible type, with user-friendly member names. */
116 typedef struct
118 __io_read_fn *read; /* Read bytes. */
119 __io_write_fn *write; /* Write bytes. */
120 __io_seek_fn *seek; /* Seek/tell file position. */
121 __io_close_fn *close; /* Close file. */
122 __io_fileno_fn *fileno; /* Return file descriptor. */
123 } cookie_io_functions_t;
124 /* This name is still used in the prototypes in this file. */
125 typedef cookie_io_functions_t __io_functions;
126 #else
127 /* Stick to ANSI-safe names. */
128 typedef struct
130 __io_read_fn *__read; /* Read bytes. */
131 __io_write_fn *__write; /* Write bytes. */
132 __io_seek_fn *__seek; /* Seek/tell file position. */
133 __io_close_fn *__close; /* Close file. */
134 __io_fileno_fn *__fileno; /* Return file descriptor. */
135 } __io_functions;
136 #endif
138 /* Higher level interface, dependent on FILE representation. */
139 typedef struct
141 /* Make room in the input buffer. */
142 int (*__input) (FILE *__stream);
143 /* Make room in the output buffer. */
144 void (*__output) (FILE *__stream, int __c);
145 } __room_functions;
147 extern __const __io_functions __default_io_functions;
148 extern __const __room_functions __default_room_functions;
151 /* Default close function. */
152 extern __io_close_fn __stdio_close;
153 /* Open FILE with mode M, store cookie in *COOKIEPTR. */
154 extern int __stdio_open (__const char *__file, __io_mode __m,
155 void **__cookieptr) __THROW;
156 /* Put out an error message for when stdio needs to die. */
157 extern void __stdio_errmsg (__const char *__msg, size_t __len) __THROW;
161 /* For thread safe I/O functions we need a lock in each stream. We
162 keep the type opaque here. */
163 struct __stdio_lock;
165 /* The FILE structure. */
166 struct __stdio_file
168 /* Magic number for validation. Must be negative in open streams
169 for the glue to Unix stdio getc/putc to work.
170 NOTE: stdio/glue.c has special knowledge of these first four members. */
171 int __magic;
172 #define _IOMAGIC ((int) 0xfedabeeb) /* Magic number to fill `__magic'. */
173 #define _GLUEMAGIC ((int) 0xfeedbabe) /* Magic for glued Unix streams. */
175 char *__bufp; /* Pointer into the buffer. */
176 char *__get_limit; /* Reading limit. */
177 char *__put_limit; /* Writing limit. */
179 char *__buffer; /* Base of buffer. */
180 size_t __bufsize; /* Size of the buffer. */
181 __ptr_t __cookie; /* Magic cookie. */
182 __io_mode __mode; /* File access mode. */
183 __io_functions __io_funcs; /* I/O functions. */
184 __room_functions __room_funcs;/* I/O buffer room functions. */
185 fpos_t __offset; /* Current file position. */
186 fpos_t __target; /* Target file position. */
187 FILE *__next; /* Next FILE in the linked list. */
188 char *__pushback_bufp; /* Old bufp if char pushed back. */
189 unsigned char __pushback; /* Pushed-back character. */
190 unsigned int __pushed_back:1; /* A char has been pushed back. */
191 unsigned int __eof:1; /* End of file encountered. */
192 unsigned int __error:1; /* Error encountered. */
193 unsigned int __userbuf:1; /* Buffer from user (should not be freed). */
194 unsigned int __linebuf:1; /* Flush on newline. */
195 unsigned int __linebuf_active:1; /* put_limit is not really in use. */
196 unsigned int __seen:1; /* This stream has been seen. */
197 unsigned int __ispipe:1; /* Nonzero if opened by popen. */
198 struct __stdio_lock *__lock; /* Pointer to associated lock. */
202 /* All macros used internally by other macros here and by stdio functions begin
203 with `__'. All of these may evaluate their arguments more than once. */
206 /* Nonzero if STREAM is a valid stream.
207 STREAM must be a modifiable lvalue (wow, I got to use that term).
208 See stdio/glue.c for what the confusing bit is about. */
209 #define __validfp(stream) \
210 (stream != NULL && \
211 ({ if (stream->__magic == _GLUEMAGIC) \
212 stream = *((struct { int __magic; FILE **__p; } *) stream)->__p; \
213 stream->__magic == _IOMAGIC; }))
215 /* Clear the error and EOF indicators of STREAM. */
216 #define __clearerr(stream) ((stream)->__error = (stream)->__eof = 0)
218 /* Nuke STREAM, making it unusable but available for reuse. */
219 extern void __invalidate (FILE *__stream) __THROW;
221 /* Make sure STREAM->__offset and STREAM->__target are initialized.
222 Returns 0 if successful, or EOF on
223 error (but doesn't set STREAM->__error). */
224 extern int __stdio_check_offset (FILE *__stream) __THROW;
227 /* The possibilities for the third argument to `setvbuf'. */
228 #define _IOFBF 0x1 /* Full buffering. */
229 #define _IOLBF 0x2 /* Line buffering. */
230 #define _IONBF 0x4 /* No buffering. */
233 /* Default buffer size. */
234 #define BUFSIZ 1024
237 /* End of file character.
238 Some things throughout the library rely on this being -1. */
239 #define EOF (-1)
242 /* The possibilities for the third argument to `fseek'.
243 These values should not be changed. */
244 #define SEEK_SET 0 /* Seek from beginning of file. */
245 #define SEEK_CUR 1 /* Seek from current position. */
246 #define SEEK_END 2 /* Seek from end of file. */
249 #ifdef __USE_SVID
250 /* Default path prefix for `tempnam' and `tmpnam'. */
251 #define P_tmpdir "/usr/tmp"
252 #endif
255 /* Get the values:
256 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
257 TMP_MAX The minimum number of unique filenames generated by tmpnam
258 (and tempnam when it uses tmpnam's name space),
259 or tempnam (the two are separate).
260 L_ctermid How long an array to pass to `ctermid'.
261 L_cuserid How long an array to pass to `cuserid'.
262 FOPEN_MAX Minimum number of files that can be open at once.
263 FILENAME_MAX Maximum length of a filename. */
264 #include <bits/stdio_lim.h>
267 /* All the known streams are in a linked list
268 linked by the `next' field of the FILE structure. */
269 extern FILE *__stdio_head; /* Head of the list. */
271 /* Standard streams. */
272 extern FILE *stdin, *stdout, *stderr;
273 #ifdef __STRICT_ANSI__
274 /* ANSI says these are macros; satisfy pedants. */
275 #define stdin stdin
276 #define stdout stdout
277 #define stderr stderr
278 #endif
281 /* Remove file FILENAME. */
282 extern int remove (__const char *__filename) __THROW;
283 /* Rename file OLD to NEW. */
284 extern int rename (__const char *__old, __const char *__new) __THROW;
287 /* Create a temporary file and open it read/write. */
288 extern FILE *tmpfile (void) __THROW;
289 #ifdef __USE_LARGEFILE64
290 extern FILE *tmpfile64 (void) __THROW;
291 #endif
292 /* Generate a temporary filename. */
293 extern char *tmpnam (char *__s) __THROW;
295 #ifdef __USE_REENTRANT
296 /* This is the reentrant variant of `tmpnam'. The only difference is
297 that it does not allow S to be NULL. */
298 extern char *tmpnam_r (char *__s) __THROW;
299 #endif
302 #if defined __USE_SVID || defined __USE_XOPEN
303 /* Generate a unique temporary filename using up to five characters of PFX
304 if it is not NULL. The directory to put this file in is searched for
305 as follows: First the environment variable "TMPDIR" is checked.
306 If it contains the name of a writable directory, that directory is used.
307 If not and if DIR is not NULL, that value is checked. If that fails,
308 P_tmpdir is tried and finally "/tmp". The storage for the filename
309 is allocated by `malloc'. */
310 extern char *tempnam (__const char *__dir, __const char *__pfx) __THROW;
311 #endif
314 /* This performs actual output when necessary, flushing
315 STREAM's buffer and optionally writing another character. */
316 extern int __flshfp (FILE *__stream, int __c) __THROW;
319 /* Close STREAM. */
320 extern int fclose (FILE *__stream) __THROW;
321 /* Flush STREAM, or all streams if STREAM is NULL. */
322 extern int fflush (FILE *__stream) __THROW;
324 #ifdef __USE_MISC
325 /* Faster versions when locking is not required. */
326 extern int fflush_unlocked (FILE *__stream) __THROW;
327 #endif
329 #ifdef __USE_GNU
330 /* Close all streams. */
331 extern int __fcloseall (void) __THROW;
332 extern int fcloseall (void) __THROW;
333 #endif
336 /* Open a file and create a new stream for it. */
337 extern FILE *fopen (__const char *__filename, __const char *__modes) __THROW;
338 /* Open a file, replacing an existing stream with it. */
339 extern FILE *freopen (__const char *__restrict __filename,
340 __const char *__restrict __modes,
341 FILE *__restrict __stream) __THROW;
343 /* Return a new, zeroed, stream.
344 You must set its cookie and io_mode.
345 The first operation will give it a buffer unless you do.
346 It will also give it the default functions unless you set the `seen' flag.
347 The offset is set to -1, meaning it will be determined by doing a
348 stationary seek. You can set it to avoid the initial tell call.
349 The target is set to -1, meaning it will be set to the offset
350 before the target is needed.
351 Returns NULL if a stream can't be created. */
352 extern FILE *__newstream (void) __THROW;
354 #ifdef __USE_POSIX
355 /* Create a new stream that refers to an existing system file descriptor. */
356 extern FILE *__fdopen (int __fd, __const char *__modes) __THROW;
357 extern FILE *fdopen (int __fd, __const char *__modes) __THROW;
358 #endif
360 #ifdef __USE_GNU
361 /* Create a new stream that refers to the given magic cookie,
362 and uses the given functions for input and output. */
363 extern FILE *fopencookie (void *__magic_cookie, __const char *__modes,
364 __io_functions __io_funcs) __THROW;
366 /* Create a new stream that refers to a memory buffer. */
367 extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) __THROW;
369 /* Open a stream that writes into a malloc'd buffer that is expanded as
370 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
371 and the number of characters written on fflush or fclose. */
372 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW;
373 #endif
376 /* If BUF is NULL, make STREAM unbuffered.
377 Else make it use buffer BUF, of size BUFSIZ. */
378 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
379 /* Make STREAM use buffering mode MODE.
380 If BUF is not NULL, use N bytes of it for buffering;
381 else allocate an internal buffer N bytes long. */
382 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
383 int __modes, size_t __n) __THROW;
385 #ifdef __USE_BSD
386 /* If BUF is NULL, make STREAM unbuffered.
387 Else make it use SIZE bytes of BUF for buffering. */
388 extern void setbuffer (FILE *__stream, char *__buf, size_t __size) __THROW;
390 /* Make STREAM line-buffered. */
391 extern void setlinebuf (FILE *__stream) __THROW;
392 #endif
395 /* Write formatted output to STREAM. */
396 extern int fprintf (FILE *__restrict __stream,
397 __const char *__restrict __format, ...) __THROW;
398 /* Write formatted output to stdout. */
399 extern int printf (__const char *__restrict __format, ...) __THROW;
400 /* Write formatted output to S. */
401 extern int sprintf (char *__restrict __s, __const char *__restrict __format,
402 ...) __THROW;
404 /* Write formatted output to S from argument list ARG. */
405 extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,
406 __gnuc_va_list __arg) __THROW;
407 /* Write formatted output to stdout from argument list ARG. */
408 extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg)
409 __THROW;
410 /* Write formatted output to S from argument list ARG. */
411 extern int vsprintf (char *__restrict __s, __const char *__restrict __format,
412 __gnuc_va_list __arg) __THROW;
414 #ifdef __OPTIMIZE__
415 extern __inline int
416 vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) __THROW
418 return vfprintf (stdout, __fmt, __arg);
420 #endif /* Optimizing. */
422 #if defined __USE_BSD || defined __USE_ISOC99
423 /* Maximum chars of output to write in MAXLEN. */
424 extern int __snprintf (char *__s, size_t __maxlen,
425 __const char *__format, ...)
426 __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
427 extern int snprintf (char *__s, size_t __maxlen, __const char *__format, ...)
428 __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
430 extern int __vsnprintf (char *__s, size_t __maxlen,
431 __const char *__format, __gnuc_va_list __arg)
432 __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
433 extern int vsnprintf (char *__s, size_t __maxlen,
434 __const char *__format, __gnuc_va_list __arg)
435 __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
436 #endif
438 #ifdef __USE_GNU
439 /* Write formatted output to a string dynamically allocated with `malloc'.
440 Store the address of the string in *PTR. */
441 extern int vasprintf (char **__restrict __ptr,
442 __const char *__restrict __f, __gnuc_va_list __arg)
443 __THROW __attribute__ ((__format__ (__printf__, 2, 0)));
444 extern int __asprintf (char **__restrict __ptr,
445 __const char *__restrict __fmt, ...)
446 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
447 extern int asprintf (char **__restrict __ptr,
448 __const char *__restrict __fmt, ...)
449 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
451 /* Write formatted output to a file descriptor. */
452 extern int vdprintf (int __fd, __const char *__restrict __fmt,
453 __gnuc_va_list __arg)
454 __THROW __attribute__ ((__format__ (__printf__, 2, 0)));
455 extern int dprintf (int __fd, __const char *__restrict __fmt, ...)
456 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
457 #endif
460 /* Read formatted input from STREAM. */
461 extern int fscanf (FILE *__restrict __stream,
462 __const char *__restrict __format, ...) __THROW;
463 /* Read formatted input from stdin. */
464 extern int scanf (__const char *__restrict __format, ...) __THROW;
465 /* Read formatted input from S. */
466 extern int sscanf (__const char *__restrict __s,
467 __const char *__restrict __format, ...) __THROW;
469 #ifdef __USE_ISOC99
470 /* Read formatted input from S into argument list ARG. */
471 extern int __vfscanf (FILE *__s, __const char *__format,
472 __gnuc_va_list __arg) __THROW;
473 extern int vfscanf (FILE *__s, __const char *__format,
474 __gnuc_va_list __arg) __THROW;
476 /* Read formatted input from stdin into argument list ARG. */
477 extern int __vscanf (__const char *__format, __gnuc_va_list __arg) __THROW;
478 extern int vscanf (__const char *__format, __gnuc_va_list __arg) __THROW;
480 /* Read formatted input from S into argument list ARG. */
481 extern int __vsscanf (__const char *__s, __const char *__format,
482 __gnuc_va_list __arg) __THROW;
483 extern int vsscanf (__const char *__s, __const char *__format,
484 __gnuc_va_list __arg) __THROW;
487 #ifdef __OPTIMIZE__
488 extern __inline int
489 vfscanf (FILE *__s, const char *__fmt, __gnuc_va_list __arg) __THROW
491 return __vfscanf (__s, __fmt, __arg);
493 extern __inline int
494 vscanf (const char *__fmt, __gnuc_va_list __arg) __THROW
496 return __vfscanf (stdin, __fmt, __arg);
498 extern __inline int
499 vsscanf (const char *__s, const char *__fmt, __gnuc_va_list __arg) __THROW
501 return __vsscanf (__s, __fmt, __arg);
503 #endif /* Optimizing. */
504 #endif /* Use ISO C9x. */
507 /* This does actual reading when necessary, filling STREAM's
508 buffer and returning the first character in it. */
509 extern int __fillbf (FILE *__stream) __THROW;
512 /* Read a character from STREAM. */
513 extern int fgetc (FILE *__stream) __THROW;
514 extern int getc (FILE *__stream) __THROW;
516 /* Read a character from stdin. */
517 extern int getchar (void) __THROW;
519 /* The C standard explicitly says this can
520 re-evaluate its argument, so it does. */
521 #define __getc(stream) \
522 ((stream)->__bufp < (stream)->__get_limit ? \
523 (int) ((unsigned char) *(stream)->__bufp++) : __fillbf(stream))
525 /* The C standard explicitly says this is a macro,
526 so we always do the optimization for it. */
527 #define getc(stream) __getc(stream)
529 #ifdef __OPTIMIZE__
530 extern __inline int
531 getchar (void) __THROW
533 return __getc (stdin);
535 #endif /* Optimizing. */
537 #if defined __USE_POSIX || defined __USE_MISC
538 /* These are defined in POSIX.1:1996. */
539 extern int getc_unlocked (FILE *__stream) __THROW;
540 extern int getchar_unlocked (void) __THROW;
542 # ifdef __OPTIMIZE__
543 extern __inline int
544 getc_unlocked (FILE *__stream) __THROW
546 return __getc (__stream);
549 extern __inline int
550 getchar_unlocked (void) __THROW
552 return __getc (stdin);
554 # endif /* Optimizing. */
555 #endif /* Use POSIX or MISC. */
558 /* Write a character to STREAM. */
559 extern int fputc (int __c, FILE *__stream) __THROW;
560 extern int putc (int __c, FILE *__stream) __THROW;
562 /* Write a character to stdout. */
563 extern int putchar (int __c) __THROW;
566 /* The C standard explicitly says this can
567 re-evaluate its arguments, so it does. */
568 #define __putc(c, stream) \
569 ((stream)->__bufp < (stream)->__put_limit ? \
570 (int) (unsigned char) (*(stream)->__bufp++ = (unsigned char) (c)) : \
571 __flshfp ((stream), (unsigned char) (c)))
573 /* The C standard explicitly says this can be a macro,
574 so we always do the optimization for it. */
575 #define putc(c, stream) __putc ((c), (stream))
577 #ifdef __OPTIMIZE__
578 extern __inline int
579 putchar (int __c) __THROW
581 return __putc (__c, stdout);
583 #endif
585 #ifdef __USE_MISC
586 /* Faster version when locking is not necessary. */
587 extern int fputc_unlocked (int __c, FILE *__stream) __THROW;
589 # ifdef __OPTIMIZE__
590 extern __inline int
591 fputc_unlocked (int __c, FILE *__stream) __THROW
593 return __putc (__c, __stream);
595 # endif /* Optimizing. */
596 #endif /* Use MISC. */
598 #if defined __USE_POSIX || defined __USE_MISC
599 /* These are defined in POSIX.1:1996. */
600 extern int putc_unlocked (int __c, FILE *__stream) __THROW;
601 extern int putchar_unlocked (int __c) __THROW;
603 # ifdef __OPTIMIZE__
604 extern __inline int
605 putc_unlocked (int __c, FILE *__stream) __THROW
607 return __putc (__c, __stream);
610 extern __inline int
611 putchar_unlocked (int __c) __THROW
613 return __putc (__c, stdout);
615 # endif /* Optimizing. */
616 #endif /* Use POSIX or MISC. */
619 #if defined __USE_SVID || defined __USE_MISC
620 /* Get a word (int) from STREAM. */
621 extern int getw (FILE *__stream) __THROW;
623 /* Write a word (int) to STREAM. */
624 extern int putw (int __w, FILE *__stream) __THROW;
625 #endif
628 /* Get a newline-terminated string of finite length from STREAM. */
629 extern char *fgets (char *__restrict __s, int __n,
630 FILE *__restrict __stream) __THROW;
632 #ifdef __USE_GNU
633 /* This function does the same as `fgets' but does not lock the stream. */
634 extern char *fgets_unlocked (char *__restrict __s, int __n,
635 FILE *__restrict __stream) __THROW;
636 #endif
638 /* Get a newline-terminated string from stdin, removing the newline.
639 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
640 extern char *gets (char *__s) __THROW;
643 #ifdef __USE_GNU
644 #include <sys/types.h>
646 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
647 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
648 NULL), pointing to *N characters of space. It is realloc'd as
649 necessary. Returns the number of characters read (not including the
650 null terminator), or -1 on error or EOF. */
651 ssize_t __getdelim (char **__lineptr, size_t *__n,
652 int __delimiter, FILE *__stream) __THROW;
653 ssize_t getdelim (char **__lineptr, size_t *__n,
654 int __delimiter, FILE *__stream) __THROW;
656 /* Like `getdelim', but reads up to a newline. */
657 ssize_t __getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW;
658 ssize_t getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW;
660 #ifdef __OPTIMIZE__
661 extern __inline ssize_t
662 getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW
664 return __getdelim (__lineptr, __n, '\n', __stream);
666 #endif /* Optimizing. */
667 #endif
670 /* Write a string to STREAM. */
671 extern int fputs (__const char *__restrict __s, FILE *__restrict __stream)
672 __THROW;
674 #ifdef __USE_GNU
675 /* This function does the same as `fputs' but does not lock the stream. */
676 extern int fputs_unlocked (__const char *__restrict __s,
677 FILE *__restrict __stream) __THROW;
678 #endif
680 /* Write a string, followed by a newline, to stdout. */
681 extern int puts (__const char *__s) __THROW;
684 /* Push a character back onto the input buffer of STREAM. */
685 extern int ungetc (int __c, FILE *__stream) __THROW;
688 /* Read chunks of generic data from STREAM. */
689 extern size_t fread (void *__restrict __ptr, size_t __size,
690 size_t __n, FILE *__restrict __stream) __THROW;
691 /* Write chunks of generic data to STREAM. */
692 extern size_t fwrite (__const void *__restrict __ptr, size_t __size,
693 size_t __n, FILE *__restrict __s) __THROW;
695 #ifdef __USE_MISC
696 /* Faster versions when locking is not necessary. */
697 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
698 size_t __n, FILE *__restrict __stream) __THROW;
699 extern size_t fwrite_unlocked (__const void *__restrict __ptr,
700 size_t __size, size_t __n,
701 FILE *__restrict __stream) __THROW;
702 #endif
705 /* Seek to a certain position on STREAM. */
706 extern int fseek (FILE *__stream, long int __off, int __whence) __THROW;
707 /* Return the current position of STREAM. */
708 extern long int ftell (FILE *__stream) __THROW;
709 /* Rewind to the beginning of STREAM. */
710 extern void rewind (FILE *__stream) __THROW;
712 /* Get STREAM's position. */
713 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos)
714 __THROW;
715 /* Set STREAM's position. */
716 extern int fsetpos (FILE *__stream, __const fpos_t *__pos) __THROW;
719 /* Clear the error and EOF indicators for STREAM. */
720 extern void clearerr (FILE *__stream) __THROW;
721 /* Return the EOF indicator for STREAM. */
722 extern int feof (FILE *__stream) __THROW;
723 /* Return the error indicator for STREAM. */
724 extern int ferror (FILE *__stream) __THROW;
726 #ifdef __OPTIMIZE__
727 #define feof(stream) ((stream)->__eof != 0)
728 #define ferror(stream) ((stream)->__error != 0)
729 #endif /* Optimizing. */
731 #ifdef __USE_MISC
732 /* Faster versions when locking is not required. */
733 extern void clearerr_unlocked (FILE *__stream) __THROW;
734 extern int feof_unlocked (FILE *__stream) __THROW;
735 extern int ferror_unlocked (FILE *__stream) __THROW;
737 # ifdef __OPTIMIZE__
738 # define feof_unlocked(stream) ((stream)->__eof != 0)
739 # define ferror_unlocked(stream) ((stream)->__error != 0)
740 # endif /* Optimizing. */
741 #endif
743 /* Print a message describing the meaning of the value of errno. */
744 extern void perror (__const char *__s) __THROW;
747 #ifdef __USE_POSIX
748 /* Return the system file descriptor for STREAM. */
749 extern int fileno (FILE *__stream) __THROW;
750 #endif /* Use POSIX. */
752 #ifdef __USE_MISC
753 /* Faster version when locking is not required. */
754 extern int fileno_unlocked (FILE *__stream) __THROW;
755 #endif
758 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
759 defined __USE_MISC)
760 /* Create a new stream connected to a pipe running the given command. */
761 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
763 /* Close a stream opened by popen and return the status of its child. */
764 extern int pclose (FILE *__stream) __THROW;
765 #endif
768 #ifdef __USE_POSIX
769 /* Return the name of the controlling terminal. */
770 extern char *ctermid (char *__s) __THROW;
771 #endif
774 #ifdef __USE_XOPEN
775 /* Return the name of the current user. */
776 extern char *cuserid (char *__s) __THROW;
777 #endif
780 #ifdef __USE_GNU
781 struct obstack; /* See <obstack.h>. */
783 /* Open a stream that writes to OBSTACK. */
784 extern FILE *open_obstack_stream (struct obstack *__obstack) __THROW;
786 /* Write formatted output to an obstack. */
787 extern int obstack_printf (struct obstack *__obstack,
788 __const char *__format, ...) __THROW;
789 extern int obstack_vprintf (struct obstack *__obstack, __const char *__format,
790 __gnuc_va_list __args) __THROW;
791 #endif
794 #if defined __USE_POSIX || defined __USE_MISC
795 /* These are defined in POSIX.1:1996. */
797 /* Acquire ownership of STREAM. */
798 extern void flockfile (FILE *__stream) __THROW;
800 /* Try to acquire ownership of STREAM but do not block if it is not
801 possible. */
802 extern int ftrylockfile (FILE *__stream) __THROW;
804 /* Relinquish the ownership granted for STREAM. */
805 extern void funlockfile (FILE *__stream) __THROW;
806 #endif /* POSIX || misc */
808 #if defined __USE_XOPEN && !defined __USE_GNU
809 /* The X/Open standard requires some functions and variables to be
810 declared here which do not belong into this header. But we have to
811 follow. In GNU mode we don't do this nonsense. */
812 # define __need_getopt
813 # include <getopt.h>
814 #endif
816 __END_DECLS
818 #endif /* <stdio.h> included. */
820 #endif /* stdio.h */