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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 BASE_EXPORT bool IsLink(const FilePath& file_path); | 292 BASE_EXPORT bool IsLink(const FilePath& file_path); |
293 | 293 |
294 // Returns information about the given file path. | 294 // Returns information about the given file path. |
295 BASE_EXPORT bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* info); | 295 BASE_EXPORT bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* info); |
296 | 296 |
297 // Sets the time of the last access and the time of the last modification. | 297 // Sets the time of the last access and the time of the last modification. |
298 BASE_EXPORT bool TouchFile(const FilePath& path, | 298 BASE_EXPORT bool TouchFile(const FilePath& path, |
299 const Time& last_accessed, | 299 const Time& last_accessed, |
300 const Time& last_modified); | 300 const Time& last_modified); |
301 | 301 |
| 302 } // namespace base |
| 303 |
| 304 // ----------------------------------------------------------------------------- |
| 305 |
| 306 namespace file_util { |
| 307 |
| 308 #if defined(OS_POSIX) |
| 309 // Store inode number of |path| in |inode|. Return true on success. |
| 310 BASE_EXPORT bool GetInode(const base::FilePath& path, ino_t* inode); |
| 311 #endif |
| 312 |
302 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. | 313 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. |
303 BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode); | 314 BASE_EXPORT FILE* OpenFile(const base::FilePath& filename, const char* mode); |
304 | 315 |
305 // Closes file opened by OpenFile. Returns true on success. | 316 // Closes file opened by OpenFile. Returns true on success. |
306 BASE_EXPORT bool CloseFile(FILE* file); | 317 BASE_EXPORT bool CloseFile(FILE* file); |
307 | 318 |
308 // Truncates an open file to end at the location of the current file pointer. | 319 // Truncates an open file to end at the location of the current file pointer. |
309 // This is a cross-platform analog to Windows' SetEndOfFile() function. | 320 // This is a cross-platform analog to Windows' SetEndOfFile() function. |
310 BASE_EXPORT bool TruncateFile(FILE* file); | 321 BASE_EXPORT bool TruncateFile(FILE* file); |
311 | 322 |
312 // Reads the given number of bytes from the file into the buffer. Returns | 323 // Reads the given number of bytes from the file into the buffer. Returns |
313 // the number of read bytes, or -1 on error. | 324 // the number of read bytes, or -1 on error. |
314 BASE_EXPORT int ReadFile(const base::FilePath& filename, char* data, int size); | 325 BASE_EXPORT int ReadFile(const base::FilePath& filename, char* data, int size); |
315 | 326 |
316 } // namespace base | |
317 | |
318 // ----------------------------------------------------------------------------- | |
319 | |
320 namespace file_util { | |
321 | |
322 // Writes the given buffer into the file, overwriting any data that was | 327 // Writes the given buffer into the file, overwriting any data that was |
323 // previously there. Returns the number of bytes written, or -1 on error. | 328 // previously there. Returns the number of bytes written, or -1 on error. |
324 BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data, | 329 BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data, |
325 int size); | 330 int size); |
326 #if defined(OS_POSIX) | 331 #if defined(OS_POSIX) |
327 // Append the data to |fd|. Does not close |fd| when done. | 332 // Append the data to |fd|. Does not close |fd| when done. |
328 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); | 333 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); |
329 #endif | 334 #endif |
330 // Append the given buffer into the file. Returns the number of bytes written, | 335 // Append the given buffer into the file. Returns the number of bytes written, |
331 // or -1 on error. | 336 // or -1 on error. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // This function simulates Move(), but unlike Move() it works across volumes. | 461 // This function simulates Move(), but unlike Move() it works across volumes. |
457 // This function is not transactional. | 462 // This function is not transactional. |
458 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 463 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
459 const FilePath& to_path); | 464 const FilePath& to_path); |
460 #endif // defined(OS_WIN) | 465 #endif // defined(OS_WIN) |
461 | 466 |
462 } // namespace internal | 467 } // namespace internal |
463 } // namespace base | 468 } // namespace base |
464 | 469 |
465 #endif // BASE_FILE_UTIL_H_ | 470 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |