#include "ifdnstreambuf.ih"

int IFdNStreambuf::underflow()
{
    if (gptr() < egptr())
        return *gptr();

    int nread = read(d_fd, d_buffer, d_n);

    if (nread <= 0)
        return EOF;

    setg(d_buffer, d_buffer, d_buffer + nread);
    return static_cast<unsigned char>(*gptr());
}
