Adjusted.
[glibc.git] / stdio / stdio.h
blobc67ab6326e71d4bfabba507ba890df22189c6f43
1 /* Copyright (C) 1991-1999, 2000 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 C99 Standard: 7.19 Input/output <stdio.h>
23 #ifndef _STDIO_H
25 #if !defined(__need_FILE) && !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 #define __need_FILE
43 #define __need___FILE
44 #endif /* Don't need FILE. */
47 #if !defined __FILE_defined && defined __need_FILE
49 /* The opaque type of streams. */
50 typedef struct __stdio_file FILE;
52 #define __FILE_defined 1
53 #endif /* FILE not defined. */
54 #undef __need_FILE
57 #if !defined ____FILE_defined && defined __need___FILE
59 /* The opaque type of streams. */
60 typedef struct __stdio_file __FILE;
62 #define ____FILE_defined 1
63 #endif /* __FILE not defined. */
64 #undef __need___FILE
67 #ifdef _STDIO_H
69 /* The type of the second argument to `fgetpos' and `fsetpos'. */
70 typedef __off_t fpos_t;
72 /* The mode of I/O, as given in the MODE argument to fopen, etc. */
73 typedef struct
75 unsigned int __read:1; /* Open for reading. */
76 unsigned int __write:1; /* Open for writing. */
77 unsigned int __append:1; /* Open for appending. */
78 unsigned int __binary:1; /* Opened binary. */
79 unsigned int __create:1; /* Create the file. */
80 unsigned int __exclusive:1; /* Error if it already exists. */
81 unsigned int __truncate:1; /* Truncate the file on opening. */
82 } __io_mode;
85 /* Functions to do I/O and file management for a stream. */
87 /* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
88 Return number of bytes read. */
89 typedef __ssize_t __io_read_fn (__ptr_t __cookie, char *__buf,
90 size_t __nbytes);
92 /* Write N bytes pointed to by BUF to COOKIE. Write all N bytes
93 unless there is an error. Return number of bytes written, or -1 if
94 there is an error without writing anything. If the file has been
95 opened for append (__mode.__append set), then set the file pointer
96 to the end of the file and then do the write; if not, just write at
97 the current file pointer. */
98 typedef __ssize_t __io_write_fn (__ptr_t __cookie, __const char *__buf,
99 size_t __n);
101 /* Move COOKIE's file position to *POS bytes from the
102 beginning of the file (if W is SEEK_SET),
103 the current position (if W is SEEK_CUR),
104 or the end of the file (if W is SEEK_END).
105 Set *POS to the new file position.
106 Returns zero if successful, nonzero if not. */
107 typedef int __io_seek_fn (__ptr_t __cookie, fpos_t *__pos, int __w);
109 /* Close COOKIE. */
110 typedef int __io_close_fn (__ptr_t __cookie);
112 /* Return the file descriptor associated with COOKIE,
113 or -1 on error. There need not be any associated file descriptor. */
114 typedef int __io_fileno_fn (__ptr_t __cookie);
116 #ifdef __USE_GNU
117 /* User-visible names for the above. */
118 typedef __io_read_fn cookie_read_function_t;
119 typedef __io_write_fn cookie_write_function_t;
120 typedef __io_seek_fn cookie_seek_function_t;
121 typedef __io_close_fn cookie_close_function_t;
122 typedef __io_fileno_fn cookie_fileno_function_t;
123 #endif
125 /* Low level interface, independent of FILE representation. */
126 #if defined __USE_GNU && !defined _LIBC
127 /* Define the user-visible type, with user-friendly member 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 } cookie_io_functions_t;
136 /* This name is still used in the prototypes in this file. */
137 typedef cookie_io_functions_t __io_functions;
138 #else
139 /* Stick to ANSI-safe names. */
140 typedef struct
142 __io_read_fn *__read; /* Read bytes. */
143 __io_write_fn *__write; /* Write bytes. */
144 __io_seek_fn *__seek; /* Seek/tell file position. */
145 __io_close_fn *__close; /* Close file. */
146 __io_fileno_fn *__fileno; /* Return file descriptor. */
147 } __io_functions;
148 #endif
150 /* Higher level interface, dependent on FILE representation. */
151 typedef struct
153 /* Make room in the input buffer. */
154 int (*__input) (FILE *__stream);
155 /* Make room in the output buffer. */
156 void (*__output) (FILE *__stream, int __c);
157 } __room_functions;
159 extern __const __io_functions __default_io_functions;
160 extern __const __room_functions __default_room_functions;
163 /* Default close function. */
164 extern __io_close_fn __stdio_close;
165 /* Open FILE with mode M, store cookie in *COOKIEPTR. */
166 extern int __stdio_open (__const char *__file, __io_mode __m,
167 void **__cookieptr) __THROW;
168 /* Put out an error message for when stdio needs to die. */
169 extern void __stdio_errmsg (__const char *__msg, size_t __len) __THROW;
173 /* For thread safe I/O functions we need a lock in each stream. We
174 keep the type opaque here. */
175 struct __stdio_lock;
177 /* The FILE structure. */
178 struct __stdio_file
180 /* Magic number for validation. Must be negative in open streams
181 for the glue to Unix stdio getc/putc to work.
182 NOTE: stdio/glue.c has special knowledge of these first four members. */
183 int __magic;
184 #define _IOMAGIC ((int) 0xfedabeeb) /* Magic number to fill `__magic'. */
185 #define _GLUEMAGIC ((int) 0xfeedbabe) /* Magic for glued Unix streams. */
187 char *__bufp; /* Pointer into the buffer. */
188 char *__get_limit; /* Reading limit. */
189 char *__put_limit; /* Writing limit. */
191 char *__buffer; /* Base of buffer. */
192 size_t __bufsize; /* Size of the buffer. */
193 __ptr_t __cookie; /* Magic cookie. */
194 __io_mode __mode; /* File access mode. */
195 __io_functions __io_funcs; /* I/O functions. */
196 __room_functions __room_funcs;/* I/O buffer room functions. */
197 fpos_t __offset; /* Current file position. */
198 fpos_t __target; /* Target file position. */
199 FILE *__next; /* Next FILE in the linked list. */
200 char *__pushback_bufp; /* Old bufp if char pushed back. */
201 unsigned char __pushback; /* Pushed-back character. */
202 unsigned int __pushed_back:1; /* A char has been pushed back. */
203 unsigned int __eof:1; /* End of file encountered. */
204 unsigned int __error:1; /* Error encountered. */
205 unsigned int __userbuf:1; /* Buffer from user (should not be freed). */
206 unsigned int __linebuf:1; /* Flush on newline. */
207 unsigned int __linebuf_active:1; /* put_limit is not really in use. */
208 unsigned int __seen:1; /* This stream has been seen. */
209 unsigned int __ispipe:1; /* Nonzero if opened by popen. */
210 struct __stdio_lock *__lock; /* Pointer to associated lock. */
214 /* All macros used internally by other macros here and by stdio functions begin
215 with `__'. All of these may evaluate their arguments more than once. */
218 /* Nonzero if STREAM is a valid stream.
219 STREAM must be a modifiable lvalue (wow, I got to use that term).
220 See stdio/glue.c for what the confusing bit is about. */
221 #define __validfp(stream) \
222 (stream != NULL && \
223 ({ if (stream->__magic == _GLUEMAGIC) \
224 stream = *((struct { int __magic; FILE **__p; } *) stream)->__p; \
225 stream->__magic == _IOMAGIC; }))
227 /* Clear the error and EOF indicators of STREAM. */
228 #define __clearerr(stream) ((stream)->__error = (stream)->__eof = 0)
230 /* Nuke STREAM, making it unusable but available for reuse. */
231 extern void __invalidate (FILE *__stream) __THROW;
233 /* Make sure STREAM->__offset and STREAM->__target are initialized.
234 Returns 0 if successful, or EOF on
235 error (but doesn't set STREAM->__error). */
236 extern int __stdio_check_offset (FILE *__stream) __THROW;
239 /* The possibilities for the third argument to `setvbuf'. */
240 #define _IOFBF 0x1 /* Full buffering. */
241 #define _IOLBF 0x2 /* Line buffering. */
242 #define _IONBF 0x4 /* No buffering. */
245 /* Default buffer size. */
246 #define BUFSIZ 1024
249 /* End of file character.
250 Some things throughout the library rely on this being -1. */
251 #define EOF (-1)
254 /* The possibilities for the third argument to `fseek'.
255 These values should not be changed. */
256 #define SEEK_SET 0 /* Seek from beginning of file. */
257 #define SEEK_CUR 1 /* Seek from current position. */
258 #define SEEK_END 2 /* Seek from end of file. */
261 #ifdef __USE_SVID
262 /* Default path prefix for `tempnam' and `tmpnam'. */
263 #define P_tmpdir "/usr/tmp"
264 #endif
267 /* Get the values:
268 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
269 TMP_MAX The minimum number of unique filenames generated by tmpnam
270 (and tempnam when it uses tmpnam's name space),
271 or tempnam (the two are separate).
272 L_ctermid How long an array to pass to `ctermid'.
273 L_cuserid How long an array to pass to `cuserid'.
274 FOPEN_MAX Minimum number of files that can be open at once.
275 FILENAME_MAX Maximum length of a filename. */
276 #include <bits/stdio_lim.h>
279 /* All the known streams are in a linked list
280 linked by the `next' field of the FILE structure. */
281 extern FILE *__stdio_head; /* Head of the list. */
283 /* Standard streams. */
284 extern FILE *stdin, *stdout, *stderr;
285 #ifdef __STRICT_ANSI__
286 /* ANSI says these are macros; satisfy pedants. */
287 #define stdin stdin
288 #define stdout stdout
289 #define stderr stderr
290 #endif
293 /* Remove file FILENAME. */
294 extern int remove (__const char *__filename) __THROW;
295 /* Rename file OLD to NEW. */
296 extern int rename (__const char *__old, __const char *__new) __THROW;
299 /* Create a temporary file and open it read/write. */
300 extern FILE *tmpfile (void) __THROW;
301 #ifdef __USE_LARGEFILE64
302 extern FILE *tmpfile64 (void) __THROW;
303 #endif
304 /* Generate a temporary filename. */
305 extern char *tmpnam (char *__s) __THROW;
307 #ifdef __USE_REENTRANT
308 /* This is the reentrant variant of `tmpnam'. The only difference is
309 that it does not allow S to be NULL. */
310 extern char *tmpnam_r (char *__s) __THROW;
311 #endif
314 #if defined __USE_SVID || defined __USE_XOPEN
315 /* Generate a unique temporary filename using up to five characters of PFX
316 if it is not NULL. The directory to put this file in is searched for
317 as follows: First the environment variable "TMPDIR" is checked.
318 If it contains the name of a writable directory, that directory is used.
319 If not and if DIR is not NULL, that value is checked. If that fails,
320 P_tmpdir is tried and finally "/tmp". The storage for the filename
321 is allocated by `malloc'. */
322 extern char *tempnam (__const char *__dir, __const char *__pfx) __THROW;
323 #endif
326 /* This performs actual output when necessary, flushing
327 STREAM's buffer and optionally writing another character. */
328 extern int __flshfp (FILE *__stream, int __c) __THROW;
331 /* Close STREAM. */
332 extern int fclose (FILE *__stream) __THROW;
333 /* Flush STREAM, or all streams if STREAM is NULL. */
334 extern int fflush (FILE *__stream) __THROW;
336 #ifdef __USE_MISC
337 /* Faster versions when locking is not required. */
338 extern int fflush_unlocked (FILE *__stream) __THROW;
339 #endif
341 #ifdef __USE_GNU
342 /* Close all streams. */
343 extern int __fcloseall (void) __THROW;
344 extern int fcloseall (void) __THROW;
345 #endif
348 /* Open a file and create a new stream for it. */
349 extern FILE *fopen (__const char *__filename, __const char *__modes) __THROW;
350 /* Open a file, replacing an existing stream with it. */
351 extern FILE *freopen (__const char *__restrict __filename,
352 __const char *__restrict __modes,
353 FILE *__restrict __stream) __THROW;
355 /* Return a new, zeroed, stream.
356 You must set its cookie and io_mode.
357 The first operation will give it a buffer unless you do.
358 It will also give it the default functions unless you set the `seen' flag.
359 The offset is set to -1, meaning it will be determined by doing a
360 stationary seek. You can set it to avoid the initial tell call.
361 The target is set to -1, meaning it will be set to the offset
362 before the target is needed.
363 Returns NULL if a stream can't be created. */
364 extern FILE *__newstream (void) __THROW;
366 #ifdef __USE_POSIX
367 /* Create a new stream that refers to an existing system file descriptor. */
368 extern FILE *__fdopen (int __fd, __const char *__modes) __THROW;
369 extern FILE *fdopen (int __fd, __const char *__modes) __THROW;
370 #endif
372 #ifdef __USE_GNU
373 /* Create a new stream that refers to the given magic cookie,
374 and uses the given functions for input and output. */
375 extern FILE *fopencookie (void *__magic_cookie, __const char *__modes,
376 __io_functions __io_funcs) __THROW;
378 /* Create a new stream that refers to a memory buffer. */
379 extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) __THROW;
381 /* Open a stream that writes into a malloc'd buffer that is expanded as
382 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
383 and the number of characters written on fflush or fclose. */
384 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW;
385 #endif
388 /* If BUF is NULL, make STREAM unbuffered.
389 Else make it use buffer BUF, of size BUFSIZ. */
390 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
391 /* Make STREAM use buffering mode MODE.
392 If BUF is not NULL, use N bytes of it for buffering;
393 else allocate an internal buffer N bytes long. */
394 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
395 int __modes, size_t __n) __THROW;
397 #ifdef __USE_BSD
398 /* If BUF is NULL, make STREAM unbuffered.
399 Else make it use SIZE bytes of BUF for buffering. */
400 extern void setbuffer (FILE *__stream, char *__buf, size_t __size) __THROW;
402 /* Make STREAM line-buffered. */
403 extern void setlinebuf (FILE *__stream) __THROW;
404 #endif
407 /* Write formatted output to STREAM. */
408 extern int fprintf (FILE *__restrict __stream,
409 __const char *__restrict __format, ...) __THROW;
410 /* Write formatted output to stdout. */
411 extern int printf (__const char *__restrict __format, ...) __THROW;
412 /* Write formatted output to S. */
413 extern int sprintf (char *__restrict __s, __const char *__restrict __format,
414 ...) __THROW;
416 /* Write formatted output to S from argument list ARG. */
417 extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,
418 __gnuc_va_list __arg) __THROW;
419 /* Write formatted output to stdout from argument list ARG. */
420 extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg)
421 __THROW;
422 /* Write formatted output to S from argument list ARG. */
423 extern int vsprintf (char *__restrict __s, __const char *__restrict __format,
424 __gnuc_va_list __arg) __THROW;
426 #ifdef __OPTIMIZE__
427 extern __inline int
428 vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) __THROW
430 return vfprintf (stdout, __fmt, __arg);
432 #endif /* Optimizing. */
434 #if defined __USE_BSD || defined __USE_ISOC99
435 /* Maximum chars of output to write in MAXLEN. */
436 extern int __snprintf (char *__s, size_t __maxlen,
437 __const char *__format, ...)
438 __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
439 extern int snprintf (char *__s, size_t __maxlen, __const char *__format, ...)
440 __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
442 extern int __vsnprintf (char *__s, size_t __maxlen,
443 __const char *__format, __gnuc_va_list __arg)
444 __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
445 extern int vsnprintf (char *__s, size_t __maxlen,
446 __const char *__format, __gnuc_va_list __arg)
447 __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
448 #endif
450 #ifdef __USE_GNU
451 /* Write formatted output to a string dynamically allocated with `malloc'.
452 Store the address of the string in *PTR. */
453 extern int vasprintf (char **__restrict __ptr,
454 __const char *__restrict __f, __gnuc_va_list __arg)
455 __THROW __attribute__ ((__format__ (__printf__, 2, 0)));
456 extern int __asprintf (char **__restrict __ptr,
457 __const char *__restrict __fmt, ...)
458 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
459 extern int asprintf (char **__restrict __ptr,
460 __const char *__restrict __fmt, ...)
461 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
463 /* Write formatted output to a file descriptor. */
464 extern int vdprintf (int __fd, __const char *__restrict __fmt,
465 __gnuc_va_list __arg)
466 __THROW __attribute__ ((__format__ (__printf__, 2, 0)));
467 extern int dprintf (int __fd, __const char *__restrict __fmt, ...)
468 __THROW __attribute__ ((__format__ (__printf__, 2, 3)));
469 #endif
472 /* Read formatted input from STREAM. */
473 extern int fscanf (FILE *__restrict __stream,
474 __const char *__restrict __format, ...) __THROW;
475 /* Read formatted input from stdin. */
476 extern int scanf (__const char *__restrict __format, ...) __THROW;
477 /* Read formatted input from S. */
478 extern int sscanf (__const char *__restrict __s,
479 __const char *__restrict __format, ...) __THROW;
481 #ifdef __USE_ISOC99
482 /* Read formatted input from S into argument list ARG. */
483 extern int __vfscanf (FILE *__s, __const char *__format,
484 __gnuc_va_list __arg) __THROW;
485 extern int vfscanf (FILE *__s, __const char *__format,
486 __gnuc_va_list __arg) __THROW;
488 /* Read formatted input from stdin into argument list ARG. */
489 extern int __vscanf (__const char *__format, __gnuc_va_list __arg) __THROW;
490 extern int vscanf (__const char *__format, __gnuc_va_list __arg) __THROW;
492 /* Read formatted input from S into argument list ARG. */
493 extern int __vsscanf (__const char *__s, __const char *__format,
494 __gnuc_va_list __arg) __THROW;
495 extern int vsscanf (__const char *__s, __const char *__format,
496 __gnuc_va_list __arg) __THROW;
499 #ifdef __OPTIMIZE__
500 extern __inline int
501 vfscanf (FILE *__s, const char *__fmt, __gnuc_va_list __arg) __THROW
503 return __vfscanf (__s, __fmt, __arg);
505 extern __inline int
506 vscanf (const char *__fmt, __gnuc_va_list __arg) __THROW
508 return __vfscanf (stdin, __fmt, __arg);
510 extern __inline int
511 vsscanf (const char *__s, const char *__fmt, __gnuc_va_list __arg) __THROW
513 return __vsscanf (__s, __fmt, __arg);
515 #endif /* Optimizing. */
516 #endif /* Use ISO C9x. */
519 /* This does actual reading when necessary, filling STREAM's
520 buffer and returning the first character in it. */
521 extern int __fillbf (FILE *__stream) __THROW;
524 /* Read a character from STREAM. */
525 extern int fgetc (FILE *__stream) __THROW;
526 extern int getc (FILE *__stream) __THROW;
528 /* Read a character from stdin. */
529 extern int getchar (void) __THROW;
531 /* The C standard explicitly says this can
532 re-evaluate its argument, so it does. */
533 #define __getc(stream) \
534 ((stream)->__bufp < (stream)->__get_limit ? \
535 (int) ((unsigned char) *(stream)->__bufp++) : __fillbf(stream))
537 /* The C standard explicitly says this is a macro,
538 so we always do the optimization for it. */
539 #define getc(stream) __getc(stream)
541 #ifdef __OPTIMIZE__
542 extern __inline int
543 getchar (void) __THROW
545 return __getc (stdin);
547 #endif /* Optimizing. */
549 #if defined __USE_POSIX || defined __USE_MISC
550 /* These are defined in POSIX.1:1996. */
551 extern int getc_unlocked (FILE *__stream) __THROW;
552 extern int getchar_unlocked (void) __THROW;
554 # ifdef __OPTIMIZE__
555 extern __inline int
556 getc_unlocked (FILE *__stream) __THROW
558 return __getc (__stream);
561 extern __inline int
562 getchar_unlocked (void) __THROW
564 return __getc (stdin);
566 # endif /* Optimizing. */
567 #endif /* Use POSIX or MISC. */
570 /* Write a character to STREAM. */
571 extern int fputc (int __c, FILE *__stream) __THROW;
572 extern int putc (int __c, FILE *__stream) __THROW;
574 /* Write a character to stdout. */
575 extern int putchar (int __c) __THROW;
578 /* The C standard explicitly says this can
579 re-evaluate its arguments, so it does. */
580 #define __putc(c, stream) \
581 ((stream)->__bufp < (stream)->__put_limit ? \
582 (int) (unsigned char) (*(stream)->__bufp++ = (unsigned char) (c)) : \
583 __flshfp ((stream), (unsigned char) (c)))
585 /* The C standard explicitly says this can be a macro,
586 so we always do the optimization for it. */
587 #define putc(c, stream) __putc ((c), (stream))
589 #ifdef __OPTIMIZE__
590 extern __inline int
591 putchar (int __c) __THROW
593 return __putc (__c, stdout);
595 #endif
597 #ifdef __USE_MISC
598 /* Faster version when locking is not necessary. */
599 extern int fputc_unlocked (int __c, FILE *__stream) __THROW;
601 # ifdef __OPTIMIZE__
602 extern __inline int
603 fputc_unlocked (int __c, FILE *__stream) __THROW
605 return __putc (__c, __stream);
607 # endif /* Optimizing. */
608 #endif /* Use MISC. */
610 #if defined __USE_POSIX || defined __USE_MISC
611 /* These are defined in POSIX.1:1996. */
612 extern int putc_unlocked (int __c, FILE *__stream) __THROW;
613 extern int putchar_unlocked (int __c) __THROW;
615 # ifdef __OPTIMIZE__
616 extern __inline int
617 putc_unlocked (int __c, FILE *__stream) __THROW
619 return __putc (__c, __stream);
622 extern __inline int
623 putchar_unlocked (int __c) __THROW
625 return __putc (__c, stdout);
627 # endif /* Optimizing. */
628 #endif /* Use POSIX or MISC. */
631 #if defined __USE_SVID || defined __USE_MISC
632 /* Get a word (int) from STREAM. */
633 extern int getw (FILE *__stream) __THROW;
635 /* Write a word (int) to STREAM. */
636 extern int putw (int __w, FILE *__stream) __THROW;
637 #endif
640 /* Get a newline-terminated string of finite length from STREAM. */
641 extern char *fgets (char *__restrict __s, int __n,
642 FILE *__restrict __stream) __THROW;
644 #ifdef __USE_GNU
645 /* This function does the same as `fgets' but does not lock the stream. */
646 extern char *fgets_unlocked (char *__restrict __s, int __n,
647 FILE *__restrict __stream) __THROW;
648 #endif
650 /* Get a newline-terminated string from stdin, removing the newline.
651 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
652 extern char *gets (char *__s) __THROW;
655 #ifdef __USE_GNU
656 #include <sys/types.h>
658 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
659 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
660 NULL), pointing to *N characters of space. It is realloc'd as
661 necessary. Returns the number of characters read (not including the
662 null terminator), or -1 on error or EOF. */
663 ssize_t __getdelim (char **__lineptr, size_t *__n,
664 int __delimiter, FILE *__stream) __THROW;
665 ssize_t getdelim (char **__lineptr, size_t *__n,
666 int __delimiter, FILE *__stream) __THROW;
668 /* Like `getdelim', but reads up to a newline. */
669 ssize_t __getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW;
670 ssize_t getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW;
672 #ifdef __OPTIMIZE__
673 extern __inline ssize_t
674 getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW
676 return __getdelim (__lineptr, __n, '\n', __stream);
678 #endif /* Optimizing. */
679 #endif
682 /* Write a string to STREAM. */
683 extern int fputs (__const char *__restrict __s, FILE *__restrict __stream)
684 __THROW;
686 #ifdef __USE_GNU
687 /* This function does the same as `fputs' but does not lock the stream. */
688 extern int fputs_unlocked (__const char *__restrict __s,
689 FILE *__restrict __stream) __THROW;
690 #endif
692 /* Write a string, followed by a newline, to stdout. */
693 extern int puts (__const char *__s) __THROW;
696 /* Push a character back onto the input buffer of STREAM. */
697 extern int ungetc (int __c, FILE *__stream) __THROW;
700 /* Read chunks of generic data from STREAM. */
701 extern size_t fread (void *__restrict __ptr, size_t __size,
702 size_t __n, FILE *__restrict __stream) __THROW;
703 /* Write chunks of generic data to STREAM. */
704 extern size_t fwrite (__const void *__restrict __ptr, size_t __size,
705 size_t __n, FILE *__restrict __s) __THROW;
707 #ifdef __USE_MISC
708 /* Faster versions when locking is not necessary. */
709 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
710 size_t __n, FILE *__restrict __stream) __THROW;
711 extern size_t fwrite_unlocked (__const void *__restrict __ptr,
712 size_t __size, size_t __n,
713 FILE *__restrict __stream) __THROW;
714 #endif
717 /* Seek to a certain position on STREAM. */
718 extern int fseek (FILE *__stream, long int __off, int __whence) __THROW;
719 /* Return the current position of STREAM. */
720 extern long int ftell (FILE *__stream) __THROW;
721 /* Rewind to the beginning of STREAM. */
722 extern void rewind (FILE *__stream) __THROW;
724 /* Get STREAM's position. */
725 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos)
726 __THROW;
727 /* Set STREAM's position. */
728 extern int fsetpos (FILE *__stream, __const fpos_t *__pos) __THROW;
731 /* Clear the error and EOF indicators for STREAM. */
732 extern void clearerr (FILE *__stream) __THROW;
733 /* Return the EOF indicator for STREAM. */
734 extern int feof (FILE *__stream) __THROW;
735 /* Return the error indicator for STREAM. */
736 extern int ferror (FILE *__stream) __THROW;
738 #ifdef __OPTIMIZE__
739 #define feof(stream) ((stream)->__eof != 0)
740 #define ferror(stream) ((stream)->__error != 0)
741 #endif /* Optimizing. */
743 #ifdef __USE_MISC
744 /* Faster versions when locking is not required. */
745 extern void clearerr_unlocked (FILE *__stream) __THROW;
746 extern int feof_unlocked (FILE *__stream) __THROW;
747 extern int ferror_unlocked (FILE *__stream) __THROW;
749 # ifdef __OPTIMIZE__
750 # define feof_unlocked(stream) ((stream)->__eof != 0)
751 # define ferror_unlocked(stream) ((stream)->__error != 0)
752 # endif /* Optimizing. */
753 #endif
755 /* Print a message describing the meaning of the value of errno. */
756 extern void perror (__const char *__s) __THROW;
759 #ifdef __USE_POSIX
760 /* Return the system file descriptor for STREAM. */
761 extern int fileno (FILE *__stream) __THROW;
762 #endif /* Use POSIX. */
764 #ifdef __USE_MISC
765 /* Faster version when locking is not required. */
766 extern int fileno_unlocked (FILE *__stream) __THROW;
767 #endif
770 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
771 defined __USE_MISC)
772 /* Create a new stream connected to a pipe running the given command. */
773 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
775 /* Close a stream opened by popen and return the status of its child. */
776 extern int pclose (FILE *__stream) __THROW;
777 #endif
780 #ifdef __USE_POSIX
781 /* Return the name of the controlling terminal. */
782 extern char *ctermid (char *__s) __THROW;
783 #endif
786 #ifdef __USE_XOPEN
787 /* Return the name of the current user. */
788 extern char *cuserid (char *__s) __THROW;
789 #endif
792 #ifdef __USE_GNU
793 struct obstack; /* See <obstack.h>. */
795 /* Open a stream that writes to OBSTACK. */
796 extern FILE *open_obstack_stream (struct obstack *__obstack) __THROW;
798 /* Write formatted output to an obstack. */
799 extern int obstack_printf (struct obstack *__obstack,
800 __const char *__format, ...) __THROW;
801 extern int obstack_vprintf (struct obstack *__obstack, __const char *__format,
802 __gnuc_va_list __args) __THROW;
803 #endif
806 #if defined __USE_POSIX || defined __USE_MISC
807 /* These are defined in POSIX.1:1996. */
809 /* Acquire ownership of STREAM. */
810 extern void flockfile (FILE *__stream) __THROW;
812 /* Try to acquire ownership of STREAM but do not block if it is not
813 possible. */
814 extern int ftrylockfile (FILE *__stream) __THROW;
816 /* Relinquish the ownership granted for STREAM. */
817 extern void funlockfile (FILE *__stream) __THROW;
818 #endif /* POSIX || misc */
820 #if defined __USE_XOPEN && !defined __USE_GNU
821 /* The X/Open standard requires some functions and variables to be
822 declared here which do not belong into this header. But we have to
823 follow. In GNU mode we don't do this nonsense. */
824 # define __need_getopt
825 # include <getopt.h>
826 #endif
828 __END_DECLS
830 #endif /* <stdio.h> included. */
832 #endif /* stdio.h */