diff --git a/fdostream.cpp b/fdiobuf.cpp similarity index 59% rename from fdostream.cpp rename to fdiobuf.cpp index d087312..7780d90 100644 --- a/fdostream.cpp +++ b/fdiobuf.cpp @@ -1,5 +1,5 @@ // -// fdostream.cpp +// fdiobuf.cpp // libscio // // Created by Bob Polis at 2020-02-14 @@ -14,7 +14,20 @@ #include #endif -std::streambuf::int_type sc::io::fdoutbuf::overflow(std::streambuf::int_type c) { +std::streambuf::int_type sc::io::fdiobuf::underflow() { + int num = ::read(_fd, &_ch, 1); + if (num <= 0) { + return EOF; + } + setg(&_ch, &_ch, &_ch + 1); + return _ch; +} + +std::streamsize sc::io::fdiobuf::xsgetn(char* s, std::streamsize n) { + return ::read(_fd, s, n); +} + +std::streambuf::int_type sc::io::fdiobuf::overflow(std::streambuf::int_type c) { if (c != EOF) { int res; if ((res = ::write(_fd, &c, 1)) != 1) { @@ -27,7 +40,7 @@ std::streambuf::int_type sc::io::fdoutbuf::overflow(std::streambuf::int_type c) return c; } -std::streamsize sc::io::fdoutbuf::xsputn(const char* s, std::streamsize num) { +std::streamsize sc::io::fdiobuf::xsputn(const char* s, std::streamsize num) { int res = ::write(_fd, s, num); if (res != num) { std::cerr << "write result = " << res << ", errno = " << errno << '\n'; diff --git a/fdistream.cpp b/fdistream.cpp deleted file mode 100644 index 6520a2e..0000000 --- a/fdistream.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// fdistream.cpp -// libscio -// -// Created by Bob Polis at 2020-02-14 -// Copyright (c) 2020 SwiftCoder. All rights reserved. -// - -#include "libscio.hpp" - -#ifdef _MSC_VER - #include -#else - #include -#endif - -using namespace sc::io; - -std::streambuf::int_type fdinbuf::underflow() { - int num = read(_fd, &_ch, 1); - if (num <= 0) { - return EOF; - } - setg(&_ch, &_ch, &_ch + 1); - return _ch; -} - -std::streamsize fdinbuf::xsgetn(char* s, std::streamsize n) { - return read(_fd, s, n); -}