xref: /haiku/headers/posix/stdio_post.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 #ifndef _STDIO_POST_H_
2 #define _STDIO_POST_H_
3 /*
4 ** Distributed under the terms of the OpenBeOS License.
5 */
6 
7 
8 // "Private"/inline functions of our BeOS compatible stdio implementation
9 
10 // ToDo: this is a work in progress to make our stdio
11 //		BeOS' GNU/libio (almost) binary compatible
12 //		We are not yet compatible!
13 //		Currently only function names are compatible
14 
15 #ifndef _STDIO_H_
16 #	error "This file must be included from stdio.h!"
17 #endif
18 
19 #ifdef __cplusplus
20 #	define __INLINE inline
21 #else
22 #	define __INLINE extern __inline
23 #endif
24 
25 
26 extern int _IO_feof_unlocked(FILE *stream);
27 extern int _IO_ferror_unlocked(FILE *stream);
28 extern int _IO_putc(int c, FILE *stream);
29 extern int _IO_putc_unlocked(int c, FILE *stream);
30 extern int _IO_getc(FILE *stream);
31 extern int _IO_getc_unlocked(FILE *stream);
32 extern int _IO_peekc_unlocked(FILE *stream);
33 
34 extern int __underflow(FILE *stream);
35 extern int __uflow(FILE *stream);
36 extern int __overflow(FILE *stream, int c);
37 
38 
39 __INLINE int
40 feof_unlocked(FILE *stream)
41 {
42 	return _IO_feof_unlocked(stream);
43 }
44 
45 __INLINE int
46 ferror_unlocked(FILE *stream)
47 {
48 	return _IO_ferror_unlocked(stream);
49 }
50 
51 
52 #define getc(stream) \
53 	(_single_threaded ? _IO_getc_unlocked(stream) : _IO_getc(stream))
54 #define putc(c, stream) \
55 	(_single_threaded ? _IO_putc_unlocked(c, stream) : _IO_putc(c, stream))
56 
57 __INLINE int
58 _IO_getc_unlocked(FILE *stream)
59 {
60 	if (stream->_IO_read_ptr >= stream->_IO_read_end)
61 		return __uflow(stream);
62 
63 	return *(unsigned char *)stream->_IO_read_ptr++;
64 }
65 
66 
67 __INLINE int
68 _IO_peekc_unlocked(FILE *stream)
69 {
70 	if (stream->_IO_read_ptr >= stream->_IO_read_end && __underflow(stream) == EOF)
71 		return EOF;
72 
73 	return *(unsigned char *)stream->_IO_read_ptr;
74 }
75 
76 
77 __INLINE int
78 _IO_putc_unlocked(int c, FILE *stream)
79 {
80 	if (stream->_IO_write_ptr >= stream->_IO_write_end)
81 		return __overflow(stream, (unsigned char)c);
82 
83 	return (unsigned char)(*stream->_IO_write_ptr++ = c);
84 }
85 
86 
87 __INLINE int
88 putc_unlocked(int c, FILE *stream)
89 {
90 	return _IO_putc_unlocked(c, stream);
91 }
92 
93 
94 __INLINE int
95 putchar_unlocked(int c)
96 {
97 	return _IO_putc_unlocked(c, stdout);
98 }
99 
100 #undef __INLINE
101 
102 #endif	/* _STDIO_POST_H_ */
103