2020-02-17 21:11:49 +01:00
|
|
|
//
|
|
|
|
// fdistream.cpp
|
|
|
|
// libscio
|
|
|
|
//
|
|
|
|
// Created by Bob Polis at 2020-02-14
|
|
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "libscio.hpp"
|
2020-02-22 21:18:53 +01:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2020-03-02 13:45:15 +01:00
|
|
|
#include <io.h>
|
2020-02-22 21:18:53 +01:00
|
|
|
#else
|
2020-03-02 13:45:15 +01:00
|
|
|
#include <unistd.h>
|
2020-02-22 21:18:53 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace sc::io;
|
|
|
|
|
|
|
|
std::streambuf::int_type fdinbuf::underflow() {
|
2020-03-02 16:20:36 +01:00
|
|
|
int num = read(_fd, &_ch, 1);
|
2020-02-22 21:18:53 +01:00
|
|
|
if (num <= 0) {
|
2020-03-02 16:20:36 +01:00
|
|
|
return EOF;
|
2020-02-22 21:18:53 +01:00
|
|
|
}
|
2020-03-02 16:20:36 +01:00
|
|
|
setg(&_ch, &_ch, &_ch + 1);
|
2020-02-22 21:18:53 +01:00
|
|
|
return _ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::streamsize fdinbuf::xsgetn(char* s, std::streamsize n) {
|
|
|
|
return read(_fd, s, n);
|
|
|
|
}
|