Rev | Line | |
---|
[1] | 1 | #include "dietstdio.h" |
---|
| 2 | #include <unistd.h> |
---|
| 3 | #include <endian.h> |
---|
| 4 | |
---|
| 5 | int fputc_unlocked(int c, FILE *stream) { |
---|
| 6 | if (!(stream->flags&CANWRITE) || __fflush4(stream,0)) { |
---|
| 7 | kaputt: |
---|
| 8 | stream->flags|=ERRORINDICATOR; |
---|
| 9 | return EOF; |
---|
| 10 | } |
---|
| 11 | if ((stream->bm>=stream->buflen-1)) |
---|
| 12 | if (fflush_unlocked(stream)) goto kaputt; |
---|
| 13 | if (stream->flags&NOBUF) { |
---|
| 14 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
---|
| 15 | if (write(stream->fd,&c,1) != 1) |
---|
| 16 | #else |
---|
| 17 | if (write(stream->fd,(char*)&c+sizeof(c)-1,1) != 1) |
---|
| 18 | #endif |
---|
| 19 | goto kaputt; |
---|
| 20 | return 0; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | log_msg("putting '%c' into fd %d buffer\n", c, stream->fd); |
---|
| 24 | |
---|
| 25 | stream->buf[stream->bm]=c; |
---|
| 26 | ++stream->bm; |
---|
| 27 | if (((stream->flags&BUFLINEWISE) && c=='\n') || |
---|
| 28 | ((stream->flags&NOBUF))) /* puke */ |
---|
| 29 | if (fflush_unlocked(stream)) goto kaputt; |
---|
| 30 | |
---|
| 31 | log_msg("'%c' putted !\n", c); |
---|
| 32 | return 0; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | int fputc(int c,FILE* stream) __attribute__((weak,alias("fputc_unlocked"))); |
---|
Note: See
TracBrowser
for help on using the repository browser.