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