From e4bb2e17621f515c23dc60a8e37fe85efb87702c Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 19 Nov 2017 16:54:59 +0100 Subject: [PATCH] mlibc: Mescc-tools support: fix fgetc. * mlibc/libc-mes.c (fgetc): Fix from completely fubar. --- mlibc/libc-mes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mlibc/libc-mes.c b/mlibc/libc-mes.c index 3375a958..3fbd68be 100644 --- a/mlibc/libc-mes.c +++ b/mlibc/libc-mes.c @@ -191,8 +191,11 @@ int fgetc (int fd) { char c; + int i; int r = read (fd, &c, 1); - return c == 1 ? c : (-1); + if (r < 1) return -1; + i = c; + return i; } void