source: trunk/sys/dietlibc/fputc_unlocked.c @ 385

Last change on this file since 385 was 1, checked in by alain, 8 years ago

First import

File size: 894 bytes
Line 
1#include "dietstdio.h"
2#include <unistd.h>
3#include <endian.h>
4
5int fputc_unlocked(int c, FILE *stream) {
6  if (!(stream->flags&CANWRITE) || __fflush4(stream,0)) {
7kaputt:
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
35int fputc(int c,FILE* stream) __attribute__((weak,alias("fputc_unlocked")));
Note: See TracBrowser for help on using the repository browser.