xref: /titanic_51/usr/src/ucbhead/stdio.h (revision a31148363f598def767ac48c5d82e1572e44b935)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 /*
41  * User-visible pieces of the ANSI C standard I/O package.
42  */
43 
44 #ifndef _STDIO_H
45 #define	_STDIO_H
46 
47 #pragma ident	"%Z%%M%	%I%	%E% SMI"
48 
49 #include <sys/feature_tests.h>
50 #include <sys/va_list.h>
51 #include <stdio_tag.h>
52 #include <stdio_impl.h>
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #ifndef BSD
59 #define	BSD
60 #endif
61 
62 #ifndef _SIZE_T
63 #define	_SIZE_T
64 #if !defined(_LP64) && defined(__cplusplus)
65 typedef unsigned int	size_t;
66 #else
67 typedef unsigned long	size_t;
68 #endif
69 #endif
70 
71 #ifndef _SSIZE_T
72 #define	_SSIZE_T
73 #if !defined(_LP64) && defined(__cplusplus)
74 typedef int	ssize_t;
75 #else
76 typedef long	ssize_t;
77 #endif
78 #endif
79 
80 typedef long	fpos_t;
81 
82 #ifndef NULL
83 #define	NULL		0
84 #endif
85 
86 #if defined(__STDC__)
87 
88 #if #machine(pdp11)
89 #define	BUFSIZ		512
90 #define	_STDIO_REVERSE
91 #elif #machine(u370)
92 #define	BUFSIZ		4096
93 #define	_STDIO_REVERSE
94 #define	_STDIO_ALLOCATE
95 #else
96 #define	BUFSIZ		1024
97 #endif
98 
99 #else	/* !defined(__STDC__) */
100 
101 #if pdp11 || u370
102 
103 #if pdp11
104 #define	BUFSIZ		512
105 #define	_STDIO_REVERSE
106 #else 	/* u370 */
107 #define	BUFSIZ		4096
108 #define	_STDIO_REVERSE
109 #define	_STDIO_ALLOCATE
110 #endif
111 
112 #else
113 #define	BUFSIZ		1024
114 #endif
115 
116 #endif	/* __STDC__ */
117 
118 #if defined(__i386)
119 #define	_NFILE	60	/* initial number of streams: Intel x86 ABI */
120 #else
121 #define	_NFILE	20	/* initial number of streams: SPARC ABI and default */
122 #endif
123 
124 #define	_SBFSIZ	8	/* compatibility with shared libs */
125 
126 #define	_IOFBF		0000	/* full buffered */
127 #define	_IOLBF		0100	/* line buffered */
128 #define	_IONBF		0004	/* not buffered */
129 #define	_IOEOF		0020	/* EOF reached on read */
130 #define	_IOERR		0040	/* I/O error from system */
131 
132 #define	_IOREAD		0001	/* currently reading */
133 #define	_IOWRT		0002	/* currently writing */
134 #define	_IORW		0200	/* opened for reading and writing */
135 #define	_IOMYBUF	0010	/* stdio malloc()'d buffer */
136 
137 #ifndef EOF
138 #define	EOF	(-1)
139 #endif
140 
141 #define	FOPEN_MAX	_NFILE
142 #define	FILENAME_MAX    1024	/* max # of characters in a path name */
143 
144 #define	SEEK_SET	0
145 #define	SEEK_CUR	1
146 #define	SEEK_END	2
147 #define	TMP_MAX		17576	/* 26 * 26 * 26 */
148 
149 #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
150 #define	L_ctermid	9
151 #define	L_cuserid	9
152 #define	P_tmpdir	"/var/tmp/"
153 #endif
154 
155 #define	L_tmpnam	25	/* (sizeof(P_tmpdir) + 15) */
156 
157 #if defined(__STDC__)
158 #define	stdin	(&__iob[0])
159 #define	stdout	(&__iob[1])
160 #define	stderr	(&__iob[2])
161 #else
162 #define	stdin	(&_iob[0])
163 #define	stdout	(&_iob[1])
164 #define	stderr	(&_iob[2])
165 #endif
166 
167 #ifndef	_FILEDEFED
168 #define	_FILEDEFED
169 typedef	__FILE FILE;
170 #endif
171 
172 #if defined(__STDC__)
173 extern FILE		__iob[_NFILE];
174 #else
175 extern FILE		_iob[_NFILE];
176 #endif
177 extern FILE		*_lastbuf;
178 extern unsigned char 	*_bufendtab[];
179 #ifndef _STDIO_ALLOCATE
180 extern unsigned char	 _sibuf[], _sobuf[];
181 #endif
182 
183 /* Large file interfaces */
184 /* transition back from explicit 64-bit offset to implicit (64-bit) offset */
185 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
186 #ifdef __PRAGMA_REDEFINE_EXTNAME
187 #pragma redefine_extname	fopen64		fopen
188 #pragma redefine_extname	freopen64	freopen
189 #else
190 #define	fopen64			fopen
191 #define	freopen64		freopen
192 #endif
193 #endif
194 
195 /* transition from 32-bit offset to explicit 64-bit offset */
196 #if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
197 #ifdef __PRAGMA_REDEFINE_EXTNAME
198 #pragma redefine_extname	fopen		fopen64
199 #pragma redefine_extname	freopen		freopen64
200 #else
201 #define	fopen			fopen64
202 #define	freopen			freopen64
203 #endif
204 #endif
205 
206 #if defined(__STDC__)
207 
208 extern int	remove(const char *);
209 extern int	rename(const char *, const char *);
210 extern int	fclose(FILE *);
211 extern int	fflush(FILE *);
212 extern FILE	*fopen(const char *, const char *);
213 extern FILE	*freopen(const char *, const char *, FILE *);
214 extern void	setbuf(FILE *, char *);
215 extern void	setbuffer(FILE *, char *, int);
216 extern int	setlinebuf(FILE *);
217 extern int	setvbuf(FILE *, char *, int, size_t);
218 /* PRINTFLIKE2 */
219 extern int	fprintf(FILE *, const char *, ...);
220 /* SCANFLIKE2 */
221 extern int	fscanf(FILE *, const char *, ...);
222 /* PRINTFLIKE1 */
223 extern int	printf(const char *, ...);
224 /* SCANFLIKE1 */
225 extern int	scanf(const char *, ...);
226 /* PRINTFLIKE2 */
227 extern char	*sprintf(const char *, const char *, ...);
228 /* SCANFLIKE2 */
229 extern int	sscanf(const char *, const char *, ...);
230 extern int	vfprintf(FILE *, const char *, __va_list);
231 extern int	vprintf(const char *, __va_list);
232 extern char	*vsprintf(char *, char *, __va_list);
233 extern int	fgetc(FILE *);
234 extern char	*fgets(char *, int, FILE *);
235 extern int	fputc(int, FILE *);
236 extern int	fputs(const char *, FILE *);
237 extern int	getc(FILE *);
238 extern int	getchar(void);
239 extern char	*gets(char *);
240 extern int	putc(int, FILE *);
241 extern int	putchar(int);
242 extern int	puts(const char *);
243 extern int	ungetc(int, FILE *);
244 extern size_t	fread(void *, size_t, size_t, FILE *);
245 extern size_t	fwrite(const void *, size_t, size_t, FILE *);
246 extern int	fgetpos(FILE *, fpos_t *);
247 extern int	fseek(FILE *, long, int);
248 extern int	fsetpos(FILE *, const fpos_t *);
249 extern long	ftell(FILE *);
250 extern void	rewind(FILE *);
251 extern void	clearerr(FILE *);
252 extern int	feof(FILE *);
253 extern int	ferror(FILE *);
254 extern void	perror(const char *);
255 
256 extern int	__filbuf(FILE *);
257 extern int	__flsbuf(int, FILE *);
258 
259 #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
260 	/* non-ANSI standard compilation */
261 
262 extern FILE    *fdopen(int, const char *);
263 extern FILE    *popen(const char *, const char *);
264 extern char    *ctermid(char *);
265 extern char    *cuserid(char *);
266 extern char    *tempnam(const char *, const char *);
267 extern int	getw(FILE *);
268 extern int	putw(int, FILE *);
269 extern int	pclose(FILE *);
270 extern int	system(const char *);
271 extern int	fileno(FILE *);
272 
273 #endif	/* !defined(_STRICT_STDC) */
274 
275 #else	/* !defined __STDC__ */
276 #define	_bufend(p)	_bufendtab[fileno(p)]
277 #define	_bufsiz(p)	(_bufend(p) - (p)->_base)
278 
279 extern FILE	*fopen(), *fdopen(), *freopen(), *popen();
280 extern long	ftell();
281 extern void	rewind(), setbuf(), setbuffer();
282 extern int	setlinebuf();
283 extern char	*ctermid(), *cuserid(), *fgets(), *gets(), *sprintf(),
284 		*vsprintf();
285 extern int	fclose(), fflush(), fread(), fwrite(), fseek(), fgetc(),
286 		getw(), pclose(), printf(), fprintf(),
287 		vprintf(), vfprintf(), fputc(), putw(),
288 		puts(), fputs(), scanf(), fscanf(), sscanf(),
289 		setvbuf(), system(), ungetc();
290 extern int	fileno();
291 extern int	getc(), getchar(), putc(), putchar(), feof(), ferror();
292 extern void	clearerr();
293 
294 #endif	/* __STDC__ */
295 
296 #ifndef __lint
297 
298 #ifndef _LP64
299 
300 #ifdef __STDC__
301 
302 #define	getc(p)		(--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
303 #define	putc(x, p)	(--(p)->_cnt < 0 ? __flsbuf((x), (p)) \
304 				: (int)(*(p)->_ptr++ = (x)))
305 
306 #else /* __STDC__ */
307 
308 #define	getc(p)		(--(p)->_cnt < 0 ? _filbuf(p) : (int)*(p)->_ptr++)
309 #define	putc(x, p)	(--(p)->_cnt < 0 ? \
310 			_flsbuf((unsigned char) (x), (p)) : \
311 			(int)(*(p)->_ptr++ = (unsigned char)(x)))
312 #endif /* __STDC__ */
313 
314 #define	clearerr(p)	((void) ((p)->_flag &= ~(_IOERR | _IOEOF)))
315 #define	feof(p)		((p)->_flag & _IOEOF)
316 #define	ferror(p)	((p)->_flag & _IOERR)
317 
318 #endif /* _LP64 */
319 
320 #define	getchar()	getc(stdin)
321 #define	putchar(x)	putc((x), stdout)
322 
323 #endif /* __lint */
324 
325 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
326 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
327 #if defined(__STDC__)
328 extern FILE	*fopen64(const char *, const char *);
329 extern FILE	*freopen64(const char *, const char *, FILE *);
330 #else
331 extern FILE	*fopen64(), *freopen64();
332 #endif
333 #endif	/* _LARGEFILE64_SOURCE... */
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif	/* _STDIO_H */
340