Exemplo n.º 1
0
//------------------------------------------------------------------------------
intrusive_ptr<sink_base> console()
{
    if(con)
        return con;
    n_throw(logic_error)
        << ei_msg_c("Call init_console() first!");
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
void init_console()
{
    if(con)
        n_throw(logic_error)
        << ei_msg_c("init_console() has already been called.");
    con = new console_();
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
void cout_impl_::write(const char *x, streamsize n)
{
    while(n > 0)
    {
        const size_t r = fwrite(x, 1, n, stdout);
        if(ferror(stdout))
            n_throw(io_error) << ei_msg_c("fwrite() failed.");
        x += r;
        n -= r;
    }
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
void create_directory(const path &p, file_permission_type fp)
{
    const int r = ::mkdir(p.c_str(), fp);
    if(r != 0)
    {
        n_throw(system::system_error)
            << ei_msg_c("mkdir() failed.")
            << ei_path(p)
            << system::ei_error_code(system::error_code(
                errno, system::system_category()));
    }
}
Exemplo n.º 5
0
//------------------------------------------------------------------------------
void rename(const path &op, const path &np)
{
    const int r = ::rename(op.c_str(), np.c_str());
    if(r != 0)
    {
        n_throw(system::system_error)
            << ei_msg_c("rename() failed.")
            << ei_path(op)
            << system::ei_error_code(system::error_code(
                errno, system::system_category()));
    }
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------
path read_symlink(const path &p)
{
    string buf;
    buf.resize(4096);
    
    const ::ssize_t r = ::readlink(p.c_str(), buf.data(), buf.size());
    if(r == -1)
    {
        n_throw(system::system_error)
            << ei_msg_c("readlink() failed.")
            << ei_path(p)
            << system::ei_error_code(system::error_code(
                errno, system::system_category()));
    }
    
    buf.resize(r);
    
    return path(foundation::move(buf));
}
Exemplo n.º 7
0
//------------------------------------------------------------------------------
void cout_impl_::flush() {
    if(fflush(stdout))
        n_throw(io_error) << ei_msg_c("fflush() failed.");
}
Exemplo n.º 8
0
//------------------------------------------------------------------------------
void cout_impl_::put(char x)
{
    if(EOF == fputc(x, stdout))
        n_throw(io_error) << ei_msg_c("fputc() failed.");
}