added error messages when write fails

This commit is contained in:
Bob Polis 2020-04-24 10:04:48 +02:00
parent 363424f15a
commit c6994e6983

View File

@ -16,13 +16,22 @@
std::streambuf::int_type sc::io::fdoutbuf::overflow(std::streambuf::int_type c) { std::streambuf::int_type sc::io::fdoutbuf::overflow(std::streambuf::int_type c) {
if (c != EOF) { if (c != EOF) {
if (::write(_fd, &c, 1) != 1) { int res;
if ((res = ::write(_fd, &c, 1)) != 1) {
return EOF; return EOF;
} }
else {
std::cerr << "write result = " << res << ", errno = " << errno << '\n';
}
} }
return c; return c;
} }
std::streamsize sc::io::fdoutbuf::xsputn(const char* s, std::streamsize num) { std::streamsize sc::io::fdoutbuf::xsputn(const char* s, std::streamsize num) {
return ::write(_fd, s, num); int res = ::write(_fd, s, num);
if (res != num) {
std::cerr << "write result = " << res << ", errno = " << errno << '\n';
return EOF;
}
return res;
} }