xref: /titanic_41/usr/src/ucbhead/stdio.h (revision edb432dd16be68a2fea50d9a0a1e839f16c6bc65)
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 #include <sys/feature_tests.h>
48 #include <sys/va_list.h>
49 #include <stdio_tag.h>
50 #include <stdio_impl.h>
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #ifndef BSD
57 #define	BSD
58 #endif
59 
60 #ifndef _SIZE_T
61 #define	_SIZE_T
62 #if !defined(_LP64) && defined(__cplusplus)
63 typedef unsigned int	size_t;
64 #else
65 typedef unsigned long	size_t;
66 #endif
67 #endif
68 
69 #ifndef _SSIZE_T
70 #define	_SSIZE_T
71 #if !defined(_LP64) && defined(__cplusplus)
72 typedef int	ssize_t;
73 #else
74 typedef long	ssize_t;
75 #endif
76 #endif
77 
78 typedef long	fpos_t;
79 
80 #ifndef NULL
81 #define	NULL		0
82 #endif
83 
84 #define	BUFSIZ		1024
85 
86 #if defined(__i386)
87 #define	_NFILE	60	/* initial number of streams: Intel x86 ABI */
88 #else
89 #define	_NFILE	20	/* initial number of streams: SPARC ABI and default */
90 #endif
91 
92 #define	_SBFSIZ	8	/* compatibility with shared libs */
93 
94 #define	_IOFBF		0000	/* full buffered */
95 #define	_IOLBF		0100	/* line buffered */
96 #define	_IONBF		0004	/* not buffered */
97 #define	_IOEOF		0020	/* EOF reached on read */
98 #define	_IOERR		0040	/* I/O error from system */
99 
100 #define	_IOREAD		0001	/* currently reading */
101 #define	_IOWRT		0002	/* currently writing */
102 #define	_IORW		0200	/* opened for reading and writing */
103 #define	_IOMYBUF	0010	/* stdio malloc()'d buffer */
104 
105 #ifndef EOF
106 #define	EOF	(-1)
107 #endif
108 
109 #define	FOPEN_MAX	_NFILE
110 #define	FILENAME_MAX    1024	/* max # of characters in a path name */
111 
112 #define	SEEK_SET	0
113 #define	SEEK_CUR	1
114 #define	SEEK_END	2
115 #define	TMP_MAX		17576	/* 26 * 26 * 26 */
116 
117 #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
118 #define	L_ctermid	9
119 #define	L_cuserid	9
120 #define	P_tmpdir	"/var/tmp/"
121 #endif
122 
123 #define	L_tmpnam	25	/* (sizeof(P_tmpdir) + 15) */
124 
125 #define	stdin	(&__iob[0])
126 #define	stdout	(&__iob[1])
127 #define	stderr	(&__iob[2])
128 
129 #ifndef	_FILEDEFED
130 #define	_FILEDEFED
131 typedef	__FILE FILE;
132 #endif
133 
134 extern FILE		__iob[_NFILE];
135 extern FILE		*_lastbuf;
136 extern unsigned char 	*_bufendtab[];
137 extern unsigned char	 _sibuf[], _sobuf[];
138 
139 /* Large file interfaces */
140 /* transition back from explicit 64-bit offset to implicit (64-bit) offset */
141 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
142 #ifdef __PRAGMA_REDEFINE_EXTNAME
143 #pragma redefine_extname	fopen64		fopen
144 #pragma redefine_extname	freopen64	freopen
145 #else
146 #define	fopen64			fopen
147 #define	freopen64		freopen
148 #endif
149 #endif
150 
151 /* transition from 32-bit offset to explicit 64-bit offset */
152 #if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
153 #ifdef __PRAGMA_REDEFINE_EXTNAME
154 #pragma redefine_extname	fopen		fopen64
155 #pragma redefine_extname	freopen		freopen64
156 #else
157 #define	fopen			fopen64
158 #define	freopen			freopen64
159 #endif
160 #endif
161 
162 
163 extern int	remove(const char *);
164 extern int	rename(const char *, const char *);
165 extern int	fclose(FILE *);
166 extern int	fflush(FILE *);
167 extern FILE	*fopen(const char *, const char *);
168 extern FILE	*freopen(const char *, const char *, FILE *);
169 extern void	setbuf(FILE *, char *);
170 extern void	setbuffer(FILE *, char *, int);
171 extern int	setlinebuf(FILE *);
172 extern int	setvbuf(FILE *, char *, int, size_t);
173 /* PRINTFLIKE2 */
174 extern int	fprintf(FILE *, const char *, ...);
175 /* SCANFLIKE2 */
176 extern int	fscanf(FILE *, const char *, ...);
177 /* PRINTFLIKE1 */
178 extern int	printf(const char *, ...);
179 /* SCANFLIKE1 */
180 extern int	scanf(const char *, ...);
181 /* PRINTFLIKE2 */
182 extern char	*sprintf(const char *, const char *, ...);
183 /* SCANFLIKE2 */
184 extern int	sscanf(const char *, const char *, ...);
185 extern int	vfprintf(FILE *, const char *, __va_list);
186 extern int	vprintf(const char *, __va_list);
187 extern char	*vsprintf(char *, char *, __va_list);
188 extern int	fgetc(FILE *);
189 extern char	*fgets(char *, int, FILE *);
190 extern int	fputc(int, FILE *);
191 extern int	fputs(const char *, FILE *);
192 extern int	getc(FILE *);
193 extern int	getchar(void);
194 extern char	*gets(char *);
195 extern int	putc(int, FILE *);
196 extern int	putchar(int);
197 extern int	puts(const char *);
198 extern int	ungetc(int, FILE *);
199 extern size_t	fread(void *, size_t, size_t, FILE *);
200 extern size_t	fwrite(const void *, size_t, size_t, FILE *);
201 extern int	fgetpos(FILE *, fpos_t *);
202 extern int	fseek(FILE *, long, int);
203 extern int	fsetpos(FILE *, const fpos_t *);
204 extern long	ftell(FILE *);
205 extern void	rewind(FILE *);
206 extern void	clearerr(FILE *);
207 extern int	feof(FILE *);
208 extern int	ferror(FILE *);
209 extern void	perror(const char *);
210 
211 extern int	__filbuf(FILE *);
212 extern int	__flsbuf(int, FILE *);
213 
214 #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
215 	/* non-ANSI standard compilation */
216 
217 extern FILE    *fdopen(int, const char *);
218 extern FILE    *popen(const char *, const char *);
219 extern char    *ctermid(char *);
220 extern char    *cuserid(char *);
221 extern char    *tempnam(const char *, const char *);
222 extern int	getw(FILE *);
223 extern int	putw(int, FILE *);
224 extern int	pclose(FILE *);
225 extern int	system(const char *);
226 extern int	fileno(FILE *);
227 
228 #endif	/* !defined(_STRICT_STDC) */
229 
230 
231 #ifndef __lint
232 
233 #ifndef _LP64
234 
235 
236 #define	getc(p)		(--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
237 #define	putc(x, p)	(--(p)->_cnt < 0 ? __flsbuf((x), (p)) \
238 				: (int)(*(p)->_ptr++ = (x)))
239 
240 
241 #define	clearerr(p)	((void) ((p)->_flag &= ~(_IOERR | _IOEOF)))
242 #define	feof(p)		((p)->_flag & _IOEOF)
243 #define	ferror(p)	((p)->_flag & _IOERR)
244 
245 #endif /* _LP64 */
246 
247 #define	getchar()	getc(stdin)
248 #define	putchar(x)	putc((x), stdout)
249 
250 #endif /* __lint */
251 
252 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
253 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
254 extern FILE	*fopen64(const char *, const char *);
255 extern FILE	*freopen64(const char *, const char *, FILE *);
256 #endif	/* _LARGEFILE64_SOURCE... */
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif	/* _STDIO_H */
263