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 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
35 #include <stdio_ext.h>
38 * Returns non-zero if the file is open readonly, or if the last operation
39 * on the stream was a read e.g. fread() or fgetc(). Otherwise returns 0.
42 __freading(FILE *stream
)
44 return (stream
->_flag
& _IOREAD
);
48 * Returns non-zero if the file is open write-only or append-only, or if
49 * the last operation on the stream was a write e.g. fwrite() or fputc().
50 * Otherwise returns 0.
53 __fwriting(FILE *stream
)
55 return (stream
->_flag
& _IOWRT
);
59 * Returns non-zero if it is possible to read from a stream.
62 __freadable(FILE *stream
)
64 return (stream
->_flag
& (_IOREAD
|_IORW
));
68 * Returns non-zero if it is possible to write on a stream.
71 __fwritable(FILE *stream
)
73 return (stream
->_flag
& (_IOWRT
|_IORW
));
77 * Returns non-zero if the stream is line buffered.
82 return (stream
->_flag
& _IOLBF
);
86 * Discard any pending buffered I/O.
89 __fpurge(FILE *stream
)
93 FLOCKFILE(lk
, stream
);
94 if ((stream
->_ptr
= stream
->_base
) != NULL
)
100 * Return the amount of output pending on a stream (in bytes).
103 __fpending(FILE *stream
)
108 FLOCKFILE(lk
, stream
);
109 amount
= stream
->_ptr
- stream
->_base
;
115 * Returns the buffer size (in bytes) currently in use by the given stream.
118 __fbufsize(FILE *stream
)
123 FLOCKFILE(lk
, stream
);
124 size
= _bufend(stream
) - stream
->_base
;