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 #ifndef __rtems__
59
60 #define _DEFAULT_SOURCE
61 #include <_ansi.h>
62 #include <stdio.h>
63
64 /* Subroutine versions of the inline or macro functions. */
65
66 size_t
__fbufsize(FILE * fp)67 __fbufsize (FILE * fp)
68 {
69 return (size_t) fp->_bf._size;
70 }
71
72 size_t
__fpending(FILE * fp)73 __fpending (FILE * fp)
74 {
75 return fp->_p - fp->_bf._base;
76 }
77
78 int
__flbf(FILE * fp)79 __flbf (FILE * fp)
80 {
81 return (fp->_flags & __SLBF) != 0;
82 }
83
84 int
__freadable(FILE * fp)85 __freadable (FILE * fp)
86 {
87 return (fp->_flags & (__SRD | __SRW)) != 0;
88 }
89
90 int
__fwritable(FILE * fp)91 __fwritable (FILE * fp)
92 {
93 return (fp->_flags & (__SWR | __SRW)) != 0;
94 }
95
96 int
__freading(FILE * fp)97 __freading (FILE * fp)
98 {
99 return (fp->_flags & __SRD) != 0;
100 }
101
102 int
__fwriting(FILE * fp)103 __fwriting (FILE * fp)
104 {
105 return (fp->_flags & __SWR) != 0;
106 }
107
108 #endif /* __rtems__ */
109