fixed reading by using single char buffer

This commit is contained in:
Bob Polis 2020-03-02 16:20:36 +01:00
parent d249f3ae6c
commit dd5c87c896
2 changed files with 4 additions and 13 deletions

View File

@ -16,20 +16,12 @@
using namespace sc::io;
std::streambuf::int_type fdinbuf::uflow() {
if (_ch == EOF) {
return underflow();
}
return _ch;
}
std::streambuf::int_type fdinbuf::underflow() {
char c;
int num = read(_fd, &c, 1);
int num = read(_fd, &_ch, 1);
if (num <= 0) {
_ch = EOF;
return EOF;
}
_ch = c;
setg(&_ch, &_ch, &_ch + 1);
return _ch;
}

View File

@ -44,9 +44,8 @@ namespace sc {
protected:
int _fd;
int_type _ch {EOF};
char _ch {};
int_type uflow() override;
int_type underflow() override;
std::streamsize xsgetn(char* s, std::streamsize n) override;
};