diff options
Diffstat (limited to 'newlib/libc/stdio/ungetc.c')
-rw-r--r-- | newlib/libc/stdio/ungetc.c | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/newlib/libc/stdio/ungetc.c b/newlib/libc/stdio/ungetc.c index fc6fa3160..5ca98251d 100644 --- a/newlib/libc/stdio/ungetc.c +++ b/newlib/libc/stdio/ungetc.c @@ -19,8 +19,6 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #endif /* LIBC_SCCS and not lint */ -#include <_ansi.h> -#include <reent.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -35,9 +33,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; /*static*/ int -_DEFUN(__submore, (rptr, fp), - struct _reent *rptr _AND - register FILE *fp) +__submore (fp) + register FILE *fp; { register int i; register unsigned char *p; @@ -47,7 +44,7 @@ _DEFUN(__submore, (rptr, fp), /* * Get a new buffer (rather than expanding the old one). */ - if ((p = (unsigned char *) _malloc_r (rptr, (size_t) BUFSIZ)) == NULL) + if ((p = (unsigned char *) _malloc_r (_REENT, (size_t) BUFSIZ)) == NULL) return EOF; fp->_ub._base = p; fp->_ub._size = BUFSIZ; @@ -58,10 +55,10 @@ _DEFUN(__submore, (rptr, fp), return 0; } i = fp->_ub._size; - p = (unsigned char *) _realloc_r (rptr, (_PTR) (fp->_ub._base), i << 1); + p = (unsigned char *) _realloc_r (_REENT, (_PTR) (fp->_ub._base), i << 1); if (p == NULL) return EOF; - _CAST_VOID memcpy ((_PTR) (p + i), (_PTR) p, (size_t) i); + (void) memcpy ((void *) (p + i), (void *) p, (size_t) i); fp->_p = p + i; fp->_ub._base = p; fp->_ub._size = i << 1; @@ -69,22 +66,21 @@ _DEFUN(__submore, (rptr, fp), } int -_DEFUN(_ungetc_r, (rptr, c, fp), - struct _reent *rptr _AND - int c _AND - register FILE *fp) +ungetc (c, fp) + int c; + register FILE *fp; { if (c == EOF) return (EOF); + _flockfile(fp); + /* Ensure stdio has been initialized. ??? Might be able to remove this as some other stdio routine should have already been called to get the char we are un-getting. */ - CHECK_INIT (rptr); + CHECK_INIT (fp); - _flockfile (fp); - /* After ungetc, we won't be at eof anymore */ fp->_flags &= ~__SEOF; @@ -96,14 +92,14 @@ _DEFUN(_ungetc_r, (rptr, c, fp), */ if ((fp->_flags & __SRW) == 0) { - _funlockfile (fp); + _funlockfile(fp); return EOF; } if (fp->_flags & __SWR) { if (fflush (fp)) { - _funlockfile (fp); + _funlockfile(fp); return EOF; } fp->_flags &= ~__SWR; @@ -121,14 +117,14 @@ _DEFUN(_ungetc_r, (rptr, c, fp), if (HASUB (fp)) { - if (fp->_r >= fp->_ub._size && __submore (rptr, fp)) + if (fp->_r >= fp->_ub._size && __submore (fp)) { - _funlockfile (fp); + _funlockfile(fp); return EOF; } *--fp->_p = c; fp->_r++; - _funlockfile (fp); + _funlockfile(fp); return c; } @@ -142,7 +138,7 @@ _DEFUN(_ungetc_r, (rptr, c, fp), { fp->_p--; fp->_r++; - _funlockfile (fp); + _funlockfile(fp); return c; } @@ -158,17 +154,6 @@ _DEFUN(_ungetc_r, (rptr, c, fp), fp->_ubuf[sizeof (fp->_ubuf) - 1] = c; fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - 1]; fp->_r = 1; - _funlockfile (fp); + _funlockfile(fp); return c; } - -#ifndef _REENT_ONLY -int -_DEFUN(ungetc, (c, fp), - int c _AND - register FILE *fp) -{ - return _ungetc_r (_REENT, c, fp); -} -#endif /* !_REENT_ONLY */ - |