//------------------------------------------------------------------------------ intrusive_ptr<sink_base> console() { if(con) return con; n_throw(logic_error) << ei_msg_c("Call init_console() first!"); }
//------------------------------------------------------------------------------ void init_console() { if(con) n_throw(logic_error) << ei_msg_c("init_console() has already been called."); con = new console_(); }
//------------------------------------------------------------------------------ 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())); } }
//------------------------------------------------------------------------------ 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())); } }
//------------------------------------------------------------------------------ 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)); }
//------------------------------------------------------------------------------ void cout_impl_::flush() { if(fflush(stdout)) n_throw(io_error) << ei_msg_c("fflush() failed."); }
//------------------------------------------------------------------------------ void cout_impl_::put(char x) { if(EOF == fputc(x, stdout)) n_throw(io_error) << ei_msg_c("fputc() failed."); }