source: trunk/sys/dietlibc/setvbuf.c @ 365

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

First import

File size: 1.0 KB
Line 
1#include "dietstdio.h"
2#include <unistd.h>
3#include <stdlib.h>
4#include "dietwarning.h"
5
6static int set_flags(FILE *stream, int flags) {
7  switch (flags) {
8    case _IONBF: stream->flags = (stream->flags & ~(BUFLINEWISE)) | NOBUF; break;
9    case _IOLBF: stream->flags = (stream->flags & ~(NOBUF)) | BUFLINEWISE; break;
10    case _IOFBF: stream->flags = stream->flags & ~(NOBUF | BUFLINEWISE); break;
11    default: return -1;
12  }
13  return 0;
14}
15
16int setvbuf_unlocked(FILE *stream, char *buf, int flags, size_t size) {
17  if (buf) {
18    if (!(stream->flags&STATICBUF)) free(stream->buf);
19    stream->buf=buf;
20  }
21  else {
22    char *tmp;
23    if (!size) {
24      return set_flags(stream,flags);
25    }
26    if (!(tmp=malloc(size))) return -1;
27    if (!(stream->flags&STATICBUF)) free(stream->buf);
28    stream->buf=tmp;
29  }
30  stream->flags &= ~STATICBUF;
31  stream->buflen=size;
32  stream->bm=stream->bs=0;
33  return set_flags(stream,flags);
34}
35
36int setvbuf(FILE *stream, char *buf, int flags, size_t size) __attribute__((weak,alias("setvbuf_unlocked")));
Note: See TracBrowser for help on using the repository browser.