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 static int iint(FILE *fp
, void *dst
, int l
)
61 } while (isdigit(c
= ic(fp
)));
64 *(long *) dst
= neg
? -n
: n
;
66 *(int *) dst
= neg
? -n
: n
;
70 static int istr(FILE *fp
, char *dst
)
74 while ((c
= ic(fp
)) != EOF
&& !isspace(c
))
81 int vfscanf(FILE *fp
, char *fmt
, va_list ap
)
90 while (isspace(c
= ic(fp
)))
93 while (*fmt
&& *fmt
!= '%' && !isspace(*fmt
))
106 if (iint(fp
, va_arg(ap
, long *), l
))
111 if (istr(fp
, va_arg(ap
, char *)))
120 int fscanf(FILE *fp
, char *fmt
, ...)
125 ret
= vfscanf(fp
, fmt
, ap
);
130 int scanf(char *fmt
, ...)
135 ret
= vfscanf(stdin
, fmt
, ap
);
140 int vsscanf(char *s
, char *fmt
, va_list ap
)
145 return vfscanf(&f
, fmt
, ap
);
148 int sscanf(char *s
, char *fmt
, ...)
153 ret
= vsscanf(s
, fmt
, ap
);
158 char *fgets(char *s
, int sz
, FILE *fp
)
162 while (i
+ 1 < sz
&& (c
= ic(fp
)) != EOF
) {