xref: /minix3/include/stdio.h (revision 58a2b0008e28f606a7f7f5faaeaba4faac57a1ea)
1 /*
2  * stdio.h - input/output definitions
3  *
4  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
5  * See the copyright notice in the ACK home directory, in the file "Copyright".
6  */
7 /* $Header$ */
8 
9 #ifndef _STDIO_H
10 #define	_STDIO_H
11 
12 #ifndef _MINIX_ANSI_H
13 #include <minix/ansi.h>
14 #endif
15 #include <minix/types.h>
16 
17 #include <sys/null.h>   /* For NULL */
18 
19 /*
20  * Focus point of all stdio activity.
21  */
22 typedef struct __iobuf {
23 	int		_count;
24 	int		_fd;
25 	int		_flags;
26 	int		_bufsiz;
27 	unsigned char	*_buf;
28 	unsigned char	*_ptr;
29 } FILE;
30 
31 #define	_IOFBF		0x000
32 #define	_IOREAD		0x001
33 #define	_IOWRITE	0x002
34 #define	_IONBF		0x004
35 #define	_IOMYBUF	0x008
36 #define	_IOEOF		0x010
37 #define	_IOERR		0x020
38 #define	_IOLBF		0x040
39 #define	_IOREADING	0x080
40 #define	_IOWRITING	0x100
41 #define	_IOAPPEND	0x200
42 #define _IOFIFO		0x400
43 
44 /* The following definitions are also in <unistd.h>. They should not
45  * conflict.
46  */
47 #define	SEEK_SET	0
48 #define	SEEK_CUR	1
49 #define	SEEK_END	2
50 
51 #define	stdin		(&__stdin)
52 #define	stdout		(&__stdout)
53 #define	stderr		(&__stderr)
54 
55 #define	BUFSIZ		4096
56 #define	EOF		(-1)
57 
58 #define	FOPEN_MAX	20
59 
60 #define	FILENAME_MAX	NAME_MAX
61 
62 #define	TMP_MAX		999
63 #define	L_tmpnam	(sizeof("/tmp/") + FILENAME_MAX)
64 #define P_tmpdir "/tmp"
65 #define __STDIO_VA_LIST__	void *
66 
67 typedef long int	fpos_t;
68 
69 #ifndef _SIZE_T
70 #define	_SIZE_T
71 typedef unsigned int	size_t;		/* type returned by sizeof */
72 #endif /* _SIZE_T */
73 
74 extern FILE	*__iotab[FOPEN_MAX];
75 extern FILE	__stdin, __stdout, __stderr;
76 
77 _PROTOTYPE( int remove, (const char *_filename)				);
78 _PROTOTYPE( int rename, (const char *_old, const char *_new)		);
79 _PROTOTYPE( FILE *tmpfile, (void)					);
80 _PROTOTYPE( char *tmpnam, (char *_s)					);
81 _PROTOTYPE( int fclose, (FILE *_stream)					);
82 _PROTOTYPE( int fflush, (FILE *_stream)					);
83 _PROTOTYPE( FILE *fopen, (const char *_filename, const char *_mode)	);
84 _PROTOTYPE( FILE *freopen,
85 	    (const char *_filename, const char *_mode, FILE *_stream)	);
86 _PROTOTYPE( void setbuf, (FILE *_stream, char *_buf)			);
87 _PROTOTYPE( int setvbuf,
88 		(FILE *_stream, char *_buf, int _mode, size_t _size)	);
89 _PROTOTYPE( int fprintf, (FILE *_stream, const char *_format, ...)	);
90 _PROTOTYPE( int printf, (const char *_format, ...)			);
91 _PROTOTYPE( int sprintf, (char *_s, const char *_format, ...)		);
92 _PROTOTYPE( int vfprintf,
93 		(FILE *_stream, const char *_format, char *_arg)	);
94 _PROTOTYPE( int vprintf, (const char *_format, char *_arg)		);
95 _PROTOTYPE( int vsprintf, (char *_s, const char *_format, char *_arg)	);
96 _PROTOTYPE( int fscanf, (FILE *_stream, const char *_format, ...)	);
97 _PROTOTYPE( int scanf, (const char *_format, ...)			);
98 _PROTOTYPE( int sscanf, (const char *_s, const char *_format, ...)	);
99 #define vfscanf _doscan
100 _PROTOTYPE( int vfscanf, (FILE *_stream, const char *_format, char *_arg));
101 _PROTOTYPE( int vscanf, (const char *_format, char *_arg)		);
102 _PROTOTYPE( int vsscanf, (const char *_s, const char *_format, char *_arg));
103 _PROTOTYPE( int fgetc, (FILE *_stream)					);
104 _PROTOTYPE( char *fgets, (char *_s, int _n, FILE *_stream)		);
105 _PROTOTYPE( int fputc, (int _c, FILE *_stream)				);
106 _PROTOTYPE( int fputs, (const char *_s, FILE *_stream)			);
107 _PROTOTYPE( int getc, (FILE *_stream)					);
108 _PROTOTYPE( int getchar, (void)						);
109 _PROTOTYPE( char *gets, (char *_s)					);
110 _PROTOTYPE( int putc, (int _c, FILE *_stream)				);
111 _PROTOTYPE( int putchar, (int _c)					);
112 _PROTOTYPE( int puts, (const char *_s)					);
113 _PROTOTYPE( int ungetc, (int _c, FILE *_stream)				);
114 _PROTOTYPE( size_t fread,
115 	    (void *_ptr, size_t _size, size_t _nmemb, FILE *_stream)	);
116 _PROTOTYPE( size_t fwrite,
117 	(const void *_ptr, size_t _size, size_t _nmemb, FILE *_stream)	);
118 _PROTOTYPE( int fgetpos, (FILE *_stream, fpos_t *_pos)			);
119 _PROTOTYPE( int fseek, (FILE *_stream, long _offset, int _whence)	);
120 _PROTOTYPE( int fseeko, (FILE *_stream, off_t _offset, int _whence)	);
121 _PROTOTYPE( int fsetpos, (FILE *_stream, fpos_t *_pos)			);
122 _PROTOTYPE( long ftell, (FILE *_stream)					);
123 _PROTOTYPE( off_t ftello, (FILE *_stream)				);
124 _PROTOTYPE( void rewind, (FILE *_stream)				);
125 _PROTOTYPE( void clearerr, (FILE *_stream)				);
126 _PROTOTYPE( int feof, (FILE *_stream)					);
127 _PROTOTYPE( int ferror, (FILE *_stream)					);
128 _PROTOTYPE( void perror, (const char *_s)				);
129 _PROTOTYPE( int __fillbuf, (FILE *_stream)				);
130 _PROTOTYPE( int __flushbuf, (int _c, FILE *_stream)			);
131 
132 #define	getchar()	getc(stdin)
133 #define	putchar(c)	putc(c,stdout)
134 #define	getc(p)		(--(p)->_count >= 0 ? (int) (*(p)->_ptr++) : \
135 				__fillbuf(p))
136 #define	putc(c, p)	(--(p)->_count >= 0 ? \
137 			 (int) (*(p)->_ptr++ = (c)) : \
138 			 __flushbuf((c),(p)))
139 
140 #define	feof(p)		(((p)->_flags & _IOEOF) != 0)
141 #define	ferror(p)	(((p)->_flags & _IOERR) != 0)
142 #define clearerr(p)     ((p)->_flags &= ~(_IOERR|_IOEOF))
143 
144 #ifdef _POSIX_SOURCE
145 _PROTOTYPE( int fileno, (FILE *_stream)					);
146 _PROTOTYPE (FILE *fdopen, (int _fildes, const char *_types) );
147 #define	fileno(stream)		((stream)->_fd)
148 #define L_ctermid 255	/* required by POSIX */
149 #define L_cuserid 255	/* required by POSIX */
150 
151 _PROTOTYPE(FILE *popen, (const char *_command, const char *_type));
152 _PROTOTYPE(int pclose, (FILE *_stream));
153 _PROTOTYPE(int snprintf, (char *_s, size_t _n, const char *_format, ...));
154 _PROTOTYPE(int vsnprintf, (char *_s, size_t _n, const char *_format,
155 							char *_arg)	);
156 _PROTOTYPE(char *fgetln, (FILE *stream, size_t *len));
157 #endif
158 
159 #ifdef _MINIX
160 _PROTOTYPE(int asprintf, (char **ret, const char *fmt, ...));
161 _PROTOTYPE(int vasprintf, (char **ret, const char *fmt, char *_arg));
162 #endif /* _MINIX */
163 
164 #endif /* _STDIO_H */
165