1 /* Copyright (c) 2014 Yaakov Selkowitz <yselkowi@redhat.com> */
2 /*
3 FUNCTION
4 <<stdio_ext>>,<<__fbufsize>>,<<__fpending>>,<<__flbf>>,<<__freadable>>,<<__fwritable>>,<<__freading>>,<<__fwriting>>---access internals of FILE structure
5 
6 INDEX
7 	__fbufsize
8 INDEX
9 	__fpending
10 INDEX
11 	__flbf
12 INDEX
13 	__freadable
14 INDEX
15 	__fwritable
16 INDEX
17 	__freading
18 INDEX
19 	__fwriting
20 
21 SYNOPSIS
22 	#include <stdio.h>
23 	#include <stdio_ext.h>
24 	size_t __fbufsize(FILE *<[fp]>);
25 	size_t __fpending(FILE *<[fp]>);
26 	int __flbf(FILE *<[fp]>);
27 	int __freadable(FILE *<[fp]>);
28 	int __fwritable(FILE *<[fp]>);
29 	int __freading(FILE *<[fp]>);
30 	int __fwriting(FILE *<[fp]>);
31 
32 DESCRIPTION
33 These functions provides access to the internals of the FILE structure <[fp]>.
34 
35 RETURNS
36 <<__fbufsize>> returns the number of bytes in the buffer of stream <[fp]>.
37 
38 <<__fpending>> returns the number of bytes in the output buffer of stream <[fp]>.
39 
40 <<__flbf>> returns nonzero if stream <[fp]> is line-buffered, and <<0>> if not.
41 
42 <<__freadable>> returns nonzero if stream <[fp]> may be read, and <<0>> if not.
43 
44 <<__fwritable>> returns nonzero if stream <[fp]> may be written, and <<0>> if not.
45 
46 <<__freading>> returns nonzero if stream <[fp]> if the last operation on
47 it was a read, or if it read-only, and <<0>> if not.
48 
49 <<__fwriting>> returns nonzero if stream <[fp]> if the last operation on
50 it was a write, or if it write-only, and <<0>> if not.
51 
52 PORTABILITY
53 These functions originate from Solaris and are also provided by GNU libc.
54 
55 No supporting OS subroutines are required.
56 */
57 
58 #include <picolibc.h>
59 
60 #ifndef __rtems__
61 
62 #define _DEFAULT_SOURCE
63 #include <stdio.h>
64 #include <stdio_ext.h>
65 
66 /* Subroutine versions of the inline or macro functions. */
67 
68 size_t
__fbufsize(FILE * fp)69 __fbufsize (FILE * fp)
70 {
71   return (size_t) fp->_bf._size;
72 }
73 
74 size_t
__fpending(FILE * fp)75 __fpending (FILE * fp)
76 {
77   return fp->_p - fp->_bf._base;
78 }
79 
80 int
__flbf(FILE * fp)81 __flbf (FILE * fp)
82 {
83   return (fp->_flags & __SLBF) != 0;
84 }
85 
86 int
__freadable(FILE * fp)87 __freadable (FILE * fp)
88 {
89   return (fp->_flags & (__SRD | __SRW)) != 0;
90 }
91 
92 int
__fwritable(FILE * fp)93 __fwritable (FILE * fp)
94 {
95   return (fp->_flags & (__SWR | __SRW)) != 0;
96 }
97 
98 int
__freading(FILE * fp)99 __freading (FILE * fp)
100 {
101   return (fp->_flags & __SRD) != 0;
102 }
103 
104 int
__fwriting(FILE * fp)105 __fwriting (FILE * fp)
106 {
107   return (fp->_flags & __SWR) != 0;
108 }
109 
110 #endif /* __rtems__ */
111