fixed reading by using single char buffer
This commit is contained in:
parent
d249f3ae6c
commit
dd5c87c896
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user