abseil-cpp/absl/strings/internal/str_format/output.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/strings/internal/str_format/output.h"
16 
17 #include <errno.h>
18 #include <cstring>
19 
20 namespace absl {
22 namespace str_format_internal {
23 
24 namespace {
25 struct ClearErrnoGuard {
26  ClearErrnoGuard() : old_value(errno) { errno = 0; }
27  ~ClearErrnoGuard() {
28  if (!errno) errno = old_value;
29  }
30  int old_value;
31 };
32 } // namespace
33 
35  size_t to_write = std::min(v.size(), size_);
36  std::memcpy(buffer_, v.data(), to_write);
37  buffer_ += to_write;
38  size_ -= to_write;
39  total_written_ += v.size();
40 }
41 
43  while (!v.empty() && !error_) {
44  // Reset errno to zero in case the libc implementation doesn't set errno
45  // when a failure occurs.
46  ClearErrnoGuard guard;
47 
48  if (size_t result = std::fwrite(v.data(), 1, v.size(), output_)) {
49  // Some progress was made.
50  count_ += result;
51  v.remove_prefix(result);
52  } else {
53  if (errno == EINTR) {
54  continue;
55  } else if (errno) {
56  error_ = errno;
57  } else if (std::ferror(output_)) {
58  // Non-POSIX compliant libc implementations may not set errno, so we
59  // have check the streams error indicator.
60  error_ = EBADF;
61  } else {
62  // We're likely on a non-POSIX system that encountered EINTR but had no
63  // way of reporting it.
64  continue;
65  }
66  }
67  }
68 }
69 
70 } // namespace str_format_internal
72 } // namespace absl
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
absl::str_format_internal::FILERawSink::error_
int error_
Definition: abseil-cpp/absl/strings/internal/str_format/output.h:66
absl::str_format_internal::BufferRawSink::total_written_
size_t total_written_
Definition: abseil-cpp/absl/strings/internal/str_format/output.h:49
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::str_format_internal::FILERawSink::output_
std::FILE * output_
Definition: abseil-cpp/absl/strings/internal/str_format/output.h:65
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
absl::str_format_internal::FILERawSink::Write
void Write(string_view v)
Definition: abseil-cpp/absl/strings/internal/str_format/output.cc:42
absl::str_format_internal::BufferRawSink::size_
size_t size_
Definition: abseil-cpp/absl/strings/internal/str_format/output.h:48
min
#define min(a, b)
Definition: qsort.h:83
absl::str_format_internal::BufferRawSink::Write
void Write(string_view v)
Definition: abseil-cpp/absl/strings/internal/str_format/output.cc:34
absl::str_format_internal::FILERawSink::count_
size_t count_
Definition: abseil-cpp/absl/strings/internal/str_format/output.h:67
absl::str_format_internal::BufferRawSink::buffer_
char * buffer_
Definition: abseil-cpp/absl/strings/internal/str_format/output.h:47
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
str_format_internal
errno.h
old_value
int old_value
Definition: abseil-cpp/absl/strings/internal/str_format/output.cc:30


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:36