4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * stdiom.h - shared guts of stdio
37 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
47 extern __FILE __iob
[_NFILE
];
50 * The following flags, and the macros that manipulate them, operate upon
51 * the FILE structure used by stdio. If new flags are required, they should
52 * be created in this file. The values of the flags must be differnt from
53 * the currently used values. New macros should be created to use the flags
54 * so that the compilation mode dependencies can be isolated here.
58 #define _BYTE_MODE_FLAG 0400
59 #define _WC_MODE_FLAG 01000
60 #define _IONOLOCK 02000
61 #define _SEEKABLE 04000 /* is it seekable? */
62 #define SET_IONOLOCK(iop) ((iop)->_flag |= _IONOLOCK)
63 #define CLEAR_IONOLOCK(iop) ((iop)->_flag &= ~_IONOLOCK)
64 #define GET_IONOLOCK(iop) ((iop)->_flag & _IONOLOCK)
65 #define SET_BYTE_MODE(iop) ((iop)->_flag |= _BYTE_MODE_FLAG)
66 #define CLEAR_BYTE_MODE(iop) ((iop)->_flag &= ~_BYTE_MODE_FLAG)
67 #define GET_BYTE_MODE(iop) ((iop)->_flag & _BYTE_MODE_FLAG)
68 #define SET_WC_MODE(iop) ((iop)->_flag |= _WC_MODE_FLAG)
69 #define CLEAR_WC_MODE(iop) ((iop)->_flag &= ~_WC_MODE_FLAG)
70 #define GET_WC_MODE(iop) ((iop)->_flag & _WC_MODE_FLAG)
71 #define GET_NO_MODE(iop) (!((iop)->_flag & \
72 (_BYTE_MODE_FLAG | _WC_MODE_FLAG)))
73 #define SET_SEEKABLE(iop) ((iop)->_flag |= _SEEKABLE)
74 #define CLEAR_SEEKABLE(iop) ((iop)->_flag &= ~_SEEKABLE)
75 #define GET_SEEKABLE(iop) ((iop)->_flag & _SEEKABLE)
77 #define _BYTE_MODE_FLAG 0001
78 #define _WC_MODE_FLAG 0002
79 #define SET_IONOLOCK(iop) ((iop)->__ionolock = 1)
80 #define CLEAR_IONOLOCK(iop) ((iop)->__ionolock = 0)
81 #define GET_IONOLOCK(iop) ((iop)->__ionolock)
82 #define SET_BYTE_MODE(iop) ((iop)->__orientation |= _BYTE_MODE_FLAG)
83 #define CLEAR_BYTE_MODE(iop) ((iop)->__orientation &= ~_BYTE_MODE_FLAG)
84 #define GET_BYTE_MODE(iop) ((iop)->__orientation & _BYTE_MODE_FLAG)
85 #define SET_WC_MODE(iop) ((iop)->__orientation |= _WC_MODE_FLAG)
86 #define CLEAR_WC_MODE(iop) ((iop)->__orientation &= ~_WC_MODE_FLAG)
87 #define GET_WC_MODE(iop) ((iop)->__orientation & _WC_MODE_FLAG)
88 #define GET_NO_MODE(iop) (!((iop)->__orientation & \
89 (_BYTE_MODE_FLAG | _WC_MODE_FLAG)))
90 #define SET_SEEKABLE(iop) ((iop)->__seekable = 1)
91 #define CLEAR_SEEKABLE(iop) ((iop)->__seekable = 0)
92 #define GET_SEEKABLE(iop) ((iop)->__seekable)
94 /* Is iop a member of the _iob array? */
95 #define STDIOP(iop) ((iop) >= &_iob[0] && (iop) < &_iob[_NFILE])
97 /* Compute the index of an _iob array member */
98 #define IOPIND(iop) ((iop) - &_iob[0])
102 typedef unsigned char Uchar
;
104 #define _flockrel(rl) cancel_safe_mutex_unlock(rl)
106 #define MAXVAL (MAXINT - (MAXINT % BUFSIZ))
109 * The number of actual pushback characters is the value
110 * of PUSHBACK plus the first byte of the buffer. The FILE buffer must,
111 * for performance reasons, start on a word aligned boundry so the value
112 * of PUSHBACK should be a multiple of word.
113 * At least 4 bytes of PUSHBACK are needed. If sizeof (int) = 1 this breaks.
115 #define PUSHBACK (((3 + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
117 /* minimum buffer size must be at least 8 or shared library will break */
118 #define _SMBFSZ (((PUSHBACK + 4) < 8) ? 8 : (PUSHBACK + 4))
121 #define MULTIBFSZ(SZ) ((SZ) & ~0x3ff)
123 #define MULTIBFSZ(SZ) ((SZ) & ~0x1ff)
125 #define MULTIBFSZ(SZ) ((SZ) - (SZ % BUFSIZ))
129 #define _bufend(iop) _realbufend(iop)
134 extern Uchar _smbuf
[][_SMBFSZ
];
138 * Internal routines from flush.c
140 extern void __cleanup(void);
141 extern void _flushlbf(void);
142 extern FILE *_findiop(void);
145 * this is to be found in <stdio.h> for 32bit mode
148 extern int __filbuf(FILE *);
149 extern int __flsbuf(int, FILE *);
152 * Not needed as a function in 64 bit mode.
154 #define _realbufend(iop) ((iop)->_end)
156 extern Uchar
*_realbufend(FILE *iop
);
157 extern rmutex_t
*_reallock(FILE *iop
);
160 extern void _setbufend(FILE *iop
, Uchar
*end
);
161 extern rmutex_t
*_flockget(FILE *iop
);
162 extern int _xflsbuf(FILE *iop
);
163 extern int _wrtchk(FILE *iop
);
164 extern void _bufsync(FILE *iop
, Uchar
*bufend
);
165 extern int _fflush_u(FILE *iop
);
166 extern int close_fd(FILE *iop
);
167 extern int _doscan(FILE *, const char *, va_list);
169 extern void close_pid(void);
173 * Internal routines from flush.c
175 extern int _file_get(FILE *);
176 extern int _file_set(FILE *, int, const char *);
179 * Macros to aid the extended fd FILE work.
180 * This helps isolate the changes to only the 32-bit code
181 * since 64-bit Solaris is not affected by this.
184 #define GET_FD(iop) ((iop)->_file)
185 #define SET_FILE(iop, fd) ((iop)->_file = (fd))
187 #define GET_FD(iop) \
188 (((iop)->__extendedfd) ? _file_get(iop) : (iop)->_magic)
189 #define SET_FILE(iop, fd) (iop)->_magic = (fd); (iop)->__extendedfd = 0
193 * Maximum size of the file descriptor stored in the FILE structure.
197 #define _FILE_FD_MAX INT_MAX
199 #define _FILE_FD_MAX 255
203 * Internal routines from fileno.c
205 extern int _fileno(FILE *iop
);
208 * Internal routines from _findbuf.c
210 extern Uchar
*_findbuf(FILE *iop
);
213 * Internal routine used by fopen.c
215 extern FILE *_endopen(const char *, const char *, FILE *, int);
218 * Internal routine from fwrite.c
220 extern size_t _fwrite_unlocked(const void *, size_t, size_t, FILE *);
223 * Internal routine from getc.c
225 int _getc_unlocked(FILE *);
228 * Internal routine from put.c
230 int _putc_unlocked(int, FILE *);
233 * Internal routine from ungetc.c
235 int _ungetc_unlocked(int, FILE *);
238 * The following macros improve performance of the stdio by reducing the
239 * number of calls to _bufsync and _wrtchk. _needsync checks whether
240 * or not _bufsync needs to be called. _WRTCHK has the same effect as
241 * _wrtchk, but often these functions have no effect, and in those cases
242 * the macros avoid the expense of calling the functions.
245 #define _needsync(p, bufend) ((bufend - (p)->_ptr) < \
246 ((p)->_cnt < 0 ? 0 : (p)->_cnt))
248 #define _WRTCHK(iop) ((((iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT) || \
249 (iop->_base == 0) || \
250 (iop->_ptr == iop->_base && iop->_cnt == 0 && \
251 !(iop->_flag & (_IONBF | _IOLBF)))) \
255 #define IOB_LCK(iop) (&((iop)->_lock))
257 #define IOB_LCK(iop) (STDIOP(iop) ? &_xftab[IOPIND(iop)]._lock \
260 extern struct xFILEdata _xftab
[];
264 #endif /* _STDIOM_H */