80132879de723572ccbf76cf6c699403a8e884f9
[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
166
167 /* Print out MESSAGE on the error output and abort.  */
168 extern void __libc_fatal __P ((__const char *__message))
169      __attribute__ ((__noreturn__));
170
171
172 /* For thread safe I/O functions we need a lock in each stream.  We
173    keep the type opaque here.  */
174 struct __stdio_lock;
175
176 /* The FILE structure.  */
177 struct __stdio_file
178 {
179   /* Magic number for validation.  Must be negative in open streams
180      for the glue to Unix stdio getc/putc to work.
181      NOTE: stdio/glue.c has special knowledge of these first four members.  */
182   int __magic;
183 #define _IOMAGIC ((int) 0xfedabeeb)     /* Magic number to fill `__magic'.  */
184 #define _GLUEMAGIC ((int) 0xfeedbabe)   /* Magic for glued Unix streams.  */
185
186   char *__bufp;                 /* Pointer into the buffer.  */
187   char *__get_limit;            /* Reading limit.  */
188   char *__put_limit;            /* Writing limit.  */
189
190   char *__buffer;               /* Base of buffer.  */
191   size_t __bufsize;             /* Size of the buffer.  */
192   __ptr_t __cookie;             /* Magic cookie.  */
193   __io_mode __mode;             /* File access mode.  */
194   __io_functions __io_funcs;    /* I/O functions.  */
195   __room_functions __room_funcs;/* I/O buffer room functions.  */
196   fpos_t __offset;              /* Current file position.  */
197   fpos_t __target;              /* Target file position.  */
198   FILE *__next;                 /* Next FILE in the linked list.  */
199   char *__pushback_bufp;        /* Old bufp if char pushed back.  */
200   unsigned char __pushback;     /* Pushed-back character.  */
201   unsigned int __pushed_back:1; /* A char has been pushed back.  */
202   unsigned int __eof:1;         /* End of file encountered.  */
203   unsigned int __error:1;       /* Error encountered.  */
204   unsigned int __userbuf:1;     /* Buffer from user (should not be freed).  */
205   unsigned int __linebuf:1;     /* Flush on newline.  */
206   unsigned int __linebuf_active:1; /* put_limit is not really in use.  */
207   unsigned int __seen:1;        /* This stream has been seen.  */
208   unsigned int __ispipe:1;      /* Nonzero if opened by popen.  */
209   struct __stdio_lock *__lock;  /* Pointer to associated lock.  */
210 };
211
212
213 /* All macros used internally by other macros here and by stdio functions begin
214    with `__'.  All of these may evaluate their arguments more than once.  */
215
216
217 /* Nonzero if STREAM is a valid stream.
218    STREAM must be a modifiable lvalue (wow, I got to use that term).
219    See stdio/glue.c for what the confusing bit is about.  */
220 #define __validfp(stream)                                                     \
221   (stream != NULL &&                                                          \
222    ({ if (stream->__magic == _GLUEMAGIC)                                      \
223         stream = *((struct { int __magic; FILE **__p; } *) stream)->__p;      \
224       stream->__magic == _IOMAGIC; }))
225
226 /* Clear the error and EOF indicators of STREAM.  */
227 #define __clearerr(stream)      ((stream)->__error = (stream)->__eof = 0)
228
229 /* Nuke STREAM, making it unusable but available for reuse.  */
230 extern void __invalidate __P ((FILE *__stream));
231
232 /* Make sure STREAM->__offset and STREAM->__target are initialized.
233    Returns 0 if successful, or EOF on
234    error (but doesn't set STREAM->__error).  */
235 extern int __stdio_check_offset __P ((FILE *__stream));
236
237
238 /* The possibilities for the third argument to `setvbuf'.  */
239 #define _IOFBF  0x1             /* Full buffering.  */
240 #define _IOLBF  0x2             /* Line buffering.  */
241 #define _IONBF  0x4             /* No buffering.  */
242
243
244 /* Default buffer size.  */
245 #define BUFSIZ  1024
246
247
248 /* End of file character.
249    Some things throughout the library rely on this being -1.  */
250 #define EOF     (-1)
251
252
253 /* The possibilities for the third argument to `fseek'.
254    These values should not be changed.  */
255 #define SEEK_SET        0       /* Seek from beginning of file.  */
256 #define SEEK_CUR        1       /* Seek from current position.  */
257 #define SEEK_END        2       /* Seek from end of file.  */
258
259
260 #ifdef  __USE_SVID
261 /* Default path prefix for `tempnam' and `tmpnam'.  */
262 #define P_tmpdir        "/usr/tmp"
263 #endif
264
265
266 /* Get the values:
267    L_tmpnam     How long an array of chars must be to be passed to `tmpnam'.
268    TMP_MAX      The minimum number of unique filenames generated by tmpnam
269                 (and tempnam when it uses tmpnam's name space),
270                 or tempnam (the two are separate).
271    L_ctermid    How long an array to pass to `ctermid'.
272    L_cuserid    How long an array to pass to `cuserid'.
273    FOPEN_MAX    Minimum number of files that can be open at once.
274    FILENAME_MAX Maximum length of a filename.  */
275 #include <bits/stdio_lim.h>
276
277
278 /* All the known streams are in a linked list
279    linked by the `next' field of the FILE structure.  */
280 extern FILE *__stdio_head;      /* Head of the list.  */
281
282 /* Standard streams.  */
283 extern FILE *stdin, *stdout, *stderr;
284 #ifdef __STRICT_ANSI__
285 /* ANSI says these are macros; satisfy pedants.  */
286 #define stdin   stdin
287 #define stdout  stdout
288 #define stderr  stderr
289 #endif
290
291
292 /* Remove file FILENAME.  */
293 extern int remove __P ((__const char *__filename));
294 /* Rename file OLD to NEW.  */
295 extern int rename __P ((__const char *__old, __const char *__new));
296
297
298 /* Create a temporary file and open it read/write.  */
299 extern FILE *tmpfile __P ((void));
300 /* Generate a temporary filename.  */
301 extern char *tmpnam __P ((char *__s));
302
303 #ifdef __USE_REENTRANT
304 /* This is the reentrant variant of `tmpnam'.  The only difference is
305    that it does not allow S to be NULL.  */
306 extern char *tmpnam_r __P ((char *__s));
307 #endif
308
309
310 #if defined __USE_SVID || defined __USE_XOPEN
311 /* Generate a unique temporary filename using up to five characters of PFX
312    if it is not NULL.  The directory to put this file in is searched for
313    as follows: First the environment variable "TMPDIR" is checked.
314    If it contains the name of a writable directory, that directory is used.
315    If not and if DIR is not NULL, that value is checked.  If that fails,
316    P_tmpdir is tried and finally "/tmp".  The storage for the filename
317    is allocated by `malloc'.  */
318 extern char *tempnam __P ((__const char *__dir, __const char *__pfx));
319 #endif
320
321
322 /* This performs actual output when necessary, flushing
323    STREAM's buffer and optionally writing another character.  */
324 extern int __flshfp __P ((FILE *__stream, int __c));
325
326
327 /* Close STREAM.  */
328 extern int fclose __P ((FILE *__stream));
329 /* Flush STREAM, or all streams if STREAM is NULL.  */
330 extern int fflush __P ((FILE *__stream));
331
332 #ifdef __USE_GNU
333 /* Close all streams.  */
334 extern int __fcloseall __P ((void));
335 extern int fcloseall __P ((void));
336 #endif
337
338
339 /* Open a file and create a new stream for it.  */
340 extern FILE *fopen __P ((__const char *__filename, __const char *__modes));
341 /* Open a file, replacing an existing stream with it. */
342 extern FILE *freopen __P ((__const char *__restrict __filename,
343                            __const char *__restrict __modes,
344                            FILE *__restrict __stream));
345
346 /* Return a new, zeroed, stream.
347    You must set its cookie and io_mode.
348    The first operation will give it a buffer unless you do.
349    It will also give it the default functions unless you set the `seen' flag.
350    The offset is set to -1, meaning it will be determined by doing a
351    stationary seek.  You can set it to avoid the initial tell call.
352    The target is set to -1, meaning it will be set to the offset
353    before the target is needed.
354    Returns NULL if a stream can't be created.  */
355 extern FILE *__newstream __P ((void));
356
357 #ifdef  __USE_POSIX
358 /* Create a new stream that refers to an existing system file descriptor.  */
359 extern FILE *fdopen __P ((int __fd, __const char *__modes));
360 #endif
361
362 #ifdef  __USE_GNU
363 /* Create a new stream that refers to the given magic cookie,
364    and uses the given functions for input and output.  */
365 extern FILE *fopencookie __P ((__ptr_t __magic_cookie, __const char *__modes,
366                                __io_functions __io_funcs));
367
368 /* Create a new stream that refers to a memory buffer.  */
369 extern FILE *fmemopen __P ((__ptr_t __s, size_t __len, __const char *__modes));
370
371 /* Open a stream that writes into a malloc'd buffer that is expanded as
372    necessary.  *BUFLOC and *SIZELOC are updated with the buffer's location
373    and the number of characters written on fflush or fclose.  */
374 extern FILE *open_memstream __P ((char **__bufloc, size_t *__sizeloc));
375 #endif
376
377
378 /* If BUF is NULL, make STREAM unbuffered.
379    Else make it use buffer BUF, of size BUFSIZ.  */
380 extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
381 /* Make STREAM use buffering mode MODE.
382    If BUF is not NULL, use N bytes of it for buffering;
383    else allocate an internal buffer N bytes long.  */
384 extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
385                          int __modes, size_t __n));
386
387 #ifdef  __USE_BSD
388 /* If BUF is NULL, make STREAM unbuffered.
389    Else make it use SIZE bytes of BUF for buffering.  */
390 extern void setbuffer __P ((FILE *__stream, char *__buf, size_t __size));
391
392 /* Make STREAM line-buffered.  */
393 extern void setlinebuf __P ((FILE *__stream));
394 #endif
395
396
397 /* Write formatted output to STREAM.  */
398 extern int fprintf __P ((FILE *__restrict __stream,
399                          __const char *__restrict __format, ...));
400 /* Write formatted output to stdout.  */
401 extern int printf __P ((__const char *__restrict __format, ...));
402 /* Write formatted output to S.  */
403 extern int sprintf __P ((char *__restrict __s,
404                          __const char *__restrict __format, ...));
405
406 /* Write formatted output to S from argument list ARG.  */
407 extern int vfprintf __P ((FILE *__restrict __s,
408                           __const char *__restrict __format,
409                           __gnuc_va_list __arg));
410 /* Write formatted output to stdout from argument list ARG.  */
411 extern int vprintf __P ((__const char *__restrict __format,
412                          __gnuc_va_list __arg));
413 /* Write formatted output to S from argument list ARG.  */
414 extern int vsprintf __P ((char *__restrict __s,
415                           __const char *__restrict __format,
416                           __gnuc_va_list __arg));
417
418 #ifdef  __OPTIMIZE__
419 extern __inline int
420 vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
421 {
422   return vfprintf (stdout, __fmt, __arg);
423 }
424 #endif /* Optimizing.  */
425
426 #if defined __USE_BSD || defined __USE_ISOC9X
427 /* Maximum chars of output to write in MAXLEN.  */
428 extern int __snprintf __P ((char *__s, size_t __maxlen,
429                             __const char *__format, ...))
430      __attribute__ ((__format__ (__printf__, 3, 4)));
431 extern int snprintf __P ((char *__s, size_t __maxlen,
432                           __const char *__format, ...))
433      __attribute__ ((__format__ (__printf__, 3, 4)));
434
435 extern int __vsnprintf __P ((char *__s, size_t __maxlen,
436                              __const char *__format, __gnuc_va_list __arg))
437      __attribute__ ((__format__ (__printf__, 3, 0)));
438 extern int vsnprintf __P ((char *__s, size_t __maxlen,
439                            __const char *__format, __gnuc_va_list __arg))
440      __attribute__ ((__format__ (__printf__, 3, 0)));
441 #endif
442
443 #ifdef __USE_GNU
444 /* Write formatted output to a string dynamically allocated with `malloc'.
445    Store the address of the string in *PTR.  */
446 extern int vasprintf __P ((char **__ptr, __const char *__f,
447                            __gnuc_va_list __arg))
448      __attribute__ ((__format__ (__printf__, 2, 0)));
449 extern int asprintf __P ((char **__ptr, __const char *__fmt, ...))
450      __attribute__ ((__format__ (__printf__, 2, 0)));
451
452 /* Write formatted output to a file descriptor.  */
453 extern int vdprintf __P ((int __fd, __const char *__fmt,
454                           __gnuc_va_list __arg))
455      __attribute__ ((__format__ (__printf__, 2, 0)));
456 extern int dprintf __P ((int __fd, __const char *__fmt, ...))
457      __attribute__ ((__format__ (__printf__, 2, 0)));
458 #endif
459
460
461 /* Read formatted input from STREAM.  */
462 extern int fscanf __P ((FILE *__restrict __stream,
463                         __const char *__restrict __format, ...));
464 /* Read formatted input from stdin.  */
465 extern int scanf __P ((__const char *__restrict __format, ...));
466 /* Read formatted input from S.  */
467 extern int sscanf __P ((__const char *__restrict __s,
468                         __const char *__restrict __format, ...));
469
470 #ifdef  __USE_GNU
471 /* Read formatted input from S into argument list ARG.  */
472 extern int __vfscanf __P ((FILE *__s, __const char *__format,
473                            __gnuc_va_list __arg));
474 extern int vfscanf __P ((FILE *__s, __const char *__format,
475                          __gnuc_va_list __arg));
476
477 /* Read formatted input from stdin into argument list ARG.  */
478 extern int __vscanf __P ((__const char *__format, __gnuc_va_list __arg));
479 extern int vscanf __P ((__const char *__format, __gnuc_va_list __arg));
480
481 /* Read formatted input from S into argument list ARG.  */
482 extern int __vsscanf __P ((__const char *__s, __const char *__format,
483                            __gnuc_va_list __arg));
484 extern int vsscanf __P ((__const char *__s, __const char *__format,
485                          __gnuc_va_list __arg));
486
487
488 #ifdef  __OPTIMIZE__
489 extern __inline int
490 vfscanf (FILE *__s, const char *__fmt, __gnuc_va_list __arg)
491 {
492   return __vfscanf (__s, __fmt, __arg);
493 }
494 extern __inline int
495 vscanf (const char *__fmt, __gnuc_va_list __arg)
496 {
497   return __vfscanf (stdin, __fmt, __arg);
498 }
499 extern __inline int
500 vsscanf (const char *__s, const char *__fmt, __gnuc_va_list __arg)
501 {
502   return __vsscanf (__s, __fmt, __arg);
503 }
504 #endif /* Optimizing.  */
505 #endif /* Use GNU.  */
506
507
508 /* This does actual reading when necessary, filling STREAM's
509    buffer and returning the first character in it.  */
510 extern int __fillbf __P ((FILE *__stream));
511
512
513 /* Read a character from STREAM.  */
514 extern int fgetc __P ((FILE *__stream));
515 extern int getc __P ((FILE *__stream));
516
517 /* Read a character from stdin.  */
518 extern int getchar __P ((void));
519
520 /* The C standard explicitly says this can
521    re-evaluate its argument, so it does. */
522 #define __getc(stream)                                                        \
523   ((stream)->__bufp < (stream)->__get_limit ?                                 \
524    (int) ((unsigned char) *(stream)->__bufp++) : __fillbf(stream))
525
526 /* The C standard explicitly says this is a macro,
527    so we always do the optimization for it.  */
528 #define getc(stream)    __getc(stream)
529
530 #ifdef  __OPTIMIZE__
531 extern __inline int
532 getchar (void)
533 {
534   return __getc (stdin);
535 }
536 #endif /* Optimizing.  */
537
538
539 /* Write a character to STREAM.  */
540 extern int fputc __P ((int __c, FILE *__stream));
541 extern int putc __P ((int __c, FILE *__stream));
542
543 /* Write a character to stdout.  */
544 extern int putchar __P ((int __c));
545
546
547 /* The C standard explicitly says this can
548    re-evaluate its arguments, so it does.  */
549 #define __putc(c, stream)                                                     \
550   ((stream)->__bufp < (stream)->__put_limit ?                                 \
551    (int) (unsigned char) (*(stream)->__bufp++ = (unsigned char) (c)) :        \
552    __flshfp ((stream), (unsigned char) (c)))
553
554 /* The C standard explicitly says this can be a macro,
555    so we always do the optimization for it.  */
556 #define putc(c, stream) __putc ((c), (stream))
557
558 #ifdef __OPTIMIZE__
559 extern __inline int
560 putchar (int __c)
561 {
562   return __putc (__c, stdout);
563 }
564 #endif
565
566
567 #if defined __USE_SVID || defined __USE_MISC
568 /* Get a word (int) from STREAM.  */
569 extern int getw __P ((FILE *__stream));
570
571 /* Write a word (int) to STREAM.  */
572 extern int putw __P ((int __w, FILE *__stream));
573 #endif
574
575
576 /* Get a newline-terminated string of finite length from STREAM.  */
577 extern char *fgets __P ((char *__restrict __s, int __n,
578                          FILE *__restrict __stream));
579
580 /* Get a newline-terminated string from stdin, removing the newline.
581    DO NOT USE THIS FUNCTION!!  There is no limit on how much it will read.  */
582 extern char *gets __P ((char *__s));
583
584
585 #ifdef  __USE_GNU
586 #include <sys/types.h>
587
588 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
589    (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
590    NULL), pointing to *N characters of space.  It is realloc'd as
591    necessary.  Returns the number of characters read (not including the
592    null terminator), or -1 on error or EOF.  */
593 ssize_t __getdelim __P ((char **__lineptr, size_t *__n,
594                          int __delimiter, FILE *__stream));
595 ssize_t getdelim __P ((char **__lineptr, size_t *__n,
596                        int __delimiter, FILE *__stream));
597
598 /* Like `getdelim', but reads up to a newline.  */
599 ssize_t __getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
600 ssize_t getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
601
602 #ifdef  __OPTIMIZE__
603 extern __inline ssize_t
604 getline (char **__lineptr, size_t *__n, FILE *__stream)
605 {
606   return __getdelim (__lineptr, __n, '\n', __stream);
607 }
608 #endif /* Optimizing.  */
609 #endif
610
611
612 /* Write a string to STREAM.  */
613 extern int fputs __P ((__const char *__restrict __s,
614                        FILE *__restrict __stream));
615 /* Write a string, followed by a newline, to stdout.  */
616 extern int puts __P ((__const char *__s));
617
618
619 /* Push a character back onto the input buffer of STREAM.  */
620 extern int ungetc __P ((int __c, FILE *__stream));
621
622
623 /* Read chunks of generic data from STREAM.  */
624 extern size_t fread __P ((__ptr_t __restrict __ptr, size_t __size,
625                           size_t __n, FILE *__restrict __stream));
626 /* Write chunks of generic data to STREAM.  */
627 extern size_t fwrite __P ((__const __ptr_t __restrict __ptr, size_t __size,
628                            size_t __n, FILE *__restrict __s));
629
630
631 /* Seek to a certain position on STREAM.  */
632 extern int fseek __P ((FILE *__stream, long int __off, int __whence));
633 /* Return the current position of STREAM.  */
634 extern long int ftell __P ((FILE *__stream));
635 /* Rewind to the beginning of STREAM.  */
636 extern void rewind __P ((FILE *__stream));
637
638 /* Get STREAM's position.  */
639 extern int fgetpos __P ((FILE *__restrict __stream, fpos_t *__restrict __pos));
640 /* Set STREAM's position.  */
641 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
642
643
644 /* Clear the error and EOF indicators for STREAM.  */
645 extern void clearerr __P ((FILE *__stream));
646 /* Return the EOF indicator for STREAM.  */
647 extern int feof __P ((FILE *__stream));
648 /* Return the error indicator for STREAM.  */
649 extern int ferror __P ((FILE *__stream));
650
651 #ifdef  __OPTIMIZE__
652 #define feof(stream)    ((stream)->__eof != 0)
653 #define ferror(stream)  ((stream)->__error != 0)
654 #endif /* Optimizing.  */
655
656
657 /* Print a message describing the meaning of the value of errno.  */
658 extern void perror __P ((__const char *__s));
659
660 #ifdef  __USE_BSD
661 extern int sys_nerr;
662 extern const char *const sys_errlist[];
663 #endif
664 #ifdef  __USE_GNU
665 extern int _sys_nerr;
666 extern const char *const _sys_errlist[];
667 #endif
668
669
670 #ifdef  __USE_POSIX
671 /* Return the system file descriptor for STREAM.  */
672 extern int fileno __P ((FILE *__stream));
673 #endif /* Use POSIX.  */
674
675
676 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
677      defined __USE_MISC)
678 /* Create a new stream connected to a pipe running the given command.  */
679 extern FILE *popen __P ((__const char *__command, __const char *__modes));
680
681 /* Close a stream opened by popen and return the status of its child.  */
682 extern int pclose __P ((FILE *__stream));
683 #endif
684
685
686 #ifdef  __USE_POSIX
687 /* Return the name of the controlling terminal.  */
688 extern char *ctermid __P ((char *__s));
689 #endif
690
691
692 #ifdef __USE_XOPEN
693 /* Return the name of the current user.  */
694 extern char *cuserid __P ((char *__s));
695 #endif
696
697
698 #ifdef  __USE_GNU
699 struct obstack;                 /* See <obstack.h>.  */
700
701 /* Open a stream that writes to OBSTACK.  */
702 extern FILE *open_obstack_stream __P ((struct obstack *__obstack));
703
704 /* Write formatted output to an obstack.  */
705 extern int obstack_printf __P ((struct obstack *__obstack,
706                                 __const char *__format, ...));
707 extern int obstack_vprintf __P ((struct obstack *__obstack,
708                                  __const char *__format,
709                                  __gnuc_va_list __args));
710 #endif
711
712
713 __END_DECLS
714
715 #endif /* <stdio.h> included.  */
716
717 #endif /* stdio.h  */