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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
7 | 7 |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // Calls pread() repeatedly until count bytes are read, or EOF is reached. | 30 // Calls pread() repeatedly until count bytes are read, or EOF is reached. |
31 // Returns number of bytes read in *bytes_read. Returns true on success. | 31 // Returns number of bytes read in *bytes_read. Returns true on success. |
32 bool PReadAll(int fd, void* buf, size_t count, off_t offset, | 32 bool PReadAll(int fd, void* buf, size_t count, off_t offset, |
33 ssize_t* out_bytes_read); | 33 ssize_t* out_bytes_read); |
34 | 34 |
35 // Returns the entire contents of the file at path. Returns true on success. | 35 // Returns the entire contents of the file at path. Returns true on success. |
36 bool ReadFile(const std::string& path, std::vector<char>* out); | 36 bool ReadFile(const std::string& path, std::vector<char>* out); |
37 bool ReadFileToString(const std::string& path, std::string* out); | 37 bool ReadFileToString(const std::string& path, std::string* out); |
38 | 38 |
| 39 // Returns the size of the file at path. If the file doesn't exist or some |
| 40 // error occurrs, -1 is returned. |
| 41 off_t FileSize(const std::string& path); |
| 42 |
39 std::string ErrnoNumberAsString(int err); | 43 std::string ErrnoNumberAsString(int err); |
40 | 44 |
41 // Strips duplicate slashes, and optionally removes all trailing slashes. | 45 // Strips duplicate slashes, and optionally removes all trailing slashes. |
42 // Does not compact /./ or /../. | 46 // Does not compact /./ or /../. |
43 std::string NormalizePath(const std::string& path, bool strip_trailing_slash); | 47 std::string NormalizePath(const std::string& path, bool strip_trailing_slash); |
44 | 48 |
45 // Returns true if the file exists for sure. Returns false if it doesn't exist, | 49 // Returns true if the file exists for sure. Returns false if it doesn't exist, |
46 // or an error occurs. | 50 // or an error occurs. |
47 bool FileExists(const char* path); | 51 bool FileExists(const char* path); |
48 | 52 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 bool _success = (_x); \ | 268 bool _success = (_x); \ |
265 if (!_success) { \ | 269 if (!_success) { \ |
266 LOG(ERROR) << #_x " failed."; \ | 270 LOG(ERROR) << #_x " failed."; \ |
267 return; \ | 271 return; \ |
268 } \ | 272 } \ |
269 } while (0) | 273 } while (0) |
270 | 274 |
271 | 275 |
272 | 276 |
273 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 277 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
OLD | NEW |