/* Copyright (C) Magna Carta Software, Inc. 1990,1991. All Rights Reserved. C COMMUNICATIONS TOOLKIT CPEEK.C -- Examine, but do not remove, bytes in the RX buffer. */ #include #include /* C_RXPEEK -- examine, but do not remove, a byte in the receive buffer. Parameters: COMM_PORT *p -- pointer to the port; WORD num -- number of bytes from tail to read; Return Value: the byte at the requested position; EOF if request fewer bytes in buffer than requested byte; */ short c_rxpeek(COMM_PORT *p, WORD num) { short ret; unsigned oflow; if (p->rxbufhead > p->rxbuftail) { if (p->rxbuftail + num > p->rxbufhead) ret = -1; else ret = *(p->rxbuftail+num); } else { if (p->rxbuftail + num < p->rxbufend) ret = *(p->rxbuftail+num); else { oflow = num - (unsigned) (p->rxbufend - (BYTE FAR_ *) p->rxbuftail); #if defined(VERSION70) if (p->rxbuf + oflow > p->rxbufhead) ret = -1; #else if (oflow > (unsigned) (p->rxbufhead - p->rxbuf)) ret = -1; #endif else ret = *(p->rxbuf+oflow); } } return (ret); }