16#ifdef PROTOBUFLITE_HAS_NO_ZEROCOPYSTREAM
59#include <google/protobuf/io/zero_copy_stream_impl.h>
60#include <google/protobuf/stubs/common.h>
61#include <google/protobuf/stubs/logging.h>
62#include <google/protobuf/stubs/stl_util.h>
69int close_no_eintr(
int fd) {
73 }
while (result < 0 && errno == EINTR);
82FileInputStream::FileInputStream(
int file_descriptor,
int block_size)
83 : copying_input_(file_descriptor),
84 impl_(©ing_input_, block_size) {
87bool FileInputStream::Close() {
88 return copying_input_.Close();
91bool FileInputStream::Next(
const void** data,
int* size) {
92 return impl_.Next(data, size);
95void FileInputStream::BackUp(
int count) {
99bool FileInputStream::Skip(
int count) {
100 return impl_.Skip(count);
103google::protobuf::int64 FileInputStream::ByteCount()
const {
104 return impl_.ByteCount();
107FileInputStream::CopyingFileInputStream::CopyingFileInputStream(
109 : file_(file_descriptor),
110 close_on_delete_(false),
113 previous_seek_failed_(false) {
116FileInputStream::CopyingFileInputStream::~CopyingFileInputStream() {
117 if (close_on_delete_) {
119 GOOGLE_LOG(ERROR) <<
"close() failed: " << strerror(errno_);
124bool FileInputStream::CopyingFileInputStream::Close() {
125 GOOGLE_CHECK(!is_closed_);
128 if (close_no_eintr(file_) != 0) {
139int FileInputStream::CopyingFileInputStream::Read(
void* buffer,
int size) {
140 GOOGLE_CHECK(!is_closed_);
144 result =
read(file_, buffer, size);
145 }
while (result < 0 && errno == EINTR);
155int FileInputStream::CopyingFileInputStream::Skip(
int count) {
156 GOOGLE_CHECK(!is_closed_);
158 if (!previous_seek_failed_ &&
159 lseek(file_, count, SEEK_CUR) != (off_t)-1) {
167 previous_seek_failed_ =
true;
170 return google::protobuf::io::CopyingInputStream::Skip(count);
176FileOutputStream::FileOutputStream(
int file_descriptor,
int block_size)
177 : copying_output_(file_descriptor),
178 impl_(©ing_output_, block_size) {
181FileOutputStream::~FileOutputStream() {
185bool FileOutputStream::Close() {
186 bool flush_succeeded = impl_.Flush();
187 return copying_output_.Close() && flush_succeeded;
190bool FileOutputStream::Flush() {
191 return impl_.Flush();
194bool FileOutputStream::Next(
void** data,
int* size) {
195 return impl_.Next(data, size);
198void FileOutputStream::BackUp(
int count) {
202google::protobuf::int64 FileOutputStream::ByteCount()
const {
203 return impl_.ByteCount();
206FileOutputStream::CopyingFileOutputStream::CopyingFileOutputStream(
208 : file_(file_descriptor),
209 close_on_delete_(false),
214FileOutputStream::CopyingFileOutputStream::~CopyingFileOutputStream() {
215 if (close_on_delete_) {
217 GOOGLE_LOG(ERROR) <<
"close() failed: " << strerror(errno_);
222bool FileOutputStream::CopyingFileOutputStream::Close() {
223 GOOGLE_CHECK(!is_closed_);
226 if (close_no_eintr(file_) != 0) {
237bool FileOutputStream::CopyingFileOutputStream::Write(
238 const void* buffer,
int size) {
239 GOOGLE_CHECK(!is_closed_);
240 int total_written = 0;
242 const google::protobuf::uint8* buffer_base =
reinterpret_cast<const google::protobuf::uint8*
>(buffer);
244 while (total_written < size) {
247 bytes =
write(file_, buffer_base + total_written, size - total_written);
248 }
while (bytes < 0 && errno == EINTR);
266 total_written += bytes;
bool write(const Pathname &path_r, const std::string &key_r, const std::string &val_r, const std::string &newcomment_r)
Add or change a value in sysconfig file path_r.
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.