OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 vfprintf(stderr, format, args); | 50 vfprintf(stderr, format, args); |
51 fprintf(stderr, "\n"); | 51 fprintf(stderr, "\n"); |
52 va_end(args); | 52 va_end(args); |
53 exit(1); | 53 exit(1); |
54 } | 54 } |
55 | 55 |
56 // A file reader that calls Problem() on failure. | 56 // A file reader that calls Problem() on failure. |
57 class BufferedFileReader { | 57 class BufferedFileReader { |
58 public: | 58 public: |
59 BufferedFileReader(const base::FilePath& file_name, const char* kind) { | 59 BufferedFileReader(const base::FilePath& file_name, const char* kind) { |
60 int64_t file_size = 0; | 60 if (!buffer_.Initialize(file_name)) |
61 if (!base::GetFileSize(file_name, &file_size)) | |
62 Problem("Can't read %s file.", kind); | |
63 buffer_.reserve(static_cast<size_t>(file_size)); | |
64 if (!base::ReadFileToString(file_name, &buffer_)) | |
65 Problem("Can't read %s file.", kind); | 61 Problem("Can't read %s file.", kind); |
66 } | 62 } |
67 const uint8_t* data() { | 63 const uint8_t* data() const { return buffer_.data(); } |
68 return reinterpret_cast<const uint8_t*>(buffer_.data()); | 64 size_t length() const { return buffer_.length(); } |
69 } | |
70 size_t length() { return buffer_.length(); } | |
71 | 65 |
72 private: | 66 private: |
73 std::string buffer_; | 67 base::MemoryMappedFile buffer_; |
74 }; | 68 }; |
75 | 69 |
76 void WriteSinkToFile(const courgette::SinkStream *sink, | 70 void WriteSinkToFile(const courgette::SinkStream *sink, |
77 const base::FilePath& output_file) { | 71 const base::FilePath& output_file) { |
78 int count = | 72 int count = |
79 base::WriteFile(output_file, | 73 base::WriteFile(output_file, |
80 reinterpret_cast<const char*>(sink->Buffer()), | 74 reinterpret_cast<const char*>(sink->Buffer()), |
81 static_cast<int>(sink->Length())); | 75 static_cast<int>(sink->Length())); |
82 if (count == -1) | 76 if (count == -1) |
83 Problem("Can't write output."); | 77 Problem("Can't write output."); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); | 510 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); |
517 DisassembleAdjustDiff(values[0], values[1], values[2], | 511 DisassembleAdjustDiff(values[0], values[1], values[2], |
518 cmd_spread_1_adjusted); | 512 cmd_spread_1_adjusted); |
519 } else { | 513 } else { |
520 UsageProblem("No operation specified"); | 514 UsageProblem("No operation specified"); |
521 } | 515 } |
522 } | 516 } |
523 | 517 |
524 return 0; | 518 return 0; |
525 } | 519 } |
OLD | NEW |