1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
26 if (stream->mode == _IONBF || stream->buf == NULL) {
27 if (read(stream->fd, &c, 1) == 1)
33 if (stream->pos == 0 || stream->pos >= BUFSIZ ||
34 stream->buf[stream->pos] == '\0') {
35 count = read(stream->fd, stream->buf, BUFSIZ);
39 stream->buf[count] = '\0';
43 return stream->buf[stream->pos++];
47 _ungetc(int ch, FILE * stream)
49 if (stream->mode != _IONBF && stream->pos > 0)
56 if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '\0')
64 _scanf(FILE * stream, const char *fmt, va_list * ap)
71 while (*fmt != '\0') {
81 while (!_is_voidage(ch) && isdigit(ch)) {
87 while (!_is_voidage(ch) && i < length
94 /* We tried to understand what this is good for...
95 * but we did not. We know for sure that it does not
96 * work on SLOF if this is active. */
97 /* _ungetc(ch, stream); */
100 /* ch = _getc(stream); */
101 if (!_is_voidage(ch))
104 if (strlen(tbuf) == 0)
107 *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 10);
113 while (!_is_voidage(ch) && isxdigit(ch)) {
119 while (!_is_voidage(ch) && i < length
126 /* _ungetc(ch, stream); */
129 /* ch = _getc(stream); */
130 if (!_is_voidage(ch))
133 if (strlen(tbuf) == 0)
136 *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 16);
142 while (!_is_voidage(ch)
143 && !(ch < '0' || ch > '7')) {
149 while (!_is_voidage(ch) && i < length
150 && !(ch < '0' || ch > '7')) {
156 /* _ungetc(ch, stream); */
159 /* ch = _getc(stream); */
160 if (!_is_voidage(ch))
163 if (strlen(tbuf) == 0)
166 *(va_arg(*ap, int *)) = strtol(tbuf, NULL, 8);
170 while (_is_voidage(ch))
173 *(va_arg(*ap, char *)) = ch;
176 if (!_is_voidage(ch))
183 while (!_is_voidage(ch)) {
189 while (!_is_voidage(ch) && i < length) {
195 /* _ungetc(ch, stream); */
198 /* ch = _getc(stream); */
199 if (!_is_voidage(ch))
202 strcpy(va_arg(*ap, char *), tbuf);
205 if (*fmt >= '0' && *fmt <= '9')
206 length += *fmt - '0';
218 vfscanf(FILE * stream, const char *fmt, va_list ap)
222 while (*fmt != '\0') {
234 (*fmt == 'd' || *fmt == 'i' || *fmt == 'x'
235 || *fmt == 'X' || *fmt == 'p' || *fmt == 'c'
236 || *fmt == 's' || *fmt == '%' || *fmt == 'O'
241 if (_scanf(stream, formstr, &ap) <= 0)
259 return _getc(stream);