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.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2019-11-09 23:31:26 +01:00
parent 249d33f750
commit 02f8c37101
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 8 additions and 4 deletions

View File

@ -27,7 +27,6 @@ int
_open3 (char const *file_name, int flags, int mask) _open3 (char const *file_name, int flags, int mask)
{ {
int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask); int r = _sys_call3 (SYS_open, (long) file_name, (int) flags, (int) mask);
__ungetc_init ();
if (r > 2) if (r > 2)
{ {
__ungetc_clear (r); __ungetc_clear (r);

View File

@ -32,6 +32,8 @@ int *__ungetc_buf;
int int
__ungetc_p (int filedes) __ungetc_p (int filedes)
{ {
if (__ungetc_buf == 0)
__ungetc_init ();
return __ungetc_buf[filedes] >= 0; return __ungetc_buf[filedes] >= 0;
} }
@ -50,19 +52,24 @@ __ungetc_init ()
void void
__ungetc_clear (int filedes) __ungetc_clear (int filedes)
{ {
if (__ungetc_buf == 0)
__ungetc_init ();
__ungetc_buf[filedes] = -1; __ungetc_buf[filedes] = -1;
} }
void void
__ungetc_set (int filedes, int c) __ungetc_set (int filedes, int c)
{ {
if (__ungetc_buf == 0)
__ungetc_init ();
__ungetc_buf[filedes] = c; __ungetc_buf[filedes] = c;
} }
int int
fdgetc (int fd) fdgetc (int fd)
{ {
__ungetc_init (); if (__ungetc_buf == 0)
__ungetc_init ();
char c; char c;
int i = __ungetc_buf[fd]; int i = __ungetc_buf[fd];

View File

@ -24,7 +24,6 @@
int int
fdungetc (int c, int fd) fdungetc (int c, int fd)
{ {
__ungetc_init ();
if (c == -1) if (c == -1)
return c; return c;
else if (__ungetc_p (fd)) else if (__ungetc_p (fd))

View File

@ -32,7 +32,6 @@ int __stderr = STDERR;
int int
mes_open (char const *file_name, int flags, int mask) mes_open (char const *file_name, int flags, int mask)
{ {
__ungetc_init ();
int filedes = open (file_name, flags, mask); int filedes = open (file_name, flags, mask);
if (filedes > 2) if (filedes > 2)
__ungetc_clear (filedes); __ungetc_clear (filedes);