示例#1
0
文件: file.cpp 项目: adan830/poseidon
void file_put_contents(const char *path, StreamBuffer contents, bool append){
	const UniqueFile file(::open(path, O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC)));
	if(!file){
		DEBUG_THROW(SystemException);
	}
	for(;;){
		char write_buf[4096];
		const std::size_t bytes_to_write = contents.get(write_buf, sizeof(write_buf));
		if(bytes_to_write == 0){
			break;
		}
		if(::write(file.get(), write_buf, bytes_to_write) < static_cast< ::ssize_t>(bytes_to_write)){
			DEBUG_THROW(SystemException);
		}
	}
}
示例#2
0
	int getFd() const {
		return m_socket.get();
	}
示例#3
0
void
CopyFile(UniqueFile p_dst, FileDescriptor src_fd)
{
    FileDescriptor::WriteContent(Nonnull(p_dst.get()), Nonnull(src_fd));
}