Rev | Line | |
---|
[1] | 1 | #include "dietstdio.h" |
---|
| 2 | |
---|
| 3 | char *fgets_unlocked(char *s, int size, FILE *stream) { |
---|
| 4 | int l; |
---|
| 5 | for (l=0; l<size; ) { |
---|
| 6 | register int c; |
---|
| 7 | if (l && stream->bm<stream->bs) { |
---|
| 8 | /* try common case first */ |
---|
| 9 | c=(unsigned char)stream->buf[stream->bm++]; |
---|
| 10 | } else { |
---|
| 11 | c=fgetc_unlocked(stream); |
---|
| 12 | if (c==EOF) { |
---|
| 13 | if (!l) return 0; |
---|
| 14 | goto fini; |
---|
| 15 | } |
---|
| 16 | } |
---|
| 17 | s[l]=c; |
---|
| 18 | ++l; |
---|
| 19 | if (c=='\n') { |
---|
| 20 | fini: |
---|
| 21 | s[l]=0; |
---|
| 22 | return s; |
---|
| 23 | } |
---|
| 24 | } |
---|
| 25 | return 0; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | char*fgets(char*s,int size,FILE*stream) __attribute__((weak,alias("fgets_unlocked"))); |
---|
Note: See
TracBrowser
for help on using the repository browser.