libscio/fdostream.cpp
2020-04-24 10:04:48 +02:00

38 lines
815 B
C++

//
// fdostream.cpp
// libscio
//
// Created by Bob Polis at 2020-02-14
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "libscio.hpp"
#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif
std::streambuf::int_type sc::io::fdoutbuf::overflow(std::streambuf::int_type c) {
if (c != EOF) {
int res;
if ((res = ::write(_fd, &c, 1)) != 1) {
return EOF;
}
else {
std::cerr << "write result = " << res << ", errno = " << errno << '\n';
}
}
return c;
}
std::streamsize sc::io::fdoutbuf::xsputn(const char* s, std::streamsize num) {
int res = ::write(_fd, s, num);
if (res != num) {
std::cerr << "write result = " << res << ", errno = " << errno << '\n';
return EOF;
}
return res;
}