OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "update_engine/utils.h" | 5 #include "update_engine/utils.h" |
6 #include <sys/mount.h> | 6 #include <sys/mount.h> |
7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <dirent.h> | 9 #include <dirent.h> |
10 #include <errno.h> | 10 #include <errno.h> |
| 11 #include <fcntl.h> |
11 #include <stdio.h> | 12 #include <stdio.h> |
12 #include <stdlib.h> | 13 #include <stdlib.h> |
13 #include <string.h> | 14 #include <string.h> |
14 #include <unistd.h> | 15 #include <unistd.h> |
15 #include <algorithm> | 16 #include <algorithm> |
16 #include "chromeos/obsolete_logging.h" | 17 #include "chromeos/obsolete_logging.h" |
| 18 #include "update_engine/file_writer.h" |
17 | 19 |
18 using std::min; | 20 using std::min; |
19 using std::string; | 21 using std::string; |
20 using std::vector; | 22 using std::vector; |
21 | 23 |
22 namespace chromeos_update_engine { | 24 namespace chromeos_update_engine { |
23 | 25 |
24 namespace utils { | 26 namespace utils { |
25 | 27 |
| 28 bool WriteFile(const char* path, const char* data, int data_len) { |
| 29 DirectFileWriter writer; |
| 30 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path, |
| 31 O_WRONLY | O_CREAT | O_TRUNC, |
| 32 0666)); |
| 33 ScopedFileWriterCloser closer(&writer); |
| 34 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len)); |
| 35 return true; |
| 36 } |
| 37 |
26 bool ReadFile(const std::string& path, std::vector<char>* out) { | 38 bool ReadFile(const std::string& path, std::vector<char>* out) { |
27 CHECK(out); | 39 CHECK(out); |
28 FILE* fp = fopen(path.c_str(), "r"); | 40 FILE* fp = fopen(path.c_str(), "r"); |
29 if (!fp) | 41 if (!fp) |
30 return false; | 42 return false; |
31 const size_t kChunkSize = 1024; | 43 const size_t kChunkSize = 1024; |
32 size_t read_size; | 44 size_t read_size; |
33 do { | 45 do { |
34 char buf[kChunkSize]; | 46 char buf[kChunkSize]; |
35 read_size = fread(buf, 1, kChunkSize, fp); | 47 read_size = fread(buf, 1, kChunkSize, fp); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 TEST_AND_RETURN_FALSE_ERRNO(umount(mountpoint.c_str()) == 0); | 256 TEST_AND_RETURN_FALSE_ERRNO(umount(mountpoint.c_str()) == 0); |
245 return true; | 257 return true; |
246 } | 258 } |
247 | 259 |
248 const string kStatefulPartition = "/mnt/stateful_partition"; | 260 const string kStatefulPartition = "/mnt/stateful_partition"; |
249 | 261 |
250 } // namespace utils | 262 } // namespace utils |
251 | 263 |
252 } // namespace chromeos_update_engine | 264 } // namespace chromeos_update_engine |
253 | 265 |
OLD | NEW |