10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*6812Sraf * Common Development and Distribution License (the "License"). 6*6812Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*6812Sraf 220Sstevel@tonic-gate /* 23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 29*6812Sraf #include "lint.h" 300Sstevel@tonic-gate #include "file64.h" 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <stdio.h> 330Sstevel@tonic-gate #include <mtlib.h> 340Sstevel@tonic-gate #include "stdiom.h" 350Sstevel@tonic-gate #include <stdio_ext.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate /* 380Sstevel@tonic-gate * Returns non-zero if the file is open readonly, or if the last operation 390Sstevel@tonic-gate * on the stream was a read e.g. fread() or fgetc(). Otherwise returns 0. 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate int __freading(FILE * stream)420Sstevel@tonic-gate__freading(FILE *stream) 430Sstevel@tonic-gate { 440Sstevel@tonic-gate return (stream->_flag & _IOREAD); 450Sstevel@tonic-gate } 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * Returns non-zero if the file is open write-only or append-only, or if 490Sstevel@tonic-gate * the last operation on the stream was a write e.g. fwrite() or fputc(). 500Sstevel@tonic-gate * Otherwise returns 0. 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate int __fwriting(FILE * stream)530Sstevel@tonic-gate__fwriting(FILE *stream) 540Sstevel@tonic-gate { 550Sstevel@tonic-gate return (stream->_flag & _IOWRT); 560Sstevel@tonic-gate } 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * Returns non-zero if it is possible to read from a stream. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate int __freadable(FILE * stream)620Sstevel@tonic-gate__freadable(FILE *stream) 630Sstevel@tonic-gate { 640Sstevel@tonic-gate return (stream->_flag & (_IOREAD|_IORW)); 650Sstevel@tonic-gate } 660Sstevel@tonic-gate 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * Returns non-zero if it is possible to write on a stream. 690Sstevel@tonic-gate */ 700Sstevel@tonic-gate int __fwritable(FILE * stream)710Sstevel@tonic-gate__fwritable(FILE *stream) 720Sstevel@tonic-gate { 730Sstevel@tonic-gate return (stream->_flag & (_IOWRT|_IORW)); 740Sstevel@tonic-gate } 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * Returns non-zero if the stream is line buffered. 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate int __flbf(FILE * stream)800Sstevel@tonic-gate__flbf(FILE *stream) 810Sstevel@tonic-gate { 820Sstevel@tonic-gate return (stream->_flag & _IOLBF); 830Sstevel@tonic-gate } 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Discard any pending buffered I/O. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate void __fpurge(FILE * stream)890Sstevel@tonic-gate__fpurge(FILE *stream) 900Sstevel@tonic-gate { 910Sstevel@tonic-gate rmutex_t *lk; 920Sstevel@tonic-gate 930Sstevel@tonic-gate FLOCKFILE(lk, stream); 940Sstevel@tonic-gate if ((stream->_ptr = stream->_base) != NULL) 950Sstevel@tonic-gate stream->_cnt = 0; 960Sstevel@tonic-gate FUNLOCKFILE(lk); 970Sstevel@tonic-gate } 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * Return the amount of output pending on a stream (in bytes). 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate size_t __fpending(FILE * stream)1030Sstevel@tonic-gate__fpending(FILE *stream) 1040Sstevel@tonic-gate { 1050Sstevel@tonic-gate size_t amount; 1060Sstevel@tonic-gate rmutex_t *lk; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate FLOCKFILE(lk, stream); 1090Sstevel@tonic-gate amount = stream->_ptr - stream->_base; 1100Sstevel@tonic-gate FUNLOCKFILE(lk); 1110Sstevel@tonic-gate return (amount); 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate /* 1150Sstevel@tonic-gate * Returns the buffer size (in bytes) currently in use by the given stream. 1160Sstevel@tonic-gate */ 1170Sstevel@tonic-gate size_t __fbufsize(FILE * stream)1180Sstevel@tonic-gate__fbufsize(FILE *stream) 1190Sstevel@tonic-gate { 1200Sstevel@tonic-gate size_t size; 1210Sstevel@tonic-gate rmutex_t *lk; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate FLOCKFILE(lk, stream); 1240Sstevel@tonic-gate size = _bufend(stream) - stream->_base; 1250Sstevel@tonic-gate FUNLOCKFILE(lk); 1260Sstevel@tonic-gate return (size); 1270Sstevel@tonic-gate } 128