| Rev | Line | |
|---|
| [1] | 1 | #include "dietstdio.h" |
|---|
| 2 | #include <unistd.h> |
|---|
| 3 | #include <stdlib.h> |
|---|
| 4 | #include "dietwarning.h" |
|---|
| 5 | |
|---|
| 6 | static 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 | |
|---|
| 16 | int 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 | |
|---|
| 36 | int 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.