www.pudn.com > ASYNC13.rar > GETC.C
/* A module of ASYNCx.LIB version 1.20 */
#include "asyncdef.h"
/***************************************************************
Get one byte from the input buffer of the async port
associated with p. If a byte is found in the buffer, return
its value in the form of an integer (without sign extension).
If the buffer is empty, return a value of -1.
***************************************************************/
int a_getc(register ASYNC *p)
{byte c,*bp;
if (p)
{bp=p->ibuftail; /* point to the next byte in the buffer */
if (bp==p->ibufhead) /* if there is nothing in the buffer, */
return -1; /* return EOF. */
c=(byte)(*bp++); /* else, get the next byte. */
p->icount--; /* adjust the byte count */
if (bp==p->ibufend) /* wrap if necessary */
bp=p->ibuf;
p->ibuftail=bp;
return (unsigned)c; /* return the value retrieved */
}
return -1;
} /* end of a_getc(p) */