示例#1
0
//------------------------------------------------------------------------------
intrusive_ptr<sink_base> console()
{
    if(con)
        return con;
    n_throw(logic_error)
        << ei_msg_c("Call init_console() first!");
}
示例#2
0
//------------------------------------------------------------------------------
void init_console()
{
    if(con)
        n_throw(logic_error)
        << ei_msg_c("init_console() has already been called.");
    con = new console_();
}
示例#3
0
文件: cout.cpp 项目: mjssw/nebula
//------------------------------------------------------------------------------
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;
    }
}
//------------------------------------------------------------------------------
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()));
    }
}
示例#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()));
    }
}
示例#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));
}
示例#7
0
文件: cout.cpp 项目: mjssw/nebula
//------------------------------------------------------------------------------
void cout_impl_::flush() {
    if(fflush(stdout))
        n_throw(io_error) << ei_msg_c("fflush() failed.");
}
示例#8
0
文件: cout.cpp 项目: mjssw/nebula
//------------------------------------------------------------------------------
void cout_impl_::put(char x)
{
    if(EOF == fputc(x, stdout))
        n_throw(io_error) << ei_msg_c("fputc() failed.");
}