libscio/fdostream.cpp

38 lines
815 B
C++
Raw Normal View History

2020-02-14 18:17:17 +01:00
//
// fdostream.cpp
// libscio
//
// Created by Bob Polis at 2020-02-14
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "libscio.hpp"
2020-02-14 18:17:17 +01:00
#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) {
2020-04-24 10:04:48 +02:00
int res;
if ((res = ::write(_fd, &c, 1)) != 1) {
2020-02-14 18:17:17 +01:00
return EOF;
}
2020-04-24 10:04:48 +02:00
else {
std::cerr << "write result = " << res << ", errno = " << errno << '\n';
}
2020-02-14 18:17:17 +01:00
}
return c;
}
std::streamsize sc::io::fdoutbuf::xsputn(const char* s, std::streamsize num) {
2020-04-24 10:04:48 +02:00
int res = ::write(_fd, s, num);
if (res != num) {
std::cerr << "write result = " << res << ", errno = " << errno << '\n';
return EOF;
}
return res;
2020-02-14 18:17:17 +01:00
}