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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 const FilePath& filename2); | 126 const FilePath& filename2); |
127 | 127 |
128 // Returns true if the contents of the two text files given are equal, false | 128 // Returns true if the contents of the two text files given are equal, false |
129 // otherwise. This routine treats "\r\n" and "\n" as equivalent. | 129 // otherwise. This routine treats "\r\n" and "\n" as equivalent. |
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, which is useful for unit tests. |
brettw
2014/02/18 05:24:33
Can you document that this replaces rather than ap
kaliamoorthi
2014/02/18 11:50:50
Done.
| |
137 // Useful for unit tests. | |
138 BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); | 137 BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); |
139 | 138 |
139 // Read the file at |path| into |contents|, returning true on success. | |
140 // This function has an additional check on the maximum size of the file. | |
141 // When the file size is greater than |max_size|, the function reads |max_size| | |
142 // bytes into |contents| and returns false. | |
143 // This function fails if the |path| contains path traversal components ('..'). | |
144 // |contents| may be NULL, in which case this function is useful for its | |
145 // side effect of priming the disk cache, which is useful for unit tests. | |
146 BASE_EXPORT bool ReadFileToString(const FilePath& path, | |
147 std::string* contents, | |
148 size_t max_size); | |
149 | |
140 #if defined(OS_POSIX) | 150 #if defined(OS_POSIX) |
141 | 151 |
142 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result | 152 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result |
143 // in |buffer|. This function is protected against EINTR and partial reads. | 153 // in |buffer|. This function is protected against EINTR and partial reads. |
144 // Returns true iff |bytes| bytes have been successfully read from |fd|. | 154 // Returns true iff |bytes| bytes have been successfully read from |fd|. |
145 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); | 155 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); |
146 | 156 |
147 // Creates a symbolic link at |symlink| pointing to |target|. Returns | 157 // Creates a symbolic link at |symlink| pointing to |target|. Returns |
148 // false on failure. | 158 // false on failure. |
149 BASE_EXPORT bool CreateSymbolicLink(const FilePath& target, | 159 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. | 466 // This function simulates Move(), but unlike Move() it works across volumes. |
457 // This function is not transactional. | 467 // This function is not transactional. |
458 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 468 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
459 const FilePath& to_path); | 469 const FilePath& to_path); |
460 #endif // defined(OS_WIN) | 470 #endif // defined(OS_WIN) |
461 | 471 |
462 } // namespace internal | 472 } // namespace internal |
463 } // namespace base | 473 } // namespace base |
464 | 474 |
465 #endif // BASE_FILE_UTIL_H_ | 475 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |