dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / port / stdio / __extensions.c
blobe5620dd44642ff4006c22a183370845ef44573db
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "lint.h"
30 #include "file64.h"
31 #include <sys/types.h>
32 #include <stdio.h>
33 #include <mtlib.h>
34 #include "stdiom.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.
41 int
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.
52 int
53 __fwriting(FILE *stream)
55 return (stream->_flag & _IOWRT);
59 * Returns non-zero if it is possible to read from a stream.
61 int
62 __freadable(FILE *stream)
64 return (stream->_flag & (_IOREAD|_IORW));
68 * Returns non-zero if it is possible to write on a stream.
70 int
71 __fwritable(FILE *stream)
73 return (stream->_flag & (_IOWRT|_IORW));
77 * Returns non-zero if the stream is line buffered.
79 int
80 __flbf(FILE *stream)
82 return (stream->_flag & _IOLBF);
86 * Discard any pending buffered I/O.
88 void
89 __fpurge(FILE *stream)
91 rmutex_t *lk;
93 FLOCKFILE(lk, stream);
94 if ((stream->_ptr = stream->_base) != NULL)
95 stream->_cnt = 0;
96 FUNLOCKFILE(lk);
100 * Return the amount of output pending on a stream (in bytes).
102 size_t
103 __fpending(FILE *stream)
105 size_t amount;
106 rmutex_t *lk;
108 FLOCKFILE(lk, stream);
109 amount = stream->_ptr - stream->_base;
110 FUNLOCKFILE(lk);
111 return (amount);
115 * Returns the buffer size (in bytes) currently in use by the given stream.
117 size_t
118 __fbufsize(FILE *stream)
120 size_t size;
121 rmutex_t *lk;
123 FLOCKFILE(lk, stream);
124 size = _bufend(stream) - stream->_base;
125 FUNLOCKFILE(lk);
126 return (size);