From 04061cbba59951813b4c3330f03b8c322d1631ee Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Sun, 7 Jun 2020 00:31:26 +0200 Subject: [PATCH] mescc: Mes C Library: Bugfix __ungetc_clear. * lib/linux/_open3.c (_open3): Remove __ungetc_init (); * lib/mes/mes_open.c (mes_open): Likewise. * lib/mes/fdungetc.c (fdungetc): Likewise. * lib/mes/fdgetc.c (__ungetc_p, __ungetc_clear, __ungetc_set): Call __ungetc_init if buffer is uninitialized. --- lib/linux/_open3.c | 1 - lib/mes/fdgetc.c | 9 ++++++++- lib/mes/fdungetc.c | 1 - lib/mes/mes_open.c | 1 - 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/linux/_open3.c b/lib/linux/_open3.c index 8f103e7b..3072f9bf 100644 --- a/lib/linux/_open3.c +++ b/lib/linux/_open3.c @@ -27,7 +27,6 @@ int _open3 (char const *file_name, int flags, int mask) { int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask); - __ungetc_init (); if (r > 2) { __ungetc_clear (r); diff --git a/lib/mes/fdgetc.c b/lib/mes/fdgetc.c index 0370c24e..e5c63a75 100644 --- a/lib/mes/fdgetc.c +++ b/lib/mes/fdgetc.c @@ -31,6 +31,8 @@ int *__ungetc_buf; int __ungetc_p (int filedes) { + if (__ungetc_buf == 0) + __ungetc_init (); return __ungetc_buf[filedes] >= 0; } @@ -49,19 +51,24 @@ __ungetc_init () void __ungetc_clear (int filedes) { + if (__ungetc_buf == 0) + __ungetc_init (); __ungetc_buf[filedes] = -1; } void __ungetc_set (int filedes, int c) { + if (__ungetc_buf == 0) + __ungetc_init (); __ungetc_buf[filedes] = c; } int fdgetc (int fd) { - __ungetc_init (); + if (__ungetc_buf == 0) + __ungetc_init (); char c; int i = __ungetc_buf[fd]; diff --git a/lib/mes/fdungetc.c b/lib/mes/fdungetc.c index 20ef9e87..2179aeb0 100644 --- a/lib/mes/fdungetc.c +++ b/lib/mes/fdungetc.c @@ -24,7 +24,6 @@ int fdungetc (int c, int fd) { - __ungetc_init (); if (c == -1) return c; else if (__ungetc_p (fd)) diff --git a/lib/mes/mes_open.c b/lib/mes/mes_open.c index 5ab184f5..13edc022 100644 --- a/lib/mes/mes_open.c +++ b/lib/mes/mes_open.c @@ -32,7 +32,6 @@ int __stderr = STDERR; int mes_open (char const *file_name, int flags, int mask) { - __ungetc_init (); int filedes = open (file_name, flags, mask); if (filedes > 2) __ungetc_clear (filedes);