fxlibc/src/stdio/stdio_p.h

46 lines
1.2 KiB
C

#ifndef __STDIO_P_H__
# define __STDIO_P_H__
#include <stdio.h>
/*
** General utilities for scanf(); we expose them here as we use subfunctions of
** strto*() from <stdlib.h> to implement numerical specifiers.
*/
/*
** Input for scanf; exactly one of str and fp must be non-NULL. We include a
** single-character buffer for convenience for scanning functions to test the
** next character, which can be flushed back by ungetc().
*/
struct __scanf_input {
char const * __restrict__ str;
FILE *fp;
int buffer;
};
/* Initialize the input by feeding the buffer byte. */
void __scanf_start(struct __scanf_input *__in);
/* Fetch the next byte from the input and return it (don't call directly). */
int __scanf_fetch(struct __scanf_input *__in);
/* Read the next byte while maintaining the buffer. */
static inline int __scanf_in(struct __scanf_input *__in)
{
int c = __in->buffer;
__in->buffer = __scanf_fetch(__in);
return c;
}
/* Peek the next byte without advancing. */
static inline int __scanf_peek(struct __scanf_input *__in)
{
return __in->buffer;
}
/* Close the input by unsending the buffer once finished. */
void __scanf_end(struct __scanf_input *__in);
#endif /* __STDIO_P_H__ */