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