1
0
forked from Alepha/Alepha
Files
Alepha/IOStreams/OutUnixFileBuf.h

48 lines
877 B
C++

static_assert( __cplusplus > 2020'99 );
#pragma once
#include <Alepha/Alepha.h>
#include <unistd.h>
#include <streambuf>
namespace Alepha::Hydrogen::IOStreams ::detail:: OutUnixFileBuf_m
{
inline namespace exports
{
class OutUnixFileBuf;
}
class exports::OutUnixFileBuf
: virtual public std::streambuf
{
private:
int fd;
int
overflow( const int ch_ ) override
{
if( ch_ == EOF ) throw std::runtime_error{ "Unexpected EOF" };
const char ch= ch_;
xsputn( &ch, 1 );
return ch_;
}
std::streamsize
xsputn( const char *const data, const std::streamsize amt ) override
{
return ::write( fd, data, amt );
}
public:
explicit OutUnixFileBuf( const int fd ) : fd( fd ) {}
};
}
namespace Alepha::Hydrogen::IOStreams::inline exports::inline OutUnixFileBuf_m
{
using namespace detail::OutUnixFileBuf_m::exports;
}