6 static int ic(FILE *fp
)
14 while (fp
->fd
>= 0 && fp
->icur
== fp
->ilen
) {
15 int nr
= read(fp
->fd
, fp
->ibuf
, fp
->isize
);
21 return fp
->icur
< fp
->ilen
? (unsigned char) fp
->ibuf
[fp
->icur
++] : EOF
;
24 void setbuf(FILE *fp
, char *buf
)
38 int ungetc(int c
, FILE *fp
)
45 /* t is 1 for char, 2 for short, 4 for int, and 8 for long */
46 static int iint(FILE *fp
, void *dst
, int t
)
54 if (c
== '-' || c
== '+')
62 } while (isdigit(c
= ic(fp
)));
65 *(long *) dst
= neg
? -n
: n
;
67 *(int *) dst
= neg
? -n
: n
;
69 *(short *) dst
= neg
? -n
: n
;
71 *(char *) dst
= neg
? -n
: n
;
75 static int istr(FILE *fp
, char *dst
)
79 while ((c
= ic(fp
)) != EOF
&& !isspace(c
))
86 int vfscanf(FILE *fp
, char *fmt
, va_list ap
)
93 while (isspace(c
= ic(fp
)))
96 while (*fmt
&& *fmt
!= '%' && !isspace(*fmt
))
103 while (*fmt
== 'l') {
107 while (*fmt
== 'h') {
108 t
= t
< sizeof(int) ? sizeof(char) : sizeof(short);
114 if (iint(fp
, va_arg(ap
, long *), t
))
119 if (istr(fp
, va_arg(ap
, char *)))
128 int fscanf(FILE *fp
, char *fmt
, ...)
133 ret
= vfscanf(fp
, fmt
, ap
);
138 int scanf(char *fmt
, ...)
143 ret
= vfscanf(stdin
, fmt
, ap
);
148 int vsscanf(char *s
, char *fmt
, va_list ap
)
153 return vfscanf(&f
, fmt
, ap
);
156 int sscanf(char *s
, char *fmt
, ...)
161 ret
= vsscanf(s
, fmt
, ap
);
166 char *fgets(char *s
, int sz
, FILE *fp
)
170 while (i
+ 1 < sz
&& (c
= ic(fp
)) != EOF
) {