]> sourceware.org Git - glibc.git/blob - libio/stdio.h
Update.
[glibc.git] / libio / stdio.h
1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
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 #include <bits/types.h>
36 #endif /* Don't need FILE. */
37 #undef __need_FILE
38
39
40 #ifndef __FILE_defined
41
42 /* The opaque type of streams. */
43 typedef struct _IO_FILE FILE;
44
45 #define __FILE_defined 1
46 #endif /* FILE not defined. */
47
48
49 #ifdef _STDIO_H
50 #define _STDIO_USES_IOSTREAM
51
52 #include <libio.h>
53
54 #ifdef __cplusplus
55 # define __STDIO_INLINE inline
56 #else
57 # define __STDIO_INLINE extern __inline
58 #endif
59
60 /* The type of the second argument to `fgetpos' and `fsetpos'. */
61 typedef _G_fpos_t fpos_t;
62
63
64 /* Generate a unique file name (and possibly open it with mode "w+b"). */
65 extern char *__stdio_gen_tempname __P ((char *__buf, size_t __bufsize,
66 __const char *__dir,
67 __const char *__pfx,
68 int __dir_search,
69 size_t *__lenptr,
70 FILE **__streamptr));
71
72
73 /* Print out MESSAGE on the error output and abort. */
74 extern void __libc_fatal __P ((__const char *__message))
75 __attribute__ ((__noreturn__));
76
77
78 /* The possibilities for the third argument to `setvbuf'. */
79 #define _IOFBF 0 /* Fully buffered. */
80 #define _IOLBF 1 /* Line buffered. */
81 #define _IONBF 2 /* No buffering. */
82
83
84 /* Default buffer size. */
85 #ifndef BUFSIZ
86 #define BUFSIZ _IO_BUFSIZ
87 #endif
88
89
90 /* End of file character.
91 Some things throughout the library rely on this being -1. */
92 #ifndef EOF
93 #define EOF (-1)
94 #endif
95
96
97 /* The possibilities for the third argument to `fseek'.
98 These values should not be changed. */
99 #define SEEK_SET 0 /* Seek from beginning of file. */
100 #define SEEK_CUR 1 /* Seek from current position. */
101 #define SEEK_END 2 /* Seek from end of file. */
102
103
104 #ifdef __USE_SVID
105 /* Default path prefix for `tempnam' and `tmpnam'. */
106 #define P_tmpdir "/tmp"
107 #endif
108
109
110 /* Get the values:
111 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
112 TMP_MAX The minimum number of unique filenames generated by tmpnam
113 (and tempnam when it uses tmpnam's name space),
114 or tempnam (the two are separate).
115 L_ctermid How long an array to pass to `ctermid'.
116 L_cuserid How long an array to pass to `cuserid'.
117 FOPEN_MAX Minimum number of files that can be open at once.
118 FILENAME_MAX Maximum length of a filename. */
119 #include <bits/stdio_lim.h>
120
121
122 /* Standard streams. */
123 extern FILE *stdin, *stdout, *stderr;
124 /* Refer to the real names by default. */
125 #define stdin _IO_stdin
126 #define stdout _IO_stdout
127 #define stderr _IO_stderr
128
129
130 /* Remove file FILENAME. */
131 extern int remove __P ((__const char *__filename));
132 /* Rename file OLD to NEW. */
133 extern int rename __P ((__const char *__old, __const char *__new));
134
135
136 /* Create a temporary file and open it read/write. */
137 extern FILE *tmpfile __P ((void));
138 /* Generate a temporary filename. */
139 extern char *tmpnam __P ((char *__s));
140
141 #ifdef __USE_MISC
142 /* This is the reentrant variant of `tmpnam'. The only difference is
143 that it does not allow S to be NULL. */
144 extern char *tmpnam_r __P ((char *__s));
145 #endif
146
147
148 #if defined __USE_SVID || defined __USE_XOPEN
149 /* Generate a unique temporary filename using up to five characters of PFX
150 if it is not NULL. The directory to put this file in is searched for
151 as follows: First the environment variable "TMPDIR" is checked.
152 If it contains the name of a writable directory, that directory is used.
153 If not and if DIR is not NULL, that value is checked. If that fails,
154 P_tmpdir is tried and finally "/tmp". The storage for the filename
155 is allocated by `malloc'. */
156 extern char *tempnam __P ((__const char *__dir, __const char *__pfx));
157 #endif
158
159
160 /* Close STREAM. */
161 extern int fclose __P ((FILE *__stream));
162 /* Flush STREAM, or all streams if STREAM is NULL. */
163 extern int fflush __P ((FILE *__stream));
164
165 #ifdef __USE_MISC
166 /* Faster versions when locking is not required. */
167 extern int fclose_unlocked __P ((FILE *__stream));
168 extern int fflush_unlocked __P ((FILE *__stream));
169 #endif
170
171 #ifdef __USE_GNU
172 /* Close all streams. */
173 extern int __fcloseall __P ((void));
174 extern int fcloseall __P ((void));
175 #endif
176
177
178 /* Open a file and create a new stream for it. */
179 extern FILE *fopen __P ((__const char *__filename, __const char *__modes));
180 /* Open a file, replacing an existing stream with it. */
181 extern FILE *freopen __P ((__const char *__restrict __filename,
182 __const char *__restrict __modes,
183 FILE *__restrict __stream));
184
185 #ifdef __USE_POSIX
186 /* Create a new stream that refers to an existing system file descriptor. */
187 extern FILE *fdopen __P ((int __fd, __const char *__modes));
188 #endif
189
190 #ifdef __USE_GNU
191 /* Create a new stream that refers to the given magic cookie,
192 and uses the given functions for input and output. */
193 extern FILE *fopencookie __P ((void *__magic_cookie, __const char *__modes,
194 _IO_cookie_io_functions_t __io_funcs));
195
196 /* Open a stream that writes into a malloc'd buffer that is expanded as
197 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
198 and the number of characters written on fflush or fclose. */
199 extern FILE *open_memstream __P ((char **__bufloc, size_t *__sizeloc));
200 #endif
201
202
203 /* If BUF is NULL, make STREAM unbuffered.
204 Else make it use buffer BUF, of size BUFSIZ. */
205 extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
206 /* Make STREAM use buffering mode MODE.
207 If BUF is not NULL, use N bytes of it for buffering;
208 else allocate an internal buffer N bytes long. */
209 extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
210 int __modes, size_t __n));
211
212 #ifdef __USE_BSD
213 /* If BUF is NULL, make STREAM unbuffered.
214 Else make it use SIZE bytes of BUF for buffering. */
215 extern void setbuffer __P ((FILE *__stream, char *__buf, size_t __size));
216
217 /* Make STREAM line-buffered. */
218 extern void setlinebuf __P ((FILE *__stream));
219 #endif
220
221
222 /* Write formatted output to STREAM. */
223 extern int fprintf __P ((FILE *__restrict __stream,
224 __const char *__restrict __format, ...));
225 /* Write formatted output to stdout. */
226 extern int printf __P ((__const char *__restrict __format, ...));
227 /* Write formatted output to S. */
228 extern int sprintf __P ((char *__restrict __s,
229 __const char *__restrict __format, ...));
230
231 /* Write formatted output to S from argument list ARG. */
232 extern int vfprintf __P ((FILE *__restrict __s,
233 __const char *__restrict __format,
234 _G_va_list __arg));
235 /* Write formatted output to stdout from argument list ARG. */
236 extern int vprintf __P ((__const char *__restrict __format,
237 _G_va_list __arg));
238 /* Write formatted output to S from argument list ARG. */
239 extern int vsprintf __P ((char *__restrict __s,
240 __const char *__restrict __format,
241 _G_va_list __arg));
242
243 #ifdef __OPTIMIZE__
244 __STDIO_INLINE int
245 vprintf (const char *__restrict __fmt, _G_va_list __arg)
246 {
247 return vfprintf (stdout, __fmt, __arg);
248 }
249 #endif /* Optimizing. */
250
251 #if defined __USE_BSD || defined __USE_ISOC9X
252 /* Maximum chars of output to write in MAXLEN. */
253 extern int __snprintf __P ((char *__restrict __s, size_t __maxlen,
254 __const char *__restrict __format, ...))
255 __attribute__ ((__format__ (__printf__, 3, 4)));
256 extern int snprintf __P ((char *__restrict __s, size_t __maxlen,
257 __const char *__restrict __format, ...))
258 __attribute__ ((__format__ (__printf__, 3, 4)));
259
260 extern int __vsnprintf __P ((char *__restrict __s, size_t __maxlen,
261 __const char *__restrict __format,
262 _G_va_list __arg))
263 __attribute__ ((__format__ (__printf__, 3, 0)));
264 extern int vsnprintf __P ((char *__restrict __s, size_t __maxlen,
265 __const char *__restrict __format,
266 _G_va_list __arg))
267 __attribute__ ((__format__ (__printf__, 3, 0)));
268 #endif
269
270 #ifdef __USE_GNU
271 /* Write formatted output to a string dynamically allocated with `malloc'.
272 Store the address of the string in *PTR. */
273 extern int vasprintf __P ((char **__restrict __ptr,
274 __const char *__restrict __f, _G_va_list __arg))
275 __attribute__ ((__format__ (__printf__, 2, 0)));
276 extern int asprintf __P ((char **__restrict __ptr,
277 __const char *__restrict __fmt, ...))
278 __attribute__ ((__format__ (__printf__, 2, 3)));
279
280 /* Write formatted output to a file descriptor. */
281 extern int vdprintf __P ((int __fd, __const char *__restrict __fmt,
282 _G_va_list __arg))
283 __attribute__ ((__format__ (__printf__, 2, 0)));
284 extern int dprintf __P ((int __fd, __const char *__restrict __fmt, ...))
285 __attribute__ ((__format__ (__printf__, 2, 3)));
286 #endif
287
288
289 /* Read formatted input from STREAM. */
290 extern int fscanf __P ((FILE *__restrict __stream,
291 __const char *__restrict __format, ...));
292 /* Read formatted input from stdin. */
293 extern int scanf __P ((__const char *__restrict __format, ...));
294 /* Read formatted input from S. */
295 extern int sscanf __P ((__const char *__restrict __s,
296 __const char *__restrict __format, ...));
297
298 #ifdef __USE_GNU
299 /* Read formatted input from S into argument list ARG. */
300 extern int __vfscanf __P ((FILE *__restrict __s,
301 __const char *__restrict __format,
302 _G_va_list __arg))
303 __attribute__ ((__format__ (__scanf__, 2, 0)));
304 extern int vfscanf __P ((FILE *__restrict __s,
305 __const char *__restrict __format,
306 _G_va_list __arg))
307 __attribute__ ((__format__ (__scanf__, 2, 0)));
308
309 /* Read formatted input from stdin into argument list ARG. */
310 extern int __vscanf __P ((__const char *__restrict __format,
311 _G_va_list __arg))
312 __attribute__ ((__format__ (__scanf__, 1, 0)));
313 extern int vscanf __P ((__const char *__restrict __format, _G_va_list __arg))
314 __attribute__ ((__format__ (__scanf__, 1, 0)));
315
316 /* Read formatted input from S into argument list ARG. */
317 extern int __vsscanf __P ((__const char *__restrict __s,
318 __const char *__restrict __format,
319 _G_va_list __arg))
320 __attribute__ ((__format__ (__scanf__, 2, 0)));
321 extern int vsscanf __P ((__const char *__restrict __s,
322 __const char *__restrict __format,
323 _G_va_list __arg))
324 __attribute__ ((__format__ (__scanf__, 2, 0)));
325 #endif /* Use GNU. */
326
327
328 /* Read a character from STREAM. */
329 extern int fgetc __P ((FILE *__stream));
330 extern int getc __P ((FILE *__stream));
331
332 /* Read a character from stdin. */
333 extern int getchar __P ((void));
334
335 /* The C standard explicitly says this is a macro, so we always do the
336 optimization for it. */
337 #define getc(_fp) _IO_getc (_fp)
338
339 #ifdef __OPTIMIZE__
340 __STDIO_INLINE int
341 getchar (void)
342 {
343 return _IO_getc (stdin);
344 }
345 #endif /* Optimizing. */
346
347 #if defined __USE_POSIX || defined __USE_MISC
348 /* These are defined in POSIX.1:1996. */
349 extern int getc_unlocked __P ((FILE *__stream));
350 extern int getchar_unlocked __P ((void));
351
352 #ifdef __OPTIMIZE__
353 __STDIO_INLINE int
354 getc_unlocked (FILE *__fp)
355 {
356 return _IO_getc_unlocked (__fp);
357 }
358
359 __STDIO_INLINE int
360 getchar_unlocked (void)
361 {
362 return _IO_getc_unlocked (stdin);
363 }
364 #endif /* Optimizing. */
365 #endif /* Use POSIX or MISC. */
366
367
368 /* Write a character to STREAM. */
369 extern int fputc __P ((int __c, FILE *__stream));
370 extern int putc __P ((int __c, FILE *__stream));
371
372 /* Write a character to stdout. */
373 extern int putchar __P ((int __c));
374
375 /* The C standard explicitly says this can be a macro,
376 so we always do the optimization for it. */
377 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
378
379 #ifdef __OPTIMIZE__
380 __STDIO_INLINE int
381 putchar (int __c)
382 {
383 return _IO_putc (__c, stdout);
384 }
385 #endif
386
387 #ifdef __USE_MISC
388 /* Faster version when locking is not necessary. */
389 extern int fputc_unlocked __P ((int __c, FILE *__stream));
390
391 #ifdef __OPTIMIZE__
392 __STDIO_INLINE int
393 fputc_unlocked (int __c, FILE *__stream)
394 {
395 return _IO_putc_unlocked (__c, __stream);
396 }
397 #endif /* Optimizing. */
398 #endif /* Use MISC. */
399
400 #if defined __USE_POSIX || defined __USE_MISC
401 /* These are defined in POSIX.1:1996. */
402 extern int putc_unlocked __P ((int __c, FILE *__stream));
403 extern int putchar_unlocked __P ((int __c));
404
405 #ifdef __OPTIMIZE__
406 __STDIO_INLINE int
407 putc_unlocked (int __c, FILE *__stream)
408 {
409 return _IO_putc_unlocked (__c, __stream);
410 }
411
412 __STDIO_INLINE int
413 putchar_unlocked (int __c)
414 {
415 return _IO_putc_unlocked (__c, stdout);
416 }
417 #endif /* Optimizing. */
418 #endif /* Use POSIX or MISc. */
419
420
421 #if defined __USE_SVID || defined __USE_MISC
422 /* Get a word (int) from STREAM. */
423 extern int getw __P ((FILE *__stream));
424
425 /* Write a word (int) to STREAM. */
426 extern int putw __P ((int __w, FILE *__stream));
427 #endif
428
429
430 /* Get a newline-terminated string of finite length from STREAM. */
431 extern char *fgets __P ((char *__restrict __s, int __n,
432 FILE *__restrict __stream));
433
434 /* Get a newline-terminated string from stdin, removing the newline.
435 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
436 extern char *gets __P ((char *__s));
437
438
439 #ifdef __USE_GNU
440 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
441 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
442 NULL), pointing to *N characters of space. It is realloc'd as
443 necessary. Returns the number of characters read (not including the
444 null terminator), or -1 on error or EOF. */
445 _IO_ssize_t __getdelim __P ((char **__lineptr, size_t *__n,
446 int __delimiter, FILE *__stream));
447 _IO_ssize_t getdelim __P ((char **__lineptr, size_t *__n,
448 int __delimiter, FILE *__stream));
449
450 /* Like `getdelim', but reads up to a newline. */
451 _IO_ssize_t __getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
452 _IO_ssize_t getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
453
454 #ifdef __OPTIMIZE__
455 __STDIO_INLINE _IO_ssize_t
456 getline (char **__lineptr, size_t *__n, FILE *__stream)
457 {
458 return __getdelim (__lineptr, __n, '\n', __stream);
459 }
460 #endif /* Optimizing. */
461 #endif
462
463
464 /* Write a string to STREAM. */
465 extern int fputs __P ((__const char *__restrict __s,
466 FILE *__restrict __stream));
467 /* Write a string, followed by a newline, to stdout. */
468 extern int puts __P ((__const char *__s));
469
470
471 /* Push a character back onto the input buffer of STREAM. */
472 extern int ungetc __P ((int __c, FILE *__stream));
473
474
475 /* Read chunks of generic data from STREAM. */
476 extern size_t fread __P ((void *__restrict __ptr, size_t __size,
477 size_t __n, FILE *__restrict __stream));
478 /* Write chunks of generic data to STREAM. */
479 extern size_t fwrite __P ((__const void *__restrict __ptr, size_t __size,
480 size_t __n, FILE *__restrict __s));
481
482 #ifdef __USE_MISC
483 /* Faster versions when locking is not necessary. */
484 extern size_t fread_unlocked __P ((void *__restrict __ptr, size_t __size,
485 size_t __n, FILE *__restrict __stream));
486 extern size_t fwrite_unlocked __P ((__const void *__restrict __ptr,
487 size_t __size, size_t __n,
488 FILE *__restrict __stream));
489 #endif
490
491
492 /* Seek to a certain position on STREAM. */
493 extern int fseek __P ((FILE *__stream, long int __off, int __whence));
494 /* Return the current position of STREAM. */
495 extern long int ftell __P ((FILE *__stream));
496 /* Rewind to the beginning of STREAM. */
497 extern void rewind __P ((FILE *__stream));
498
499 #ifdef __USE_UNIX98
500 /* The Single Unix Specification, Version 2, specifies an alternative,
501 more adequate interface for the two functions above which deal with
502 file offset. `long int' is not the right type. */
503
504 /* Seek to a certain position on STREAM. */
505 extern int fseeko __P ((FILE *__stream, __off_t __off, int __whence));
506 /* Return the current position of STREAM. */
507 extern __off_t ftello __P ((FILE *__stream));
508 #endif
509
510 /* Get STREAM's position. */
511 extern int fgetpos __P ((FILE *__restrict __stream,
512 fpos_t *__restrict __pos));
513 /* Set STREAM's position. */
514 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
515
516
517 /* Clear the error and EOF indicators for STREAM. */
518 extern void clearerr __P ((FILE *__stream));
519 /* Return the EOF indicator for STREAM. */
520 extern int feof __P ((FILE *__stream));
521 /* Return the error indicator for STREAM. */
522 extern int ferror __P ((FILE *__stream));
523
524 #ifdef __USE_MISC
525 /* Faster versions when locking is not required. */
526 extern void clearerr_unlocked __P ((FILE *__stream));
527 extern int feof_unlocked __P ((FILE *__stream));
528 extern int ferror_unlocked __P ((FILE *__stream));
529
530 #ifdef __OPTIMIZE__
531 __STDIO_INLINE int
532 feof_unlocked (FILE *__stream)
533 {
534 return _IO_feof_unlocked (__stream);
535 }
536
537 __STDIO_INLINE int
538 ferror_unlocked (FILE *__stream)
539 {
540 return _IO_ferror_unlocked (__stream);
541 }
542 #endif /* Optimizing. */
543 #endif
544
545
546 /* Print a message describing the meaning of the value of errno. */
547 extern void perror __P ((__const char *__s));
548
549 /* These variables normally should not be used directly. The `strftime'
550 function provides all the needed functionality. */
551 #ifdef __USE_BSD
552 extern int sys_nerr;
553 extern __const char *__const sys_errlist[];
554 #endif
555 #ifdef __USE_GNU
556 extern int _sys_nerr;
557 extern __const char *__const _sys_errlist[];
558 #endif
559
560
561 #ifdef __USE_POSIX
562 /* Return the system file descriptor for STREAM. */
563 extern int fileno __P ((FILE *__stream));
564 #endif /* Use POSIX. */
565
566 #ifdef __USE_MISC
567 /* Faster version when locking is not required. */
568 extern int fileno_unlocked __P ((FILE *__stream));
569 #endif
570
571
572 #if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
573 defined __USE_MISC)
574 /* Create a new stream connected to a pipe running the given command. */
575 extern FILE *popen __P ((__const char *__command, __const char *__modes));
576
577 /* Close a stream opened by popen and return the status of its child. */
578 extern int pclose __P ((FILE *__stream));
579 #endif
580
581
582 #ifdef __USE_POSIX
583 /* Return the name of the controlling terminal. */
584 extern char *ctermid __P ((char *__s));
585 #endif /* Use POSIX. */
586
587
588 #ifdef __USE_XOPEN
589 /* Return the name of the current user. */
590 extern char *cuserid __P ((char *__s));
591 #endif /* Use X/Open. */
592
593
594 #ifdef __USE_GNU
595 struct obstack; /* See <obstack.h>. */
596
597 /* Write formatted output to an obstack. */
598 extern int obstack_printf __P ((struct obstack *__obstack,
599 __const char *__format, ...));
600 extern int obstack_vprintf __P ((struct obstack *__obstack,
601 __const char *__format,
602 _G_va_list __args));
603 #endif /* Use GNU. */
604
605
606 #if defined __USE_POSIX || defined __USE_MISC
607 /* These are defined in POSIX.1:1996. */
608
609 /* Acquire ownership of STREAM. */
610 extern void flockfile __P ((FILE *__stream));
611
612 /* Try to acquire ownership of STREAM but do not block if it is not
613 possible. */
614 extern int ftrylockfile __P ((FILE *__stream));
615
616 /* Relinquish the ownership granted for STREAM. */
617 extern void funlockfile __P ((FILE *__stream));
618 #endif /* POSIX || misc */
619
620 __END_DECLS
621
622 /* Define helper macro. */
623 #undef __STDIO_INLINE
624
625 #endif /* <stdio.h> included. */
626
627 #endif /* !_STDIO_H */
This page took 0.071812 seconds and 6 git commands to generate.