Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains utility functions for dealing with the local | 5 // This file contains utility functions for dealing with the local |
| 6 // filesystem. | 6 // filesystem. |
| 7 | 7 |
| 8 #ifndef BASE_FILE_UTIL_H_ | 8 #ifndef BASE_FILE_UTIL_H_ |
| 9 #define BASE_FILE_UTIL_H_ | 9 #define BASE_FILE_UTIL_H_ |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 BASE_EXPORT bool TextContentsEqual(const FilePath& filename1, | 130 BASE_EXPORT bool TextContentsEqual(const FilePath& filename1, |
| 131 const FilePath& filename2); | 131 const FilePath& filename2); |
| 132 | 132 |
| 133 // Read the file at |path| into |contents|, returning true on success. | 133 // Read the file at |path| into |contents|, returning true on success. |
| 134 // This function fails if the |path| contains path traversal components ('..'). | 134 // This function fails if the |path| contains path traversal components ('..'). |
| 135 // |contents| may be NULL, in which case this function is useful for its | 135 // |contents| may be NULL, in which case this function is useful for its |
| 136 // side effect of priming the disk cache. | 136 // side effect of priming the disk cache. |
| 137 // Useful for unit tests. | 137 // Useful for unit tests. |
| 138 BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); | 138 BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); |
| 139 | 139 |
| 140 // Read the file at |path| into |contents|, returning true on success. | |
| 141 // This function has an additional check on the maximum size of the file. | |
| 142 // When the file size is greater than |max_size|, the function reads |max_size| | |
| 143 // bytes into |contents| and returns false. | |
| 144 // This function fails if the |path| contains path traversal components ('..'). | |
| 145 // |contents| may be NULL, in which case this function is useful for its | |
| 146 // side effect of priming the disk cache. | |
| 147 // Useful for unit tests. | |
|
Andrew T Wilson (Slow)
2014/02/17 14:38:22
Not sure what "Useful for unit tests" means - perh
kaliamoorthi
2014/02/18 11:50:50
Done.
| |
| 148 BASE_EXPORT bool ReadFileToString(const FilePath& path, | |
| 149 std::string* contents, | |
| 150 size_t max_size); | |
| 151 | |
| 140 #if defined(OS_POSIX) | 152 #if defined(OS_POSIX) |
| 141 | 153 |
| 142 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result | 154 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result |
| 143 // in |buffer|. This function is protected against EINTR and partial reads. | 155 // in |buffer|. This function is protected against EINTR and partial reads. |
| 144 // Returns true iff |bytes| bytes have been successfully read from |fd|. | 156 // Returns true iff |bytes| bytes have been successfully read from |fd|. |
| 145 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); | 157 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); |
| 146 | 158 |
| 147 // Creates a symbolic link at |symlink| pointing to |target|. Returns | 159 // Creates a symbolic link at |symlink| pointing to |target|. Returns |
| 148 // false on failure. | 160 // false on failure. |
| 149 BASE_EXPORT bool CreateSymbolicLink(const FilePath& target, | 161 BASE_EXPORT bool CreateSymbolicLink(const FilePath& target, |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 // This function simulates Move(), but unlike Move() it works across volumes. | 468 // This function simulates Move(), but unlike Move() it works across volumes. |
| 457 // This function is not transactional. | 469 // This function is not transactional. |
| 458 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 470 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
| 459 const FilePath& to_path); | 471 const FilePath& to_path); |
| 460 #endif // defined(OS_WIN) | 472 #endif // defined(OS_WIN) |
| 461 | 473 |
| 462 } // namespace internal | 474 } // namespace internal |
| 463 } // namespace base | 475 } // namespace base |
| 464 | 476 |
| 465 #endif // BASE_FILE_UTIL_H_ | 477 #endif // BASE_FILE_UTIL_H_ |
| OLD | NEW |