28class fdstream :
public std::iostream {
29 struct buffer_t :
public std::basic_streambuf<char> {
33 explicit buffer_t(
int _fd) : fd(_fd) {}
40 int_type overflow(int_type c = traits_type::eof());
42 setg(eback(), eback(), eback());
43 setp(pbase(), epptr());
46 std::function<void()> closefn;
49 explicit fdstream(
int fd = -1) : std::iostream(&buffer), buffer(fd) { init(&buffer); }
51 if (closefn) closefn();
53 void connect(
int fd) {
58 void setclose(std::function<
void()> fn) { closefn = fn; }