From f8334e283c5eb0efeb4bb8a134041e18388d5f01 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 21 Apr 2017 16:57:00 +0200 Subject: Lua init --- src/lib/libc/stdio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/lib/libc/stdio.c') diff --git a/src/lib/libc/stdio.c b/src/lib/libc/stdio.c index 864fb34..bfa2f74 100644 --- a/src/lib/libc/stdio.c +++ b/src/lib/libc/stdio.c @@ -225,6 +225,10 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { } int fgetc(FILE *stream) { + if (stream == NULL) { + return EOF; + } + dbg_printf("FGETC %p\n", stream); // TODO buffering && ungetc @@ -321,10 +325,10 @@ int setvbuf(FILE *stream, char *buf, int mode, size_t size) { int fflush(FILE* stream) { dbg_printf("FFLUSH %p\n", stream); - if (!(stream->file_mode & FM_WRITE)) return 0; if (stream == NULL || stream->fd == 0) { return EOF; } + if (!(stream->file_mode & FM_WRITE)) return 0; if (stream->buf_mode != 0 && stream->out_buf_used > 0) { size_t ret = sc_write(stream->fd, stream->pos, stream->out_buf_used, stream->out_buf); -- cgit v1.2.3