clean up dns_parse_callback
[musl] / src / internal / shgetc.h
1 #include "stdio_impl.h"
2
3 /* Scan helper "stdio" functions for use by scanf-family and strto*-family
4  * functions. These accept either a valid stdio FILE, or a minimal pseudo
5  * FILE whose buffer pointers point into a null-terminated string. In the
6  * latter case, the sh_fromstring macro should be used to setup the FILE;
7  * the rest of the structure can be left uninitialized.
8  *
9  * To begin using these functions, shlim must first be called on the FILE
10  * to set a field width limit, or 0 for no limit. For string pseudo-FILEs,
11  * a nonzero limit is not valid and produces undefined behavior. After that,
12  * shgetc, shunget, and shcnt are valid as long as no other stdio functions
13  * are called on the stream.
14  *
15  * When used with a real FILE object, shunget has only one byte of pushback
16  * available. Further shunget (up to a limit of the stdio UNGET buffer size)
17  * will adjust the position but will not restore the data to be read again.
18  * This functionality is needed for the wcsto*-family functions, where it's
19  * okay because the FILE will be discarded immediately anyway. When used
20  * with string pseudo-FILEs, shunget has unlimited pushback, back to the
21  * beginning of the string. */
22
23 hidden void __shlim(FILE *, off_t);
24 hidden int __shgetc(FILE *);
25
26 #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf))
27 #define shlim(f, lim) __shlim((f), (lim))
28 #define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f))
29 #define shunget(f) ((f)->shlim>=0 ? (void)(f)->rpos-- : (void)0)
30
31 #define sh_fromstring(f, s) \
32         ((f)->buf = (f)->rpos = (void *)(s), (f)->rend = (void*)-1)