www.pudn.com > ASYNC13.rar > UNGETC.C


/* A module of ASYNCx.LIB version 1.20 */ 
 
#include  
#include "asyncdef.h" 
 
/* 
** Place the character c into the input buffer being used by p so that 
** it will be the next character to be read from the port. This 
** operation may be performed until the buffer is full of the characters 
** that have been pushed into it. If the port cannot accept the 
** character, a value of -1 is returned. Otherwise, the value of the 
** character that was pushed into the port's input buffer is returned. 
*/ 
int a_ungetc(int c,register ASYNC *p) 
{byte *bp; 
 if (p) 
  {disable(); 
   bp=p->ibuftail; 
   if (bp==p->ibuf) 
     bp=p->ibufend-1; 
   else 
     bp--; 
   if (bp==p->ibufhead) 
    {enable(); 
     return -1; 
    } 
   else 
    {*bp=(byte)c; 
     p->ibuftail=bp; 
     p->icount++; 
    } 
   enable(); 
   return c; 
  } 
 return -1; 
} /* end of a_ungetc(c,p) */