#ifndef __STDIO_P_H__ # define __STDIO_P_H__ #include #include /* ** General utilities for scanf(); we expose them here as we use subfunctions of ** strto*() from 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; /* Single-character lookahead buffer */ int buffer; /* Total numbers of bytes read in a scall to *scanf() */ int bytes_read; }; /* Generic formatted scaning. */ extern int __scanf( struct __scanf_input * __restrict__ __in, char const * __restrict__ __format, va_list *__args); /* 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); __in->bytes_read++; return c; } /* Read the next byte and also decrease a total count of available reads. */ static inline int __scanf_in_limit(struct __scanf_input *__in, int *__N) { (*__N)--; return __scanf_in(__in); } /* 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__ */