Rev | Line | |
---|
[1] | 1 | #include "dietstdio.h" |
---|
| 2 | #include <unistd.h> |
---|
| 3 | |
---|
| 4 | int fgetc_unlocked(FILE *stream) { |
---|
| 5 | unsigned char c; |
---|
| 6 | if (!(stream->flags&CANREAD)) goto kaputt; |
---|
| 7 | |
---|
| 8 | if (stream->ungotten) { |
---|
| 9 | stream->ungotten=0; |
---|
| 10 | return stream->ungetbuf; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | log_msg("fgetc fd %d, mb %d, bs %d\n", stream->fd, stream->bm, stream->bs); |
---|
| 14 | /* common case first */ |
---|
| 15 | if (stream->bm<stream->bs) |
---|
| 16 | { |
---|
| 17 | log_msg("fgetc fd %d, %c\n", stream->fd, stream->buf[stream->bm]); |
---|
| 18 | return (unsigned char)stream->buf[stream->bm++]; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | if (feof_unlocked(stream)) |
---|
| 22 | return EOF; |
---|
| 23 | |
---|
| 24 | if (__fflush4(stream,BUFINPUT)) return EOF; |
---|
| 25 | if (stream->bm>=stream->bs) { |
---|
| 26 | ssize_t len= read(stream->fd,stream->buf,stream->buflen); |
---|
| 27 | if (len==0) { |
---|
| 28 | stream->flags|=EOFINDICATOR; |
---|
| 29 | return EOF; |
---|
| 30 | } else if (len<0) { |
---|
| 31 | kaputt: |
---|
| 32 | stream->flags|=ERRORINDICATOR; |
---|
| 33 | return EOF; |
---|
| 34 | } |
---|
| 35 | stream->bm=0; |
---|
| 36 | stream->bs=len; |
---|
| 37 | } |
---|
| 38 | c=stream->buf[stream->bm]; |
---|
| 39 | ++stream->bm; |
---|
| 40 | return c; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | int fgetc(FILE* stream) __attribute__((weak,alias("fgetc_unlocked"))); |
---|
Note: See
TracBrowser
for help on using the repository browser.