16 #ifdef PROTOBUFLITE_HAS_NO_ZEROCOPYSTREAM 53 #include <sys/types.h> 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> 69 int close_no_eintr(
int fd) {
73 }
while (result < 0 && errno == EINTR);
83 : copying_input_(file_descriptor),
84 impl_(©ing_input_, block_size) {
87 bool FileInputStream::Close() {
88 return copying_input_.Close();
91 bool FileInputStream::Next(
const void** data,
int* size) {
92 return impl_.Next(data, size);
95 void FileInputStream::BackUp(
int count) {
99 bool FileInputStream::Skip(
int count) {
100 return impl_.Skip(count);
103 google::protobuf::int64 FileInputStream::ByteCount()
const {
104 return impl_.ByteCount();
107 FileInputStream::CopyingFileInputStream::CopyingFileInputStream(
109 : file_(file_descriptor),
110 close_on_delete_(false),
113 previous_seek_failed_(false) {
116 FileInputStream::CopyingFileInputStream::~CopyingFileInputStream() {
117 if (close_on_delete_) {
119 GOOGLE_LOG(ERROR) <<
"close() failed: " <<
strerror(errno_);
124 bool FileInputStream::CopyingFileInputStream::Close() {
125 GOOGLE_CHECK(!is_closed_);
128 if (close_no_eintr(file_) != 0) {
139 int FileInputStream::CopyingFileInputStream::Read(
void* buffer,
int size) {
140 GOOGLE_CHECK(!is_closed_);
144 result =
read(file_, buffer, size);
145 }
while (result < 0 && errno == EINTR);
155 int 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);
177 : copying_output_(file_descriptor),
178 impl_(©ing_output_, block_size) {
181 FileOutputStream::~FileOutputStream() {
185 bool FileOutputStream::Close() {
186 bool flush_succeeded = impl_.Flush();
187 return copying_output_.Close() && flush_succeeded;
190 bool FileOutputStream::Flush() {
191 return impl_.Flush();
194 bool FileOutputStream::Next(
void** data,
int* size) {
195 return impl_.Next(data, size);
198 void FileOutputStream::BackUp(
int count) {
202 google::protobuf::int64 FileOutputStream::ByteCount()
const {
203 return impl_.ByteCount();
206 FileOutputStream::CopyingFileOutputStream::CopyingFileOutputStream(
208 : file_(file_descriptor),
209 close_on_delete_(false),
214 FileOutputStream::CopyingFileOutputStream::~CopyingFileOutputStream() {
215 if (close_on_delete_) {
217 GOOGLE_LOG(ERROR) <<
"close() failed: " <<
strerror(errno_);
222 bool FileOutputStream::CopyingFileOutputStream::Close() {
223 GOOGLE_CHECK(!is_closed_);
226 if (close_no_eintr(file_) != 0) {
237 bool 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;
google::protobuf::io::FileInputStream FileInputStream
std::string strerror(int errno_r)
Return string describing the error_r code.
google::protobuf::io::FileOutputStream FileOutputStream
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
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.