Metropoli BBS
VIEWER: clearbuf.c MODE: TEXT (ASCII)
/*
Copyright (C) Magna Carta Software, Inc. 1990.  All Rights Reserved
C COMMUNICATIONS TOOLKIT
COMMIO.C -- Basic serial I/O functions (no data translation)
*/

#include <comm.h>


/*
C_RXFLUSH -- Clears numbytes from the UART's receive buffer.
Arguments:
    COMM_PORT *p -- ptr. to the port;
    WORD         -- number of bytes to clear (0 for empty);
Returns:
    0   -- "numbytes" found.  I.e. buffer may not be empty;
    EOF -- Buffer cleared (< numbytes found);
*/
short c_rxflush(COMM_PORT *p, WORD numbytes)
{
    short ret = 0;
    short savele = p->echo;

    p->echo &= ~LOCAL_ECHO;
    if (numbytes > 0) {
        for (; numbytes > 0; --numbytes)
        if (c_waitc(p, EOF, p->rx_ibdelay) == EOF) {
            ret = EOF;
            break;
        }
    }
    else {
        ret = EOF;
        if (p->rxintnum > 0) p->rxbuftail = p->rxbufhead;
        else for (;;) if (c_waitc(p, EOF, p->rx_ibdelay) == EOF) break;
    }
    p->echo = savele;

    return (ret);
}
[ RETURN TO DIRECTORY ]