source: trunk/sys/dietlibc/fflush.c @ 233

Last change on this file since 233 was 1, checked in by alain, 7 years ago

First import

File size: 1.6 KB
Line 
1#include <unistd.h>
2#include <stdlib.h>
3#include <string.h>
4#include "dietwarning.h"
5#include "dietstdio.h"
6
7FILE *__stdio_root = NULL;
8
9int __stdio_atexit=0;
10
11int fflush(FILE *stream) __attribute__((weak,alias("fflush_unlocked")));
12
13void __stdio_flushall(void) {
14  fflush(0);
15}
16
17int fflush_unlocked(FILE *stream) {
18  if (stream==0) {
19    int res;
20    FILE *f;
21    __fflush_stdin();
22    __fflush_stdout();
23    __fflush_stderr();
24    for (res=0, f=__stdio_root; f; f=f->next)
25      if (fflush(f))
26        res=-1;
27    return res;
28  }
29//  if (stream->flags&NOBUF) return 0;
30
31  if (stream->flags&BUFINPUT) {
32    register int tmp;
33    if ((tmp=stream->bm-stream->bs)) {
34      lseek(stream->fd,tmp,SEEK_CUR);
35    }
36    stream->bs=stream->bm=0;
37  } else {
38    if (stream->bm && write(stream->fd,stream->buf,stream->bm)!=(ssize_t)stream->bm) {
39      stream->flags|=ERRORINDICATOR;
40      return -1;
41    }
42    stream->bm=0;
43  }
44  return 0;
45}
46
47int __fflush4(FILE *stream,int next) {
48  if (!__stdio_atexit) {
49    __stdio_atexit=1;
50    atexit(__stdio_flushall);
51  }
52  if ((stream->flags & BUFINPUT) != next) {
53    int res=fflush_unlocked(stream);
54    stream->flags=(stream->flags&~BUFINPUT)|next;
55    return res;
56  }
57  if (stream->fd==0 && __stdin_is_tty()) __fflush_stdout();
58  return 0;
59}
60
61/* Internal function, has no prototype.
62 * This is defined here because of the weak symbol ELF semantics */
63int __stdio_outs(const char *s,size_t len);
64int __stdio_outs(const char *s,size_t len) {
65  return fwrite(s,1,(size_t)len,stdout)==len?1:0;
66}
67
68link_warning("fflush","warning: your code uses stdio (7+k bloat).")
Note: See TracBrowser for help on using the repository browser.