| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 10 #pragma once |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 BASE_API bool TouchFile(const FilePath& path, | 336 BASE_API bool TouchFile(const FilePath& path, |
| 337 const base::Time& last_accessed, | 337 const base::Time& last_accessed, |
| 338 const base::Time& last_modified); | 338 const base::Time& last_modified); |
| 339 | 339 |
| 340 // Set the time of the last modification. Useful for unit tests. | 340 // Set the time of the last modification. Useful for unit tests. |
| 341 BASE_API bool SetLastModifiedTime(const FilePath& path, | 341 BASE_API bool SetLastModifiedTime(const FilePath& path, |
| 342 const base::Time& last_modified); | 342 const base::Time& last_modified); |
| 343 | 343 |
| 344 #if defined(OS_POSIX) | 344 #if defined(OS_POSIX) |
| 345 // Store inode number of |path| in |inode|. Return true on success. | 345 // Store inode number of |path| in |inode|. Return true on success. |
| 346 BASE_API bool GetInode(const FilePath& path, ino_t* inode); | 346 bool GetInode(const FilePath& path, ino_t* inode); |
| 347 #endif | 347 #endif |
| 348 | 348 |
| 349 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. | 349 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. |
| 350 BASE_API FILE* OpenFile(const FilePath& filename, const char* mode); | 350 BASE_API FILE* OpenFile(const FilePath& filename, const char* mode); |
| 351 | 351 |
| 352 // Closes file opened by OpenFile. Returns true on success. | 352 // Closes file opened by OpenFile. Returns true on success. |
| 353 BASE_API bool CloseFile(FILE* file); | 353 BASE_API bool CloseFile(FILE* file); |
| 354 | 354 |
| 355 // Truncates an open file to end at the location of the current file pointer. | 355 // Truncates an open file to end at the location of the current file pointer. |
| 356 // This is a cross-platform analog to Windows' SetEndOfFile() function. | 356 // This is a cross-platform analog to Windows' SetEndOfFile() function. |
| 357 BASE_API bool TruncateFile(FILE* file); | 357 BASE_API bool TruncateFile(FILE* file); |
| 358 | 358 |
| 359 // Reads the given number of bytes from the file into the buffer. Returns | 359 // Reads the given number of bytes from the file into the buffer. Returns |
| 360 // the number of read bytes, or -1 on error. | 360 // the number of read bytes, or -1 on error. |
| 361 BASE_API int ReadFile(const FilePath& filename, char* data, int size); | 361 BASE_API int ReadFile(const FilePath& filename, char* data, int size); |
| 362 | 362 |
| 363 // Writes the given buffer into the file, overwriting any data that was | 363 // Writes the given buffer into the file, overwriting any data that was |
| 364 // previously there. Returns the number of bytes written, or -1 on error. | 364 // previously there. Returns the number of bytes written, or -1 on error. |
| 365 BASE_API int WriteFile(const FilePath& filename, const char* data, int size); | 365 BASE_API int WriteFile(const FilePath& filename, const char* data, int size); |
| 366 #if defined(OS_POSIX) | 366 #if defined(OS_POSIX) |
| 367 // Append the data to |fd|. Does not close |fd| when done. | 367 // Append the data to |fd|. Does not close |fd| when done. |
| 368 BASE_API int WriteFileDescriptor(const int fd, const char* data, int size); | 368 int WriteFileDescriptor(const int fd, const char* data, int size); |
| 369 #endif | 369 #endif |
| 370 | 370 |
| 371 // Gets the current working directory for the process. | 371 // Gets the current working directory for the process. |
| 372 BASE_API bool GetCurrentDirectory(FilePath* path); | 372 BASE_API bool GetCurrentDirectory(FilePath* path); |
| 373 | 373 |
| 374 // Sets the current working directory for the process. | 374 // Sets the current working directory for the process. |
| 375 BASE_API bool SetCurrentDirectory(const FilePath& path); | 375 BASE_API bool SetCurrentDirectory(const FilePath& path); |
| 376 | 376 |
| 377 // A class to handle auto-closing of FILE*'s. | 377 // A class to handle auto-closing of FILE*'s. |
| 378 class ScopedFILEClose { | 378 class ScopedFILEClose { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 FILE_SYSTEM_SMB, | 641 FILE_SYSTEM_SMB, |
| 642 FILE_SYSTEM_CODA, | 642 FILE_SYSTEM_CODA, |
| 643 FILE_SYSTEM_MEMORY, // in-memory file system | 643 FILE_SYSTEM_MEMORY, // in-memory file system |
| 644 FILE_SYSTEM_CGROUP, // cgroup control. | 644 FILE_SYSTEM_CGROUP, // cgroup control. |
| 645 FILE_SYSTEM_OTHER, // any other value. | 645 FILE_SYSTEM_OTHER, // any other value. |
| 646 FILE_SYSTEM_TYPE_COUNT | 646 FILE_SYSTEM_TYPE_COUNT |
| 647 }; | 647 }; |
| 648 | 648 |
| 649 // Attempts determine the FileSystemType for |path|. | 649 // Attempts determine the FileSystemType for |path|. |
| 650 // Returns false if |path| doesn't exist. | 650 // Returns false if |path| doesn't exist. |
| 651 BASE_API bool GetFileSystemType(const FilePath& path, FileSystemType* type); | 651 bool GetFileSystemType(const FilePath& path, FileSystemType* type); |
| 652 #endif | 652 #endif |
| 653 | 653 |
| 654 } // namespace file_util | 654 } // namespace file_util |
| 655 | 655 |
| 656 // Deprecated functions have been moved to this separate header file, | 656 // Deprecated functions have been moved to this separate header file, |
| 657 // which must be included last after all the above definitions. | 657 // which must be included last after all the above definitions. |
| 658 #include "base/file_util_deprecated.h" | 658 #include "base/file_util_deprecated.h" |
| 659 | 659 |
| 660 #endif // BASE_FILE_UTIL_H_ | 660 #endif // BASE_FILE_UTIL_H_ |
| OLD | NEW |