]> Git Repo - uclibc-ng.git/blame - include/stdio.h
We already have tar.h, so might as well include cpio.h as well...
[uclibc-ng.git] / include / stdio.h
CommitLineData
afa40ade
EA
1/* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991, 1994-1999, 2000 Free Software Foundation, Inc.
64bc6412 3
afa40ade
EA
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.
64bc6412 8
afa40ade
EA
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.
64bc6412 13
afa40ade
EA
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. */
64bc6412 18
afa40ade
EA
19/*
20 * ISO C Standard: 4.9 INPUT/OUTPUT <stdio.h>
21 */
64bc6412 22
afa40ade
EA
23#ifndef _STDIO_H
24#define _STDIO_H
64bc6412 25
afa40ade
EA
26#include <features.h>
27#include <stdarg.h>
28#include <sys/types.h>
64bc6412 29
afa40ade 30__BEGIN_DECLS
64bc6412 31
64bc6412
EA
32
33/* when you add or change fields here, be sure to change the initialization
34 * in stdio_init and fopen */
35struct __stdio_file {
36 unsigned char *bufpos; /* the next byte to write to or read from */
37 unsigned char *bufread; /* the end of data returned by last read() */
82dd793f 38 unsigned char *bufwrite; /* 1 + highest address writable by macro */
64bc6412
EA
39 unsigned char *bufstart; /* the start of the buffer */
40 unsigned char *bufend; /* the end of the buffer; ie the byte after the last
41 malloc()ed byte */
82dd793f 42 struct __stdio_file * next;
64bc6412
EA
43
44 int fd; /* the file descriptor associated with the stream */
d521275a 45
82dd793f
MNI
46 unsigned char mode;
47 unsigned char ungot;
48 char unbuf[2]; /* The buffer for 'unbuffered' streams */
64bc6412
EA
49};
50
afa40ade
EA
51typedef struct __stdio_file FILE;
52
53/* Default buffer size. */
0c827cb7 54#define BUFSIZ (512)
afa40ade
EA
55
56/* Define EOF and NULL */
64bc6412
EA
57#define EOF (-1)
58#ifndef NULL
59#define NULL (0)
60#endif
61
afa40ade
EA
62/* The possibilities for the third argument to `setvbuf'. */
63#define _IOFBF 0 /* Fully buffered. */
64#define _IOLBF 1 /* Line buffered. */
65#define _IONBF 2 /* No buffering. */
66
67/* Possible states for a file stream -- internal use only */
82dd793f
MNI
68#define __MODE_BUF 0x03 /* Modal buffering dependent on isatty */
69#define __MODE_FREEBUF 0x04 /* Buffer allocated by stdio code, can free */
70#define __MODE_FREEFIL 0x08 /* FILE allocated by stdio code, can free */
71#define __MODE_UNGOT 0x10 /* Buffer has been polluted by ungetc */
72#define __MODE_TIED 0x20 /* FILE is tied with stdin/stdout */
73#define __MODE_EOF 0x40 /* EOF status */
74#define __MODE_ERR 0x80 /* Error status */
64bc6412 75
afa40ade
EA
76/* The possibilities for the third argument to `fseek'.
77 These values should not be changed. */
78#define SEEK_SET 0 /* Seek from beginning of file. */
79#define SEEK_CUR 1 /* Seek from current position. */
80#define SEEK_END 2 /* Seek from end of file. */
64bc6412 81
afa40ade
EA
82/* Default path prefix for `tempnam' and `tmpnam'. */
83#define P_tmpdir "/tmp"
84/* Get the values:
85 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
86 TMP_MAX The minimum number of unique filenames generated by tmpnam
87 (and tempnam when it uses tmpnam's name space),
88 or tempnam (the two are separate).
89 L_ctermid How long an array to pass to `ctermid'.
90 L_cuserid How long an array to pass to `cuserid'.
91 FOPEN_MAX Minimum number of files that can be open at once.
92 FILENAME_MAX Maximum length of a filename. */
93#define __need_FOPEN_MAX
94#include <bits/stdio_lim.h>
95#undef __need_FOPEN_MAX
64bc6412 96
ae97a89e 97/* Standard streams (internal). */
bd0ff62e
MNI
98extern FILE *_stdin;
99extern FILE *_stdout;
100extern FILE *_stderr;
101
afa40ade 102/* C89/C99 say they're macros. Make them happy. */
bd0ff62e
MNI
103#define stdin _stdin
104#define stdout _stdout
105#define stderr _stderr
64bc6412 106
afa40ade
EA
107/* Remove file FILENAME. */
108extern int remove __P ((__const char *__filename));
109/* Rename file OLD to NEW. */
110extern int rename __P ((__const char *__old, __const char *__new));
64bc6412 111
64bc6412 112
afa40ade
EA
113/* Create a temporary file and open it read/write. */
114extern FILE *tmpfile __P ((void));
115#ifdef __USE_LARGEFILE64
116extern FILE *tmpfile64 __P ((void));
117#endif
118/* Generate a temporary filename. */
119extern char *tmpnam __P ((char *__s));
120
121#ifdef __USE_MISC
122/* This is the reentrant variant of `tmpnam'. The only difference is
123 that it does not allow S to be NULL. */
124extern char *tmpnam_r __P ((char *__s));
125#endif
126
127
128#if defined __USE_SVID || defined __USE_XOPEN
129/* Generate a unique temporary filename using up to five characters of PFX
130 if it is not NULL. The directory to put this file in is searched for
131 as follows: First the environment variable "TMPDIR" is checked.
132 If it contains the name of a writable directory, that directory is used.
133 If not and if DIR is not NULL, that value is checked. If that fails,
134 P_tmpdir is tried and finally "/tmp". The storage for the filename
135 is allocated by `malloc'. */
136extern char *tempnam __P ((__const char *__dir, __const char *__pfx));
137#endif
42ee0791 138
42ee0791
EA
139
140/* Close STREAM. */
141extern int fclose __P ((FILE *__stream));
142/* Flush STREAM, or all streams if STREAM is NULL. */
143extern int fflush __P ((FILE *__stream));
144
afa40ade 145/* Used internally to actuall open files */
42ee0791 146extern FILE *__fopen __P((__const char *__restrict __filename, int __fd,
d521275a
MNI
147 FILE *__restrict __stream, __const char *__restrict __mode));
148/* Open a file and create a new stream for it. */
149extern FILE *fopen __P ((__const char *__restrict __filename,
150 __const char *__restrict __mode));
64bc6412 151#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode))
42ee0791 152/* Open a file, replacing an existing stream with it. */
afa40ade 153extern FILE *freopen __P ((__const char *__restrict __filename,
d521275a 154 __const char *__restrict __mode,
afa40ade 155 FILE *__restrict __stream));
82dd793f
MNI
156
157#ifdef __USE_MISC
158/*
159 * Open a file using an automatically (stack) or statically allocated FILE.
160 * The FILE * returned behaves just as any other FILE * with respect to the
161 * stdio functions, but be aware of the following:
162 * NOTE: The buffer used for the file is FILE's builtin 2-byte buffer, so
163 * setting a new buffer is probably advisable.
164 * NOTE: This function is primarily intended to be used for stack-allocated
165 * FILEs when uClibc stdio has been built with no dynamic memory support.
166 * For the statically allocated case, it is probably better to increase
167 * the value of FIXED_STREAMS in stdio.c.
168 * WARNING: If allocated on the stack, make sure you call fclose before the
169 * stack memory is reclaimed!
170 */
171extern FILE *fsfopen __P ((__const char *__restrict __filename,
172 __const char *__restrict __mode,
173 FILE *__restrict __stream));
174#endif
175
afa40ade
EA
176
177#ifdef __USE_LARGEFILE64
178extern FILE *fopen64 __P ((__const char *__restrict __filename,
d521275a 179 __const char *__restrict __mode));
afa40ade 180extern FILE *freopen64 __P ((__const char *__restrict __filename,
d521275a 181 __const char *__restrict __mode,
afa40ade
EA
182 FILE *__restrict __stream));
183#endif
184
185#ifdef __USE_POSIX
42ee0791 186/* Create a new stream that refers to an existing system file descriptor. */
d521275a 187extern FILE *fdopen __P ((int __fd, __const char *__mode));
64bc6412 188#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode))
afa40ade 189#endif
64bc6412 190
64bc6412 191
afa40ade
EA
192/* Make STREAM use buffering mode MODE.
193 If BUF is not NULL, use N bytes of it for buffering;
194 else allocate an internal buffer N bytes long. */
195extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
d521275a
MNI
196 int __mode, size_t __n));
197
198/* If BUF is NULL, make STREAM unbuffered.
199 Else make it use buffer BUF, of size BUFSIZ. */
200extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
42ee0791 201
afa40ade
EA
202#ifdef __USE_BSD
203/* If BUF is NULL, make STREAM unbuffered.
204 Else make it use SIZE bytes of BUF for buffering. */
205extern void setbuffer __P ((FILE *__restrict __stream, char *__restrict __buf,
206 size_t __size));
207
208/* Make STREAM line-buffered. */
209extern void setlinebuf __P ((FILE *__stream));
afa40ade 210#endif
42ee0791
EA
211
212
42ee0791
EA
213/* Write formatted output to STREAM. */
214extern int fprintf __P ((FILE *__restrict __stream,
215 __const char *__restrict __format, ...));
afa40ade
EA
216/* Write formatted output to stdout. */
217extern int printf __P ((__const char *__restrict __format, ...));
42ee0791
EA
218/* Write formatted output to S. */
219extern int sprintf __P ((char *__restrict __s,
220 __const char *__restrict __format, ...));
221
bd0ff62e
MNI
222/* Write formatted output to a file descriptor */
223extern int vdprintf __P((int fd, __const char *__restrict __format,
224 va_list __arg));
225
fdfb85cb
MNI
226/* Write formatted output to a buffer S dynamically allocated by asprintf. */
227extern int asprintf __P ((char **__restrict __s,
228 __const char *__restrict __format, ...));
229
42ee0791
EA
230/* Write formatted output to S from argument list ARG. */
231extern int vfprintf __P ((FILE *__restrict __s,
232 __const char *__restrict __format,
233 va_list __arg));
afa40ade
EA
234/* Write formatted output to stdout from argument list ARG. */
235extern int vprintf __P ((__const char *__restrict __format,
236 va_list __arg));
42ee0791
EA
237/* Write formatted output to S from argument list ARG. */
238extern int vsprintf __P ((char *__restrict __s,
239 __const char *__restrict __format,
240 va_list __arg));
afa40ade 241
84866232
EA
242/* Maximum chars of output to write in MAXLEN. */
243extern int snprintf __P ((char *__restrict __s, size_t __maxlen,
244 __const char *__restrict __format, ...))
245 __attribute__ ((__format__ (__printf__, 3, 4)));
afa40ade
EA
246
247extern int __vsnprintf __P ((char *__restrict __s, size_t __maxlen,
248 __const char *__restrict __format,
249 va_list __arg))
250 __attribute__ ((__format__ (__printf__, 3, 0)));
84866232
EA
251extern int vsnprintf __P ((char *__restrict __s, size_t __maxlen,
252 __const char *__restrict __format,
253 va_list __arg))
254 __attribute__ ((__format__ (__printf__, 3, 0)));
42ee0791 255
afa40ade
EA
256/* Read formatted input from STREAM. */
257extern int fscanf __P ((FILE *__restrict __stream,
258 __const char *__restrict __format, ...));
42ee0791
EA
259/* Read formatted input from stdin. */
260extern int scanf __P ((__const char *__restrict __format, ...));
261/* Read formatted input from S. */
262extern int sscanf __P ((__const char *__restrict __s,
263 __const char *__restrict __format, ...));
afa40ade 264
42ee0791 265/* Read formatted input from S into argument list ARG. */
afa40ade 266extern int vfscanf __P ((FILE *__restrict __s,
42ee0791
EA
267 __const char *__restrict __format,
268 va_list __arg))
269 __attribute__ ((__format__ (__scanf__, 2, 0)));
afa40ade
EA
270
271/* Read formatted input from stdin into argument list ARG. */
272extern int vscanf __P ((__const char *__restrict __format, va_list __arg))
273 __attribute__ ((__format__ (__scanf__, 1, 0)));
274
42ee0791 275/* Read formatted input from S into argument list ARG. */
afa40ade 276extern int vsscanf __P ((__const char *__restrict __s,
42ee0791
EA
277 __const char *__restrict __format,
278 va_list __arg))
279 __attribute__ ((__format__ (__scanf__, 2, 0)));
64bc6412 280
64bc6412 281
afa40ade
EA
282/* Read a character from STREAM. */
283extern int fgetc __P ((FILE *__stream));
284extern int getc __P ((FILE *__stream));
285
286/* Read a character from stdin. */
287extern int getchar __P ((void));
d521275a 288#define getchar() getc(_stdin)
afa40ade
EA
289
290/* The C standard explicitly says this is a macro, so be that way */
291#define getc(stream) \
292 (((stream)->bufpos >= (stream)->bufread) ? fgetc(stream): \
293 (*(stream)->bufpos++))
294
295/* Write a character to STREAM. */
296extern int fputc __P ((int __c, FILE *__stream));
297extern int putc __P ((int __c, FILE *__stream));
298
299/* Write a character to stdout. */
300extern int putchar __P ((int __c));
d521275a
MNI
301/* Beware! stdout can be redefined! */
302#define putchar(c) putc((c), _stdout)
afa40ade
EA
303
304/* The C standard explicitly says this can be a macro, so be that way */
305#define putc(c, stream) \
306 (((stream)->bufpos >= (stream)->bufwrite) ? fputc((c), (stream)) \
307 : (unsigned char) (*(stream)->bufpos++ = (c)) )
308
309#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
310/* Get a word (int) from STREAM. */
311extern int getw __P ((FILE *__stream));
312
313/* Write a word (int) to STREAM. */
314extern int putw __P ((int __w, FILE *__stream));
315#endif
316
317
318/* Get a newline-terminated string of finite length from STREAM. */
319extern char *fgets __P ((char *__restrict __s, int __n,
320 FILE *__restrict __stream));
321
322/* Get a newline-terminated string from stdin, removing the newline.
323 DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */
324extern char *gets __P ((char *__s));
325
a67c6273 326
a8aa4c64 327#ifdef __USE_GNU
cf4328b1
EA
328/* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
329 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
330 NULL), pointing to *N characters of space. It is realloc'd as
331 necessary. Returns the number of characters read (not including the
332 null terminator), or -1 on error or EOF. */
afa40ade
EA
333extern ssize_t __getdelim __P ((char **__restrict __lineptr,
334 size_t *__restrict __n, int __delimiter,
335 FILE *__restrict __stream));
336extern ssize_t getdelim __P ((char **__restrict __lineptr,
cf4328b1
EA
337 size_t *__restrict __n, int __delimiter,
338 FILE *__restrict __stream));
afa40ade 339
56e5d28c 340/* Like `getdelim', but reads up to a newline. */
afa40ade 341extern ssize_t getline __P ((char **__restrict __lineptr,
56e5d28c
EA
342 size_t *__restrict __n,
343 FILE *__restrict __stream));
a8aa4c64 344#endif
a67c6273 345
64bc6412 346
afa40ade
EA
347/* Write a string to STREAM. */
348extern int fputs __P ((__const char *__restrict __s,
349 FILE *__restrict __stream));
350
351/* Write a string, followed by a newline, to stdout. */
352extern int puts __P ((__const char *__s));
353
354
355/* Push a character back onto the input buffer of STREAM. */
356extern int ungetc __P ((int __c, FILE *__stream));
357
358
359/* Read chunks of generic data from STREAM. */
360extern size_t fread __P ((void *__restrict __ptr, size_t __size,
361 size_t __n, FILE *__restrict __stream));
362/* Write chunks of generic data to STREAM. */
363extern size_t fwrite __P ((__const void *__restrict __ptr, size_t __size,
364 size_t __n, FILE *__restrict __s));
365
d521275a
MNI
366/* Rewind to the beginning of STREAM. */
367extern void rewind __P ((FILE *__stream));
368
afa40ade
EA
369/* Seek to a certain position on STREAM. */
370extern int fseek __P ((FILE *__stream, long int __off, int __whence));
371/* Return the current position of STREAM. */
372extern long int ftell __P ((FILE *__stream));
afa40ade
EA
373
374/* The Single Unix Specification, Version 2, specifies an alternative,
375 more adequate interface for the two functions above which deal with
376 file offset. `long int' is not the right type. These definitions
377 are originally defined in the Large File Support API. */
378
379/* Types needed in these functions. */
380#ifndef off_t
381typedef __off_t off_t;
382# define off_t off_t
383#endif
384
385#if defined __USE_LARGEFILE64 && !defined off64_t
386typedef __off64_t off64_t;
387# define off64_t off64_t
388#endif
389
d521275a
MNI
390#ifndef fpos_t
391typedef off_t fpos_t;
392#define fpos_t fpos_t
393#endif
394
395/* Seek to a certain position on STREAM. */
396extern int fsetpos __P((FILE *__stream, __const fpos_t *__pos));
397/* Return the current position of STREAM. */
398extern int fgetpos __P((FILE *__stream, fpos_t *__pos));
afa40ade
EA
399
400/* Clear the error and EOF indicators for STREAM. */
401extern void clearerr __P ((FILE *__stream));
afa40ade
EA
402/* Return the EOF indicator for STREAM. */
403extern int feof __P ((FILE *__stream));
afa40ade
EA
404/* Return the error indicator for STREAM. */
405extern int ferror __P ((FILE *__stream));
d521275a
MNI
406
407/* Macro versions of the 3 previous functions */
408/* If fp is NULL... */
409#define clearerr(fp) ((fp)->mode &= ~(__MODE_EOF|__MODE_ERR), (void)0)
82dd793f
MNI
410#define feof(fp) ((fp)->mode&__MODE_EOF)
411#define ferror(fp) ((fp)->mode&__MODE_ERR)
afa40ade
EA
412
413/* Print a message describing the meaning of the value of errno. */
414extern void perror __P ((__const char *__s));
415
416/* These variables normally should not be used directly. The `strerror'
417 function provides all the needed functionality. */
418extern int sys_nerr;
419extern __const char *__const sys_errlist[];
420
421#ifdef __USE_POSIX
422/* Return the system file descriptor for STREAM. */
423extern int fileno __P ((FILE *__stream));
d521275a
MNI
424/* Only use the macro below if you know fp is a valid FILE for a valid fd. */
425#define __fileno(fp) ((fp)->fd)
afa40ade
EA
426#endif /* Use POSIX. */
427
428#if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \
429 defined __USE_MISC)
430/* Create a new stream connected to a pipe running the given command. */
d521275a 431extern FILE *popen __P ((__const char *__command, __const char *__mode));
afa40ade
EA
432
433/* Close a stream opened by popen and return the status of its child. */
434extern int pclose __P ((FILE *__stream));
435#endif
436
437
438#ifdef __USE_POSIX
439/* Return the name of the controlling terminal. */
440extern char *ctermid __P ((char *__s));
441#endif /* Use POSIX. */
442
443
444#ifdef __USE_XOPEN
445/* Return the name of the current user. */
446extern char *cuserid __P ((char *__s));
447#endif /* Use X/Open. */
448
449
450#if defined __USE_POSIX || defined __USE_MISC
451/* These are defined in POSIX.1:1996. */
452
453/* Acquire ownership of STREAM. */
454extern void flockfile __P ((FILE *__stream));
455
456/* Try to acquire ownership of STREAM but do not block if it is not
457 possible. */
458extern int ftrylockfile __P ((FILE *__stream));
459
460/* Relinquish the ownership granted for STREAM. */
461extern void funlockfile __P ((FILE *__stream));
462#endif /* POSIX || misc */
463
464#if defined __USE_XOPEN && !defined __USE_GNU
465/* The X/Open standard requires some functions and variables to be
466 declared here which do not belong into this header. But we have to
467 follow. In GNU mode we don't do this nonsense. */
468# define __need_getopt
469# include <getopt.h>
470#endif
471
472/* If we are compiling with optimizing read this file. It contains
473 several optizing inline functions and macros. */
474#ifdef __USE_EXTERN_INLINES
475# include <bits/stdio.h>
476#endif
477
478__END_DECLS
479
480#endif /* !_STDIO_H */
This page took 0.091496 seconds and 4 git commands to generate.