Update.
[glibc.git] / stdio / stdio.h
blob7594f138406f49c22be7869fb7d0b516a2111c94
1 /* Copyright (C) 1991,92,93,94,95,96,97,98 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 __P ((__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 __P ((__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 __P ((__ptr_t __cookie, fpos_t *__pos, int __w));
97 /* Close COOKIE. */
98 typedef int __io_close_fn __P ((__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 __P ((__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) __P ((FILE *__stream));
143 /* Make room in the output buffer. */
144 void (*__output) __P ((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 __P ((__const char *__file, __io_mode __m,
155 __ptr_t *__cookieptr));
156 /* Put out an error message for when stdio needs to die. */
157 extern void __stdio_errmsg __P ((__const char *__msg, size_t __len));
158 /* Generate a unique file name (and possibly open it with mode "w+b"). */
159 extern char *__stdio_gen_tempname __P ((char *__buf, size_t __bufsize,
160 __const char *__dir,
161 __const char *__pfx,
162 int __dir_search,
163 size_t *__lenptr,
164 FILE **__streamptr,
165 int __large_file));
168 /* Print out MESSAGE on the error output and abort. */
169 extern void __libc_fatal __P ((__const char *__message))
170 __attribute__ ((__noreturn__));
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 __P ((FILE *__stream));
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 __P ((FILE *__stream));
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 __P ((__const char *__filename));
295 /* Rename file OLD to NEW. */
296 extern int rename __P ((__const char *__old, __const char *__new));
299 /* Create a temporary file and open it read/write. */
300 extern FILE *tmpfile __P ((void));
301 #ifdef __USE_LARGEFILE64
302 extern FILE *tmpfile64 __P ((void));
303 #endif
304 /* Generate a temporary filename. */
305 extern char *tmpnam __P ((char *__s));
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 __P ((char *__s));
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 __P ((__const char *__dir, __const char *__pfx));
323 #endif
326 /* This performs actual output when necessary, flushing
327 STREAM's buffer and optionally writing another character. */
328 extern int __flshfp __P ((FILE *__stream, int __c));
331 /* Close STREAM. */
332 extern int fclose __P ((FILE *__stream));
333 /* Flush STREAM, or all streams if STREAM is NULL. */
334 extern int fflush __P ((FILE *__stream));
336 #ifdef __USE_MISC
337 /* Faster versions when locking is not required. */
338 extern int fflush_unlocked __P ((FILE *__stream));
339 #endif
341 #ifdef __USE_GNU
342 /* Close all streams. */
343 extern int __fcloseall __P ((void));
344 extern int fcloseall __P ((void));
345 #endif
348 /* Open a file and create a new stream for it. */
349 extern FILE *fopen __P ((__const char *__filename, __const char *__modes));
350 /* Open a file, replacing an existing stream with it. */
351 extern FILE *freopen __P ((__const char *__restrict __filename,
352 __const char *__restrict __modes,
353 FILE *__restrict __stream));
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 __P ((void));
366 #ifdef __USE_POSIX
367 /* Create a new stream that refers to an existing system file descriptor. */
368 extern FILE *fdopen __P ((int __fd, __const char *__modes));
369 #endif
371 #ifdef __USE_GNU
372 /* Create a new stream that refers to the given magic cookie,
373 and uses the given functions for input and output. */
374 extern FILE *fopencookie __P ((__ptr_t __magic_cookie, __const char *__modes,
375 __io_functions __io_funcs));
377 /* Create a new stream that refers to a memory buffer. */
378 extern FILE *fmemopen __P ((__ptr_t __s, size_t __len, __const char *__modes));
380 /* Open a stream that writes into a malloc'd buffer that is expanded as
381 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
382 and the number of characters written on fflush or fclose. */
383 extern FILE *open_memstream __P ((char **__bufloc, size_t *__sizeloc));
384 #endif
387 /* If BUF is NULL, make STREAM unbuffered.
388 Else make it use buffer BUF, of size BUFSIZ. */
389 extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
390 /* Make STREAM use buffering mode MODE.
391 If BUF is not NULL, use N bytes of it for buffering;
392 else allocate an internal buffer N bytes long. */
393 extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
394 int __modes, size_t __n));
396 #ifdef __USE_BSD
397 /* If BUF is NULL, make STREAM unbuffered.
398 Else make it use SIZE bytes of BUF for buffering. */
399 extern void setbuffer __P ((FILE *__stream, char *__buf, size_t __size));
401 /* Make STREAM line-buffered. */
402 extern void setlinebuf __P ((FILE *__stream));
403 #endif
406 /* Write formatted output to STREAM. */
407 extern int fprintf __P ((FILE *__restrict __stream,
408 __const char *__restrict __format, ...));
409 /* Write formatted output to stdout. */
410 extern int printf __P ((__const char *__restrict __format, ...));
411 /* Write formatted output to S. */
412 extern int sprintf __P ((char *__restrict __s,
413 __const char *__restrict __format, ...));
415 /* Write formatted output to S from argument list ARG. */
416 extern int vfprintf __P ((FILE *__restrict __s,
417 __const char *__restrict __format,
418 __gnuc_va_list __arg));
419 /* Write formatted output to stdout from argument list ARG. */
420 extern int vprintf __P ((__const char *__restrict __format,
421 __gnuc_va_list __arg));
422 /* Write formatted output to S from argument list ARG. */
423 extern int vsprintf __P ((char *__restrict __s,
424 __const char *__restrict __format,
425 __gnuc_va_list __arg));
427 #ifdef __OPTIMIZE__
428 extern __inline int
429 vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
431 return vfprintf (stdout, __fmt, __arg);
433 #endif /* Optimizing. */
435 #if defined __USE_BSD || defined __USE_ISOC9X
436 /* Maximum chars of output to write in MAXLEN. */
437 extern int __snprintf __P ((char *__s, size_t __maxlen,
438 __const char *__format, ...))
439 __attribute__ ((__format__ (__printf__, 3, 4)));
440 extern int snprintf __P ((char *__s, size_t __maxlen,
441 __const char *__format, ...))
442 __attribute__ ((__format__ (__printf__, 3, 4)));
444 extern int __vsnprintf __P ((char *__s, size_t __maxlen,
445 __const char *__format, __gnuc_va_list __arg))
446 __attribute__ ((__format__ (__printf__, 3, 0)));
447 extern int vsnprintf __P ((char *__s, size_t __maxlen,
448 __const char *__format, __gnuc_va_list __arg))
449 __attribute__ ((__format__ (__printf__, 3, 0)));
450 #endif
452 #ifdef __USE_GNU
453 /* Write formatted output to a string dynamically allocated with `malloc'.
454 Store the address of the string in *PTR. */
455 extern int vasprintf __P ((char **__restrict __ptr,
456 __const char *__restrict __f, __gnuc_va_list __arg))
457 __attribute__ ((__format__ (__printf__, 2, 0)));
458 extern int __asprintf __P ((char **__restrict __ptr,
459 __const char *__restrict __fmt, ...))
460 __attribute__ ((__format__ (__printf__, 2, 3)));
461 extern int asprintf __P ((char **__restrict __ptr,
462 __const char *__restrict __fmt, ...))
463 __attribute__ ((__format__ (__printf__, 2, 3)));
465 /* Write formatted output to a file descriptor. */
466 extern int vdprintf __P ((int __fd, __const char *__restrict __fmt,
467 __gnuc_va_list __arg))
468 __attribute__ ((__format__ (__printf__, 2, 0)));
469 extern int dprintf __P ((int __fd, __const char *__restrict __fmt, ...))
470 __attribute__ ((__format__ (__printf__, 2, 3)));
471 #endif
474 /* Read formatted input from STREAM. */
475 extern int fscanf __P ((FILE *__restrict __stream,
476 __const char *__restrict __format, ...));
477 /* Read formatted input from stdin. */
478 extern int scanf __P ((__const char *__restrict __format, ...));
479 /* Read formatted input from S. */
480 extern int sscanf __P ((__const char *__restrict __s,
481 __const char *__restrict __format, ...));
483 #ifdef __USE_GNU
484 /* Read formatted input from S into argument list ARG. */
485 extern int __vfscanf __P ((FILE *__s, __const char *__format,
486 __gnuc_va_list __arg));
487 extern int vfscanf __P ((FILE *__s, __const char *__format,
488 __gnuc_va_list __arg));
490 /* Read formatted input from stdin into argument list ARG. */
491 extern int __vscanf __P ((__const char *__format, __gnuc_va_list __arg));
492 extern int vscanf __P ((__const char *__format, __gnuc_va_list __arg));
494 /* Read formatted input from S into argument list ARG. */
495 extern int __vsscanf __P ((__const char *__s, __const char *__format,
496 __gnuc_va_list __arg));
497 extern int vsscanf __P ((__const char *__s, __const char *__format,
498 __gnuc_va_list __arg));
501 #ifdef __OPTIMIZE__
502 extern __inline int
503 vfscanf (FILE *__s, const char *__fmt, __gnuc_va_list __arg)
505 return __vfscanf (__s, __fmt, __arg);
507 extern __inline int
508 vscanf (const char *__fmt, __gnuc_va_list __arg)
510 return __vfscanf (stdin, __fmt, __arg);
512 extern __inline int
513 vsscanf (const char *__s, const char *__fmt, __gnuc_va_list __arg)
515 return __vsscanf (__s, __fmt, __arg);
517 #endif /* Optimizing. */
518 #endif /* Use GNU. */
521 /* This does actual reading when necessary, filling STREAM's
522 buffer and returning the first character in it. */
523 extern int __fillbf __P ((FILE *__stream));
526 /* Read a character from STREAM. */
527 extern int fgetc __P ((FILE *__stream));
528 extern int getc __P ((FILE *__stream));
530 /* Read a character from stdin. */
531 extern int getchar __P ((void));
533 /* The C standard explicitly says this can
534 re-evaluate its argument, so it does. */
535 #define __getc(stream) \
536 ((stream)->__bufp < (stream)->__get_limit ? \
537 (int) ((unsigned char) *(stream)->__bufp++) : __fillbf(stream))
539 /* The C standard explicitly says this is a macro,
540 so we always do the optimization for it. */
541 #define getc(stream) __getc(stream)
543 #ifdef __OPTIMIZE__
544 extern __inline int
545 getchar (void)
547 return __getc (stdin);
549 #endif /* Optimizing. */
551 #if defined __USE_POSIX || defined __USE_MISC
552 /* These are defined in POSIX.1:1996. */
553 extern int getc_unlocked __P ((FILE *__stream));
554 extern int getchar_unlocked __P ((void));
556 # ifdef __OPTIMIZE__
557 extern __inline int
558 getc_unlocked (FILE *__stream)
560 return __getc (__stream);
563 extern __inline int
564 getchar_unlocked (void)
566 return __getc (stdin);
568 # endif /* Optimizing. */
569 #endif /* Use POSIX or MISC. */
572 /* Write a character to STREAM. */
573 extern int fputc __P ((int __c, FILE *__stream));
574 extern int putc __P ((int __c, FILE *__stream));
576 /* Write a character to stdout. */
577 extern int putchar __P ((int __c));
580 /* The C standard explicitly says this can
581 re-evaluate its arguments, so it does. */
582 #define __putc(c, stream) \
583 ((stream)->__bufp < (stream)->__put_limit ? \
584 (int) (unsigned char) (*(stream)->__bufp++ = (unsigned char) (c)) : \
585 __flshfp ((stream), (unsigned char) (c)))
587 /* The C standard explicitly says this can be a macro,
588 so we always do the optimization for it. */
589 #define putc(c, stream) __putc ((c), (stream))
591 #ifdef __OPTIMIZE__
592 extern __inline int
593 putchar (int __c)
595 return __putc (__c, stdout);
597 #endif
599 #ifdef __USE_MISC
600 /* Faster version when locking is not necessary. */
601 extern int fputc_unlocked __P ((int __c, FILE *__stream));
603 # ifdef __OPTIMIZE__
604 extern __inline int
605 fputc_unlocked (int __c, FILE *__stream)
607 return __putc (__c, __stream);
609 # endif /* Optimizing. */
610 #endif /* Use MISC. */
612 #if defined __USE_POSIX || defined __USE_MISC
613 /* These are defined in POSIX.1:1996. */
614 extern int putc_unlocked __P ((int __c, FILE *__stream));
615 extern int putchar_unlocked __P ((int __c));
617 # ifdef __OPTIMIZE__
618 extern __inline int
619 putc_unlocked (int __c, FILE *__stream)
621 return __putc (__c, __stream);
624 extern __inline int
625 putchar_unlocked (int __c)
627 return __putc (__c, stdout);
629 # endif /* Optimizing. */
630 #endif /* Use POSIX or MISC. */
633 #if defined __USE_SVID || defined __USE_MISC
634 /* Get a word (int) from STREAM. */
635 extern int getw __P ((FILE *__stream));
637 /* Write a word (int) to STREAM. */
638 extern int putw __P ((int __w, FILE *__stream));
639 #endif
642 /* Get a newline-terminated string of finite length from STREAM. */
643 extern char *fgets __P ((char *__restrict __s, int __n,
644 FILE *__restrict __stream));
646 #ifdef __USE_GNU
647 /* This function does the same as `fgets' but does not lock the stream. */
648 extern char *fgets_unlocked __P ((char *__restrict __s, int __n,
649 FILE *__restrict __stream));
650 #endif
652 /* Get a newline-terminated string from stdin, removing the newline.
653 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
654 extern char *gets __P ((char *__s));
657 #ifdef __USE_GNU
658 #include <sys/types.h>
660 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
661 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
662 NULL), pointing to *N characters of space. It is realloc'd as
663 necessary. Returns the number of characters read (not including the
664 null terminator), or -1 on error or EOF. */
665 ssize_t __getdelim __P ((char **__lineptr, size_t *__n,
666 int __delimiter, FILE *__stream));
667 ssize_t getdelim __P ((char **__lineptr, size_t *__n,
668 int __delimiter, FILE *__stream));
670 /* Like `getdelim', but reads up to a newline. */
671 ssize_t __getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
672 ssize_t getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
674 #ifdef __OPTIMIZE__
675 extern __inline ssize_t
676 getline (char **__lineptr, size_t *__n, FILE *__stream)
678 return __getdelim (__lineptr, __n, '\n', __stream);
680 #endif /* Optimizing. */
681 #endif
684 /* Write a string to STREAM. */
685 extern int fputs __P ((__const char *__restrict __s,
686 FILE *__restrict __stream));
688 #ifdef __USE_GNU
689 /* This function does the same as `fputs' but does not lock the stream. */
690 extern int fputs_unlocked __P ((__const char *__restrict __s,
691 FILE *__restrict __stream));
692 #endif
694 /* Write a string, followed by a newline, to stdout. */
695 extern int puts __P ((__const char *__s));
698 /* Push a character back onto the input buffer of STREAM. */
699 extern int ungetc __P ((int __c, FILE *__stream));
702 /* Read chunks of generic data from STREAM. */
703 extern size_t fread __P ((__ptr_t __restrict __ptr, size_t __size,
704 size_t __n, FILE *__restrict __stream));
705 /* Write chunks of generic data to STREAM. */
706 extern size_t fwrite __P ((__const __ptr_t __restrict __ptr, size_t __size,
707 size_t __n, FILE *__restrict __s));
709 #ifdef __USE_MISC
710 /* Faster versions when locking is not necessary. */
711 extern size_t fread_unlocked __P ((void *__restrict __ptr, size_t __size,
712 size_t __n, FILE *__restrict __stream));
713 extern size_t fwrite_unlocked __P ((__const void *__restrict __ptr,
714 size_t __size, size_t __n,
715 FILE *__restrict __stream));
716 #endif
719 /* Seek to a certain position on STREAM. */
720 extern int fseek __P ((FILE *__stream, long int __off, int __whence));
721 /* Return the current position of STREAM. */
722 extern long int ftell __P ((FILE *__stream));
723 /* Rewind to the beginning of STREAM. */
724 extern void rewind __P ((FILE *__stream));
726 /* Get STREAM's position. */
727 extern int fgetpos __P ((FILE *__restrict __stream, fpos_t *__restrict __pos));
728 /* Set STREAM's position. */
729 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
732 /* Clear the error and EOF indicators for STREAM. */
733 extern void clearerr __P ((FILE *__stream));
734 /* Return the EOF indicator for STREAM. */
735 extern int feof __P ((FILE *__stream));
736 /* Return the error indicator for STREAM. */
737 extern int ferror __P ((FILE *__stream));
739 #ifdef __OPTIMIZE__
740 #define feof(stream) ((stream)->__eof != 0)
741 #define ferror(stream) ((stream)->__error != 0)
742 #endif /* Optimizing. */
744 #ifdef __USE_MISC
745 /* Faster versions when locking is not required. */
746 extern void clearerr_unlocked __P ((FILE *__stream));
747 extern int feof_unlocked __P ((FILE *__stream));
748 extern int ferror_unlocked __P ((FILE *__stream));
750 # ifdef __OPTIMIZE__
751 # define feof_unlocked(stream) ((stream)->__eof != 0)
752 # define ferror_unlocked(stream) ((stream)->__error != 0)
753 # endif /* Optimizing. */
754 #endif
756 /* Print a message describing the meaning of the value of errno. */
757 extern void perror __P ((__const char *__s));
759 #ifdef __USE_BSD
760 extern int sys_nerr;
761 extern const char *const sys_errlist[];
762 #endif
763 #ifdef __USE_GNU
764 extern int _sys_nerr;
765 extern const char *const _sys_errlist[];
766 #endif
769 #ifdef __USE_POSIX
770 /* Return the system file descriptor for STREAM. */
771 extern int fileno __P ((FILE *__stream));
772 #endif /* Use POSIX. */
774 #ifdef __USE_MISC
775 /* Faster version when locking is not required. */
776 extern int fileno_unlocked __P ((FILE *__stream));
777 #endif
780 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
781 defined __USE_MISC)
782 /* Create a new stream connected to a pipe running the given command. */
783 extern FILE *popen __P ((__const char *__command, __const char *__modes));
785 /* Close a stream opened by popen and return the status of its child. */
786 extern int pclose __P ((FILE *__stream));
787 #endif
790 #ifdef __USE_POSIX
791 /* Return the name of the controlling terminal. */
792 extern char *ctermid __P ((char *__s));
793 #endif
796 #ifdef __USE_XOPEN
797 /* Return the name of the current user. */
798 extern char *cuserid __P ((char *__s));
799 #endif
802 #ifdef __USE_GNU
803 struct obstack; /* See <obstack.h>. */
805 /* Open a stream that writes to OBSTACK. */
806 extern FILE *open_obstack_stream __P ((struct obstack *__obstack));
808 /* Write formatted output to an obstack. */
809 extern int obstack_printf __P ((struct obstack *__obstack,
810 __const char *__format, ...));
811 extern int obstack_vprintf __P ((struct obstack *__obstack,
812 __const char *__format,
813 __gnuc_va_list __args));
814 #endif
817 #if defined __USE_POSIX || defined __USE_MISC
818 /* These are defined in POSIX.1:1996. */
820 /* Acquire ownership of STREAM. */
821 extern void flockfile __P ((FILE *__stream));
823 /* Try to acquire ownership of STREAM but do not block if it is not
824 possible. */
825 extern int ftrylockfile __P ((FILE *__stream));
827 /* Relinquish the ownership granted for STREAM. */
828 extern void funlockfile __P ((FILE *__stream));
829 #endif /* POSIX || misc */
831 #if defined __USE_XOPEN && !defined __USE_GNU
832 /* The X/Open standard requires some functions and variables to be
833 declared here which do not belong into this header. But we have to
834 follow. In GNU mode we don't do this nonsense. */
836 /* For more information on these symbols look in <getopt.h>. */
837 extern char *optarg;
838 extern int optind;
839 extern int opterr;
840 extern int optopt;
842 extern int getopt __P ((int __argc, char *__const *__argv,
843 __const char *__shortopts));
844 #endif
846 __END_DECLS
848 #endif /* <stdio.h> included. */
850 #endif /* stdio.h */