This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Reentrant ungetwc


Hello. Here is reentrant ungetc() version.

--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
Index: stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.27
diff -c -r1.27 stdio.h
*** stdio.h	23 Apr 2004 20:06:03 -0000	1.27
--- stdio.h	30 Apr 2004 15:56:20 -0000
***************
*** 288,293 ****
--- 288,294 ----
  int	_EXFUN(_printf_r, (struct _reent *, const char *, ...));
  int	_EXFUN(_putchar_r, (struct _reent *, int));
  int	_EXFUN(_puts_r, (struct _reent *, const char *));
+ int	_EXFUN(_ungetc_r, (struct _reent *, int, FILE *));
  int	_EXFUN(_remove_r, (struct _reent *, const char *));
  int	_EXFUN(_rename_r, (struct _reent *,
  			   const char *_old, const char *_new));
Index: ungetc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/ungetc.c,v
retrieving revision 1.4
diff -c -r1.4 ungetc.c
*** ungetc.c	23 Apr 2004 20:01:55 -0000	1.4
--- ungetc.c	30 Apr 2004 15:56:40 -0000
***************
*** 20,25 ****
--- 20,26 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <_ansi.h>
+ #include <reent.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
***************
*** 34,40 ****
  
  /*static*/
  int
! _DEFUN(__submore, (fp),
         register FILE *fp)
  {
    register int i;
--- 35,42 ----
  
  /*static*/
  int
! _DEFUN(__submore, (rptr, fp),
!        struct _reent *rptr _AND
         register FILE *fp)
  {
    register int i;
***************
*** 45,51 ****
        /*
         * Get a new buffer (rather than expanding the old one).
         */
!       if ((p = (unsigned char *) _malloc_r (_REENT, (size_t) BUFSIZ)) == NULL)
  	return EOF;
        fp->_ub._base = p;
        fp->_ub._size = BUFSIZ;
--- 47,53 ----
        /*
         * Get a new buffer (rather than expanding the old one).
         */
!       if ((p = (unsigned char *) _malloc_r (rptr, (size_t) BUFSIZ)) == NULL)
  	return EOF;
        fp->_ub._base = p;
        fp->_ub._size = BUFSIZ;
***************
*** 56,62 ****
        return 0;
      }
    i = fp->_ub._size;
!   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);
--- 58,64 ----
        return 0;
      }
    i = fp->_ub._size;
!   p = (unsigned char *) _realloc_r (rptr, (_PTR) (fp->_ub._base), i << 1);
    if (p == NULL)
      return EOF;
    _CAST_VOID memcpy ((_PTR) (p + i), (_PTR) p, (size_t) i);
***************
*** 67,74 ****
  }
  
  int
! _DEFUN(ungetc, (c, fp),
!        int c _AND
         register FILE *fp)
  {
    if (c == EOF)
--- 69,77 ----
  }
  
  int
! _DEFUN(_ungetc_r, (rptr, c, fp),
!        struct _reent *rptr _AND
!        int c               _AND
         register FILE *fp)
  {
    if (c == EOF)
***************
*** 118,124 ****
  
    if (HASUB (fp))
      {
!       if (fp->_r >= fp->_ub._size && __submore (fp))
          {
            _funlockfile (fp);
            return EOF;
--- 121,127 ----
  
    if (HASUB (fp))
      {
!       if (fp->_r >= fp->_ub._size && __submore (rptr, fp))
          {
            _funlockfile (fp);
            return EOF;
***************
*** 158,160 ****
--- 161,174 ----
    _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 */
+ 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]