Update.
[platform/upstream/glibc.git] / stdio / stdio.h
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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.  */
18
19 /*
20  *      ISO C Standard: 4.9 INPUT/OUTPUT        <stdio.h>
21  */
22
23 #ifndef _STDIO_H
24
25 #if     !defined(__need_FILE)
26 #define _STDIO_H        1
27 #include <features.h>
28
29 __BEGIN_DECLS
30
31 #define __need_size_t
32 #define __need_NULL
33 #include <stddef.h>
34
35 #define __need___va_list
36 #include <stdarg.h>
37 #ifndef __GNUC_VA_LIST
38 #define __gnuc_va_list  __ptr_t
39 #endif
40
41 #include <bits/types.h>
42 #endif /* Don't need FILE.  */
43 #undef  __need_FILE
44
45
46 #ifndef __FILE_defined
47
48 /* The opaque type of streams.  */
49 typedef struct __stdio_file FILE;
50
51 #define __FILE_defined  1
52 #endif /* FILE not defined.  */
53
54
55 #ifdef  _STDIO_H
56
57 /* The type of the second argument to `fgetpos' and `fsetpos'.  */
58 typedef __off_t fpos_t;
59
60 /* The mode of I/O, as given in the MODE argument to fopen, etc.  */
61 typedef struct
62 {
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;
71
72
73 /* Functions to do I/O and file management for a stream.  */
74
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));
79
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));
88
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));
96
97 /* Close COOKIE.  */
98 typedef int __io_close_fn __P ((__ptr_t __cookie));
99
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));
103
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
112
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
117 {
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
129 {
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
137
138 /* Higher level interface, dependent on FILE representation.  */
139 typedef struct
140 {
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;
146
147 extern __const __io_functions __default_io_functions;
148 extern __const __room_functions __default_room_functions;
149
150
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));
166
167
168 /* Print out MESSAGE on the error output and abort.  */
169 extern void __libc_fatal __P ((__const char *__message))
170      __attribute__ ((__noreturn__));
171
172
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;
176
177 /* The FILE structure.  */
178 struct __stdio_file
179 {
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.  */
186
187   char *__bufp;                 /* Pointer into the buffer.  */
188   char *__get_limit;            /* Reading limit.  */
189   char *__put_limit;            /* Writing limit.  */
190
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.  */
211 };
212
213
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.  */
216
217
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; }))
226
227 /* Clear the error and EOF indicators of STREAM.  */
228 #define __clearerr(stream)      ((stream)->__error = (stream)->__eof = 0)
229
230 /* Nuke STREAM, making it unusable but available for reuse.  */
231 extern void __invalidate __P ((FILE *__stream));
232
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));
237
238
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.  */
243
244
245 /* Default buffer size.  */
246 #define BUFSIZ  1024
247
248
249 /* End of file character.
250    Some things throughout the library rely on this being -1.  */
251 #define EOF     (-1)
252
253
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.  */
259
260
261 #ifdef  __USE_SVID
262 /* Default path prefix for `tempnam' and `tmpnam'.  */
263 #define P_tmpdir        "/usr/tmp"
264 #endif
265
266
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>
277
278
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.  */
282
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
291
292
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));
297
298
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));
306
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
312
313
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
324
325
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));
329
330
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));
335
336 #ifdef __USE_GNU
337 /* Close all streams.  */
338 extern int __fcloseall __P ((void));
339 extern int fcloseall __P ((void));
340 #endif
341
342
343 /* Open a file and create a new stream for it.  */
344 extern FILE *fopen __P ((__const char *__filename, __const char *__modes));
345 /* Open a file, replacing an existing stream with it. */
346 extern FILE *freopen __P ((__const char *__restrict __filename,
347                            __const char *__restrict __modes,
348                            FILE *__restrict __stream));
349
350 /* Return a new, zeroed, stream.
351    You must set its cookie and io_mode.
352    The first operation will give it a buffer unless you do.
353    It will also give it the default functions unless you set the `seen' flag.
354    The offset is set to -1, meaning it will be determined by doing a
355    stationary seek.  You can set it to avoid the initial tell call.
356    The target is set to -1, meaning it will be set to the offset
357    before the target is needed.
358    Returns NULL if a stream can't be created.  */
359 extern FILE *__newstream __P ((void));
360
361 #ifdef  __USE_POSIX
362 /* Create a new stream that refers to an existing system file descriptor.  */
363 extern FILE *fdopen __P ((int __fd, __const char *__modes));
364 #endif
365
366 #ifdef  __USE_GNU
367 /* Create a new stream that refers to the given magic cookie,
368    and uses the given functions for input and output.  */
369 extern FILE *fopencookie __P ((__ptr_t __magic_cookie, __const char *__modes,
370                                __io_functions __io_funcs));
371
372 /* Create a new stream that refers to a memory buffer.  */
373 extern FILE *fmemopen __P ((__ptr_t __s, size_t __len, __const char *__modes));
374
375 /* Open a stream that writes into a malloc'd buffer that is expanded as
376    necessary.  *BUFLOC and *SIZELOC are updated with the buffer's location
377    and the number of characters written on fflush or fclose.  */
378 extern FILE *open_memstream __P ((char **__bufloc, size_t *__sizeloc));
379 #endif
380
381
382 /* If BUF is NULL, make STREAM unbuffered.
383    Else make it use buffer BUF, of size BUFSIZ.  */
384 extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
385 /* Make STREAM use buffering mode MODE.
386    If BUF is not NULL, use N bytes of it for buffering;
387    else allocate an internal buffer N bytes long.  */
388 extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
389                          int __modes, size_t __n));
390
391 #ifdef  __USE_BSD
392 /* If BUF is NULL, make STREAM unbuffered.
393    Else make it use SIZE bytes of BUF for buffering.  */
394 extern void setbuffer __P ((FILE *__stream, char *__buf, size_t __size));
395
396 /* Make STREAM line-buffered.  */
397 extern void setlinebuf __P ((FILE *__stream));
398 #endif
399
400
401 /* Write formatted output to STREAM.  */
402 extern int fprintf __P ((FILE *__restrict __stream,
403                          __const char *__restrict __format, ...));
404 /* Write formatted output to stdout.  */
405 extern int printf __P ((__const char *__restrict __format, ...));
406 /* Write formatted output to S.  */
407 extern int sprintf __P ((char *__restrict __s,
408                          __const char *__restrict __format, ...));
409
410 /* Write formatted output to S from argument list ARG.  */
411 extern int vfprintf __P ((FILE *__restrict __s,
412                           __const char *__restrict __format,
413                           __gnuc_va_list __arg));
414 /* Write formatted output to stdout from argument list ARG.  */
415 extern int vprintf __P ((__const char *__restrict __format,
416                          __gnuc_va_list __arg));
417 /* Write formatted output to S from argument list ARG.  */
418 extern int vsprintf __P ((char *__restrict __s,
419                           __const char *__restrict __format,
420                           __gnuc_va_list __arg));
421
422 #ifdef  __OPTIMIZE__
423 extern __inline int
424 vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
425 {
426   return vfprintf (stdout, __fmt, __arg);
427 }
428 #endif /* Optimizing.  */
429
430 #if defined __USE_BSD || defined __USE_ISOC9X
431 /* Maximum chars of output to write in MAXLEN.  */
432 extern int __snprintf __P ((char *__s, size_t __maxlen,
433                             __const char *__format, ...))
434      __attribute__ ((__format__ (__printf__, 3, 4)));
435 extern int snprintf __P ((char *__s, size_t __maxlen,
436                           __const char *__format, ...))
437      __attribute__ ((__format__ (__printf__, 3, 4)));
438
439 extern int __vsnprintf __P ((char *__s, size_t __maxlen,
440                              __const char *__format, __gnuc_va_list __arg))
441      __attribute__ ((__format__ (__printf__, 3, 0)));
442 extern int vsnprintf __P ((char *__s, size_t __maxlen,
443                            __const char *__format, __gnuc_va_list __arg))
444      __attribute__ ((__format__ (__printf__, 3, 0)));
445 #endif
446
447 #ifdef __USE_GNU
448 /* Write formatted output to a string dynamically allocated with `malloc'.
449    Store the address of the string in *PTR.  */
450 extern int vasprintf __P ((char **__ptr, __const char *__f,
451                            __gnuc_va_list __arg))
452      __attribute__ ((__format__ (__printf__, 2, 0)));
453 extern int asprintf __P ((char **__ptr, __const char *__fmt, ...))
454      __attribute__ ((__format__ (__printf__, 2, 0)));
455
456 /* Write formatted output to a file descriptor.  */
457 extern int vdprintf __P ((int __fd, __const char *__fmt,
458                           __gnuc_va_list __arg))
459      __attribute__ ((__format__ (__printf__, 2, 0)));
460 extern int dprintf __P ((int __fd, __const char *__fmt, ...))
461      __attribute__ ((__format__ (__printf__, 2, 0)));
462 #endif
463
464
465 /* Read formatted input from STREAM.  */
466 extern int fscanf __P ((FILE *__restrict __stream,
467                         __const char *__restrict __format, ...));
468 /* Read formatted input from stdin.  */
469 extern int scanf __P ((__const char *__restrict __format, ...));
470 /* Read formatted input from S.  */
471 extern int sscanf __P ((__const char *__restrict __s,
472                         __const char *__restrict __format, ...));
473
474 #ifdef  __USE_GNU
475 /* Read formatted input from S into argument list ARG.  */
476 extern int __vfscanf __P ((FILE *__s, __const char *__format,
477                            __gnuc_va_list __arg));
478 extern int vfscanf __P ((FILE *__s, __const char *__format,
479                          __gnuc_va_list __arg));
480
481 /* Read formatted input from stdin into argument list ARG.  */
482 extern int __vscanf __P ((__const char *__format, __gnuc_va_list __arg));
483 extern int vscanf __P ((__const char *__format, __gnuc_va_list __arg));
484
485 /* Read formatted input from S into argument list ARG.  */
486 extern int __vsscanf __P ((__const char *__s, __const char *__format,
487                            __gnuc_va_list __arg));
488 extern int vsscanf __P ((__const char *__s, __const char *__format,
489                          __gnuc_va_list __arg));
490
491
492 #ifdef  __OPTIMIZE__
493 extern __inline int
494 vfscanf (FILE *__s, const char *__fmt, __gnuc_va_list __arg)
495 {
496   return __vfscanf (__s, __fmt, __arg);
497 }
498 extern __inline int
499 vscanf (const char *__fmt, __gnuc_va_list __arg)
500 {
501   return __vfscanf (stdin, __fmt, __arg);
502 }
503 extern __inline int
504 vsscanf (const char *__s, const char *__fmt, __gnuc_va_list __arg)
505 {
506   return __vsscanf (__s, __fmt, __arg);
507 }
508 #endif /* Optimizing.  */
509 #endif /* Use GNU.  */
510
511
512 /* This does actual reading when necessary, filling STREAM's
513    buffer and returning the first character in it.  */
514 extern int __fillbf __P ((FILE *__stream));
515
516
517 /* Read a character from STREAM.  */
518 extern int fgetc __P ((FILE *__stream));
519 extern int getc __P ((FILE *__stream));
520
521 /* Read a character from stdin.  */
522 extern int getchar __P ((void));
523
524 /* The C standard explicitly says this can
525    re-evaluate its argument, so it does. */
526 #define __getc(stream)                                                        \
527   ((stream)->__bufp < (stream)->__get_limit ?                                 \
528    (int) ((unsigned char) *(stream)->__bufp++) : __fillbf(stream))
529
530 /* The C standard explicitly says this is a macro,
531    so we always do the optimization for it.  */
532 #define getc(stream)    __getc(stream)
533
534 #ifdef  __OPTIMIZE__
535 extern __inline int
536 getchar (void)
537 {
538   return __getc (stdin);
539 }
540 #endif /* Optimizing.  */
541
542
543 /* Write a character to STREAM.  */
544 extern int fputc __P ((int __c, FILE *__stream));
545 extern int putc __P ((int __c, FILE *__stream));
546
547 /* Write a character to stdout.  */
548 extern int putchar __P ((int __c));
549
550
551 /* The C standard explicitly says this can
552    re-evaluate its arguments, so it does.  */
553 #define __putc(c, stream)                                                     \
554   ((stream)->__bufp < (stream)->__put_limit ?                                 \
555    (int) (unsigned char) (*(stream)->__bufp++ = (unsigned char) (c)) :        \
556    __flshfp ((stream), (unsigned char) (c)))
557
558 /* The C standard explicitly says this can be a macro,
559    so we always do the optimization for it.  */
560 #define putc(c, stream) __putc ((c), (stream))
561
562 #ifdef __OPTIMIZE__
563 extern __inline int
564 putchar (int __c)
565 {
566   return __putc (__c, stdout);
567 }
568 #endif
569
570
571 #if defined __USE_SVID || defined __USE_MISC
572 /* Get a word (int) from STREAM.  */
573 extern int getw __P ((FILE *__stream));
574
575 /* Write a word (int) to STREAM.  */
576 extern int putw __P ((int __w, FILE *__stream));
577 #endif
578
579
580 /* Get a newline-terminated string of finite length from STREAM.  */
581 extern char *fgets __P ((char *__restrict __s, int __n,
582                          FILE *__restrict __stream));
583
584 /* Get a newline-terminated string from stdin, removing the newline.
585    DO NOT USE THIS FUNCTION!!  There is no limit on how much it will read.  */
586 extern char *gets __P ((char *__s));
587
588
589 #ifdef  __USE_GNU
590 #include <sys/types.h>
591
592 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
593    (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
594    NULL), pointing to *N characters of space.  It is realloc'd as
595    necessary.  Returns the number of characters read (not including the
596    null terminator), or -1 on error or EOF.  */
597 ssize_t __getdelim __P ((char **__lineptr, size_t *__n,
598                          int __delimiter, FILE *__stream));
599 ssize_t getdelim __P ((char **__lineptr, size_t *__n,
600                        int __delimiter, FILE *__stream));
601
602 /* Like `getdelim', but reads up to a newline.  */
603 ssize_t __getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
604 ssize_t getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
605
606 #ifdef  __OPTIMIZE__
607 extern __inline ssize_t
608 getline (char **__lineptr, size_t *__n, FILE *__stream)
609 {
610   return __getdelim (__lineptr, __n, '\n', __stream);
611 }
612 #endif /* Optimizing.  */
613 #endif
614
615
616 /* Write a string to STREAM.  */
617 extern int fputs __P ((__const char *__restrict __s,
618                        FILE *__restrict __stream));
619 /* Write a string, followed by a newline, to stdout.  */
620 extern int puts __P ((__const char *__s));
621
622
623 /* Push a character back onto the input buffer of STREAM.  */
624 extern int ungetc __P ((int __c, FILE *__stream));
625
626
627 /* Read chunks of generic data from STREAM.  */
628 extern size_t fread __P ((__ptr_t __restrict __ptr, size_t __size,
629                           size_t __n, FILE *__restrict __stream));
630 /* Write chunks of generic data to STREAM.  */
631 extern size_t fwrite __P ((__const __ptr_t __restrict __ptr, size_t __size,
632                            size_t __n, FILE *__restrict __s));
633
634
635 /* Seek to a certain position on STREAM.  */
636 extern int fseek __P ((FILE *__stream, long int __off, int __whence));
637 /* Return the current position of STREAM.  */
638 extern long int ftell __P ((FILE *__stream));
639 /* Rewind to the beginning of STREAM.  */
640 extern void rewind __P ((FILE *__stream));
641
642 /* Get STREAM's position.  */
643 extern int fgetpos __P ((FILE *__restrict __stream, fpos_t *__restrict __pos));
644 /* Set STREAM's position.  */
645 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
646
647
648 /* Clear the error and EOF indicators for STREAM.  */
649 extern void clearerr __P ((FILE *__stream));
650 /* Return the EOF indicator for STREAM.  */
651 extern int feof __P ((FILE *__stream));
652 /* Return the error indicator for STREAM.  */
653 extern int ferror __P ((FILE *__stream));
654
655 #ifdef  __OPTIMIZE__
656 #define feof(stream)    ((stream)->__eof != 0)
657 #define ferror(stream)  ((stream)->__error != 0)
658 #endif /* Optimizing.  */
659
660
661 /* Print a message describing the meaning of the value of errno.  */
662 extern void perror __P ((__const char *__s));
663
664 #ifdef  __USE_BSD
665 extern int sys_nerr;
666 extern const char *const sys_errlist[];
667 #endif
668 #ifdef  __USE_GNU
669 extern int _sys_nerr;
670 extern const char *const _sys_errlist[];
671 #endif
672
673
674 #ifdef  __USE_POSIX
675 /* Return the system file descriptor for STREAM.  */
676 extern int fileno __P ((FILE *__stream));
677 #endif /* Use POSIX.  */
678
679
680 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
681      defined __USE_MISC)
682 /* Create a new stream connected to a pipe running the given command.  */
683 extern FILE *popen __P ((__const char *__command, __const char *__modes));
684
685 /* Close a stream opened by popen and return the status of its child.  */
686 extern int pclose __P ((FILE *__stream));
687 #endif
688
689
690 #ifdef  __USE_POSIX
691 /* Return the name of the controlling terminal.  */
692 extern char *ctermid __P ((char *__s));
693 #endif
694
695
696 #ifdef __USE_XOPEN
697 /* Return the name of the current user.  */
698 extern char *cuserid __P ((char *__s));
699 #endif
700
701
702 #ifdef  __USE_GNU
703 struct obstack;                 /* See <obstack.h>.  */
704
705 /* Open a stream that writes to OBSTACK.  */
706 extern FILE *open_obstack_stream __P ((struct obstack *__obstack));
707
708 /* Write formatted output to an obstack.  */
709 extern int obstack_printf __P ((struct obstack *__obstack,
710                                 __const char *__format, ...));
711 extern int obstack_vprintf __P ((struct obstack *__obstack,
712                                  __const char *__format,
713                                  __gnuc_va_list __args));
714 #endif
715
716
717 __END_DECLS
718
719 #endif /* <stdio.h> included.  */
720
721 #endif /* stdio.h  */