Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: third_party/crashpad/crashpad/util/file/file_io_posix.cc

Issue 2773813002: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 (Closed)
Patch Set: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/crashpad/crashpad/util/file/file_io_posix.cc
diff --git a/third_party/crashpad/crashpad/util/file/file_io_posix.cc b/third_party/crashpad/crashpad/util/file/file_io_posix.cc
index 1534db15a68cab2cdb057a8edae1a29c92ef1553..494412440f493b6802fa0b00a3103c99716bdae6 100644
--- a/third_party/crashpad/crashpad/util/file/file_io_posix.cc
+++ b/third_party/crashpad/crashpad/util/file/file_io_posix.cc
@@ -19,63 +19,49 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <algorithm>
+#include <limits>
+
#include "base/files/file_path.h"
#include "base/logging.h"
-#include "base/numerics/safe_conversions.h"
#include "base/posix/eintr_wrapper.h"
+namespace crashpad {
+
namespace {
struct ReadTraits {
- using VoidBufferType = void*;
- using CharBufferType = char*;
- static crashpad::FileOperationResult Operate(int fd,
- CharBufferType buffer,
- size_t size) {
+ using BufferType = void*;
+ static FileOperationResult Operate(int fd, BufferType buffer, size_t size) {
return read(fd, buffer, size);
}
};
struct WriteTraits {
- using VoidBufferType = const void*;
- using CharBufferType = const char*;
- static crashpad::FileOperationResult Operate(int fd,
- CharBufferType buffer,
- size_t size) {
+ using BufferType = const void*;
+ static FileOperationResult Operate(int fd, BufferType buffer, size_t size) {
return write(fd, buffer, size);
}
};
template <typename Traits>
-crashpad::FileOperationResult
-ReadOrWrite(int fd, typename Traits::VoidBufferType buffer, size_t size) {
- typename Traits::CharBufferType buffer_c =
- reinterpret_cast<typename Traits::CharBufferType>(buffer);
-
- crashpad::FileOperationResult total_bytes = 0;
- while (size > 0) {
- crashpad::FileOperationResult bytes =
- HANDLE_EINTR(Traits::Operate(fd, buffer_c, size));
- if (bytes < 0) {
- return bytes;
- } else if (bytes == 0) {
- break;
- }
-
- buffer_c += bytes;
- size -= bytes;
- total_bytes += bytes;
+FileOperationResult ReadOrWrite(int fd,
+ typename Traits::BufferType buffer,
+ size_t size) {
+ constexpr size_t kMaxReadWriteSize =
+ static_cast<size_t>(std::numeric_limits<ssize_t>::max());
+ const size_t requested_bytes = std::min(size, kMaxReadWriteSize);
+
+ FileOperationResult transacted_bytes =
+ HANDLE_EINTR(Traits::Operate(fd, buffer, requested_bytes));
+ if (transacted_bytes < 0) {
+ return -1;
}
- return total_bytes;
+ DCHECK_LE(static_cast<size_t>(transacted_bytes), requested_bytes);
+ return transacted_bytes;
}
-} // namespace
-
-namespace crashpad {
-
-namespace {
-
FileHandle OpenFileForOutput(int rdwr_or_wronly,
const base::FilePath& path,
FileWriteMode mode,
@@ -108,16 +94,23 @@ FileHandle OpenFileForOutput(int rdwr_or_wronly,
} // namespace
-FileOperationResult ReadFile(FileHandle file, void* buffer, size_t size) {
- return ReadOrWrite<ReadTraits>(file, buffer, size);
-}
+namespace internal {
+
+const char kNativeReadFunctionName[] = "read";
+const char kNativeWriteFunctionName[] = "write";
-FileOperationResult WriteFile(FileHandle file,
- const void* buffer,
- size_t size) {
+FileOperationResult NativeWriteFile(FileHandle file,
+ const void* buffer,
+ size_t size) {
return ReadOrWrite<WriteTraits>(file, buffer, size);
}
+} // namespace internal
+
+FileOperationResult ReadFile(FileHandle file, void* buffer, size_t size) {
+ return ReadOrWrite<ReadTraits>(file, buffer, size);
+}
+
FileHandle OpenFileForRead(const base::FilePath& path) {
return HANDLE_EINTR(
open(path.value().c_str(), O_RDONLY | O_NOCTTY | O_CLOEXEC));
@@ -199,4 +192,18 @@ FileOffset LoggingFileSizeByHandle(FileHandle file) {
return st.st_size;
}
+FileHandle StdioFileHandle(StdioStream stdio_stream) {
+ switch (stdio_stream) {
+ case StdioStream::kStandardInput:
+ return STDIN_FILENO;
+ case StdioStream::kStandardOutput:
+ return STDOUT_FILENO;
+ case StdioStream::kStandardError:
+ return STDERR_FILENO;
+ }
+
+ NOTREACHED();
+ return kInvalidFileHandle;
+}
+
} // namespace crashpad
« no previous file with comments | « third_party/crashpad/crashpad/util/file/file_io.cc ('k') | third_party/crashpad/crashpad/util/file/file_io_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698