xref: /titanic_50/usr/src/ucbhead/stdio.h (revision 4870e0a7381ec2ec57437062574e6ddc3dd48d7f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * User-visible pieces of the ANSI C standard I/O package.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifndef _STDIO_H
457c478bd9Sstevel@tonic-gate #define	_STDIO_H
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
487c478bd9Sstevel@tonic-gate #include <sys/va_list.h>
497c478bd9Sstevel@tonic-gate #include <stdio_tag.h>
507c478bd9Sstevel@tonic-gate #include <stdio_impl.h>
51*4870e0a7SRichard PALO #include <sys/null.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #ifdef __cplusplus
547c478bd9Sstevel@tonic-gate extern "C" {
557c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #ifndef BSD
587c478bd9Sstevel@tonic-gate #define	BSD
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #ifndef _SIZE_T
627c478bd9Sstevel@tonic-gate #define	_SIZE_T
637c478bd9Sstevel@tonic-gate #if !defined(_LP64) && defined(__cplusplus)
647c478bd9Sstevel@tonic-gate typedef unsigned int	size_t;
657c478bd9Sstevel@tonic-gate #else
667c478bd9Sstevel@tonic-gate typedef unsigned long	size_t;
677c478bd9Sstevel@tonic-gate #endif
687c478bd9Sstevel@tonic-gate #endif
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifndef _SSIZE_T
717c478bd9Sstevel@tonic-gate #define	_SSIZE_T
727c478bd9Sstevel@tonic-gate #if !defined(_LP64) && defined(__cplusplus)
737c478bd9Sstevel@tonic-gate typedef int	ssize_t;
747c478bd9Sstevel@tonic-gate #else
757c478bd9Sstevel@tonic-gate typedef long	ssize_t;
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate typedef long	fpos_t;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	BUFSIZ		1024
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #if defined(__i386)
847c478bd9Sstevel@tonic-gate #define	_NFILE	60	/* initial number of streams: Intel x86 ABI */
857c478bd9Sstevel@tonic-gate #else
867c478bd9Sstevel@tonic-gate #define	_NFILE	20	/* initial number of streams: SPARC ABI and default */
877c478bd9Sstevel@tonic-gate #endif
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	_SBFSIZ	8	/* compatibility with shared libs */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define	_IOFBF		0000	/* full buffered */
927c478bd9Sstevel@tonic-gate #define	_IOLBF		0100	/* line buffered */
937c478bd9Sstevel@tonic-gate #define	_IONBF		0004	/* not buffered */
947c478bd9Sstevel@tonic-gate #define	_IOEOF		0020	/* EOF reached on read */
957c478bd9Sstevel@tonic-gate #define	_IOERR		0040	/* I/O error from system */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	_IOREAD		0001	/* currently reading */
987c478bd9Sstevel@tonic-gate #define	_IOWRT		0002	/* currently writing */
997c478bd9Sstevel@tonic-gate #define	_IORW		0200	/* opened for reading and writing */
1007c478bd9Sstevel@tonic-gate #define	_IOMYBUF	0010	/* stdio malloc()'d buffer */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate #ifndef EOF
1037c478bd9Sstevel@tonic-gate #define	EOF	(-1)
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define	FOPEN_MAX	_NFILE
1077c478bd9Sstevel@tonic-gate #define	FILENAME_MAX    1024	/* max # of characters in a path name */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define	SEEK_SET	0
1107c478bd9Sstevel@tonic-gate #define	SEEK_CUR	1
1117c478bd9Sstevel@tonic-gate #define	SEEK_END	2
1127c478bd9Sstevel@tonic-gate #define	TMP_MAX		17576	/* 26 * 26 * 26 */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
1157c478bd9Sstevel@tonic-gate #define	L_ctermid	9
1167c478bd9Sstevel@tonic-gate #define	L_cuserid	9
1177c478bd9Sstevel@tonic-gate #define	P_tmpdir	"/var/tmp/"
1187c478bd9Sstevel@tonic-gate #endif
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	L_tmpnam	25	/* (sizeof(P_tmpdir) + 15) */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #define	stdin	(&__iob[0])
1237c478bd9Sstevel@tonic-gate #define	stdout	(&__iob[1])
1247c478bd9Sstevel@tonic-gate #define	stderr	(&__iob[2])
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #ifndef	_FILEDEFED
1277c478bd9Sstevel@tonic-gate #define	_FILEDEFED
1287c478bd9Sstevel@tonic-gate typedef	__FILE FILE;
1297c478bd9Sstevel@tonic-gate #endif
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern FILE		__iob[_NFILE];
1327c478bd9Sstevel@tonic-gate extern FILE		*_lastbuf;
1337c478bd9Sstevel@tonic-gate extern unsigned char 	*_bufendtab[];
1347c478bd9Sstevel@tonic-gate extern unsigned char	 _sibuf[], _sobuf[];
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /* Large file interfaces */
1377c478bd9Sstevel@tonic-gate /* transition back from explicit 64-bit offset to implicit (64-bit) offset */
1387c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
1397c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
1407c478bd9Sstevel@tonic-gate #pragma redefine_extname	fopen64		fopen
1417c478bd9Sstevel@tonic-gate #pragma redefine_extname	freopen64	freopen
1427c478bd9Sstevel@tonic-gate #else
1437c478bd9Sstevel@tonic-gate #define	fopen64			fopen
1447c478bd9Sstevel@tonic-gate #define	freopen64		freopen
1457c478bd9Sstevel@tonic-gate #endif
1467c478bd9Sstevel@tonic-gate #endif
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* transition from 32-bit offset to explicit 64-bit offset */
1497c478bd9Sstevel@tonic-gate #if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
1507c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
1517c478bd9Sstevel@tonic-gate #pragma redefine_extname	fopen		fopen64
1527c478bd9Sstevel@tonic-gate #pragma redefine_extname	freopen		freopen64
1537c478bd9Sstevel@tonic-gate #else
1547c478bd9Sstevel@tonic-gate #define	fopen			fopen64
1557c478bd9Sstevel@tonic-gate #define	freopen			freopen64
1567c478bd9Sstevel@tonic-gate #endif
1577c478bd9Sstevel@tonic-gate #endif
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate extern int	remove(const char *);
1617c478bd9Sstevel@tonic-gate extern int	rename(const char *, const char *);
1627c478bd9Sstevel@tonic-gate extern int	fclose(FILE *);
1637c478bd9Sstevel@tonic-gate extern int	fflush(FILE *);
1647c478bd9Sstevel@tonic-gate extern FILE	*fopen(const char *, const char *);
1657c478bd9Sstevel@tonic-gate extern FILE	*freopen(const char *, const char *, FILE *);
1667c478bd9Sstevel@tonic-gate extern void	setbuf(FILE *, char *);
1677c478bd9Sstevel@tonic-gate extern void	setbuffer(FILE *, char *, int);
1687c478bd9Sstevel@tonic-gate extern int	setlinebuf(FILE *);
1697c478bd9Sstevel@tonic-gate extern int	setvbuf(FILE *, char *, int, size_t);
1707c478bd9Sstevel@tonic-gate /* PRINTFLIKE2 */
1717c478bd9Sstevel@tonic-gate extern int	fprintf(FILE *, const char *, ...);
1727c478bd9Sstevel@tonic-gate /* SCANFLIKE2 */
1737c478bd9Sstevel@tonic-gate extern int	fscanf(FILE *, const char *, ...);
1747c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */
1757c478bd9Sstevel@tonic-gate extern int	printf(const char *, ...);
1767c478bd9Sstevel@tonic-gate /* SCANFLIKE1 */
1777c478bd9Sstevel@tonic-gate extern int	scanf(const char *, ...);
1787c478bd9Sstevel@tonic-gate /* PRINTFLIKE2 */
1797c478bd9Sstevel@tonic-gate extern char	*sprintf(const char *, const char *, ...);
1807c478bd9Sstevel@tonic-gate /* SCANFLIKE2 */
1817c478bd9Sstevel@tonic-gate extern int	sscanf(const char *, const char *, ...);
1827c478bd9Sstevel@tonic-gate extern int	vfprintf(FILE *, const char *, __va_list);
1837c478bd9Sstevel@tonic-gate extern int	vprintf(const char *, __va_list);
1847c478bd9Sstevel@tonic-gate extern char	*vsprintf(char *, char *, __va_list);
1857c478bd9Sstevel@tonic-gate extern int	fgetc(FILE *);
1867c478bd9Sstevel@tonic-gate extern char	*fgets(char *, int, FILE *);
1877c478bd9Sstevel@tonic-gate extern int	fputc(int, FILE *);
1887c478bd9Sstevel@tonic-gate extern int	fputs(const char *, FILE *);
1897c478bd9Sstevel@tonic-gate extern int	getc(FILE *);
1907c478bd9Sstevel@tonic-gate extern int	getchar(void);
1917c478bd9Sstevel@tonic-gate extern char	*gets(char *);
1927c478bd9Sstevel@tonic-gate extern int	putc(int, FILE *);
1937c478bd9Sstevel@tonic-gate extern int	putchar(int);
1947c478bd9Sstevel@tonic-gate extern int	puts(const char *);
1957c478bd9Sstevel@tonic-gate extern int	ungetc(int, FILE *);
1967c478bd9Sstevel@tonic-gate extern size_t	fread(void *, size_t, size_t, FILE *);
1977c478bd9Sstevel@tonic-gate extern size_t	fwrite(const void *, size_t, size_t, FILE *);
1987c478bd9Sstevel@tonic-gate extern int	fgetpos(FILE *, fpos_t *);
1997c478bd9Sstevel@tonic-gate extern int	fseek(FILE *, long, int);
2007c478bd9Sstevel@tonic-gate extern int	fsetpos(FILE *, const fpos_t *);
2017c478bd9Sstevel@tonic-gate extern long	ftell(FILE *);
2027c478bd9Sstevel@tonic-gate extern void	rewind(FILE *);
2037c478bd9Sstevel@tonic-gate extern void	clearerr(FILE *);
2047c478bd9Sstevel@tonic-gate extern int	feof(FILE *);
2057c478bd9Sstevel@tonic-gate extern int	ferror(FILE *);
2067c478bd9Sstevel@tonic-gate extern void	perror(const char *);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate extern int	__filbuf(FILE *);
2097c478bd9Sstevel@tonic-gate extern int	__flsbuf(int, FILE *);
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
2127c478bd9Sstevel@tonic-gate 	/* non-ANSI standard compilation */
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate extern FILE    *fdopen(int, const char *);
2157c478bd9Sstevel@tonic-gate extern FILE    *popen(const char *, const char *);
2167c478bd9Sstevel@tonic-gate extern char    *ctermid(char *);
2177c478bd9Sstevel@tonic-gate extern char    *cuserid(char *);
2187c478bd9Sstevel@tonic-gate extern char    *tempnam(const char *, const char *);
2197c478bd9Sstevel@tonic-gate extern int	getw(FILE *);
2207c478bd9Sstevel@tonic-gate extern int	putw(int, FILE *);
2217c478bd9Sstevel@tonic-gate extern int	pclose(FILE *);
2227c478bd9Sstevel@tonic-gate extern int	system(const char *);
2237c478bd9Sstevel@tonic-gate extern int	fileno(FILE *);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #endif	/* !defined(_STRICT_STDC) */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate #ifndef __lint
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate #ifndef _LP64
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #define	getc(p)		(--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
2347c478bd9Sstevel@tonic-gate #define	putc(x, p)	(--(p)->_cnt < 0 ? __flsbuf((x), (p)) \
2357c478bd9Sstevel@tonic-gate 				: (int)(*(p)->_ptr++ = (x)))
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate #define	clearerr(p)	((void) ((p)->_flag &= ~(_IOERR | _IOEOF)))
2397c478bd9Sstevel@tonic-gate #define	feof(p)		((p)->_flag & _IOEOF)
2407c478bd9Sstevel@tonic-gate #define	ferror(p)	((p)->_flag & _IOERR)
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate #endif /* _LP64 */
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate #define	getchar()	getc(stdin)
2457c478bd9Sstevel@tonic-gate #define	putchar(x)	putc((x), stdout)
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate #endif /* __lint */
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2507c478bd9Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2517c478bd9Sstevel@tonic-gate extern FILE	*fopen64(const char *, const char *);
2527c478bd9Sstevel@tonic-gate extern FILE	*freopen64(const char *, const char *, FILE *);
2537c478bd9Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE... */
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate #endif
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate #endif	/* _STDIO_H */
260