1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| | #include "stdio_impl.h"
/* Scan helper "stdio" functions for use by scanf-family and strto*-family
* functions. These accept either avalid stdio FILE, or a minimal pseduo
* FILE whose buffer pointers point into a null-terminated string. In the
* latter case, the sh_fromstring macro should be used to setup the FILE;
* the rest of the structure can be left uninitialized.
*
* To begin using these functions, shlim must first be called on the FILE
* to set a field width limit, or 0 for no limit. For string pseudo-FILEs,
* a nonzero limit is not valid and produces undefined behavior. After that,
* shgetc, shunget, and shcnt are valid as long as no other stdio functions
* are called on the stream. shunget can only be called once without an
* intervening successful shgetc on real stdio FILEs. It can be called
* multiple times, up to the number of successful shgetc calls, on a
* string pseudo-FILE. */
hidden void __shlim(FILE *, off_t);
hidden int __shgetc(FILE *);
#define sh_fromstring(f, s) \
((f)->buf = (f)->rpos = (void *)(s), (f)->rend = (void*)-1)
#define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf))
#define shlim(f, lim) __shlim((f), (lim))
#define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f))
#define shunget(f) ((f)->shend ? (void)(f)->rpos-- : (void)0)
|