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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 BASE_EXPORT bool CloseFile(FILE* file); | 321 BASE_EXPORT bool CloseFile(FILE* file); |
322 | 322 |
323 // Truncates an open file to end at the location of the current file pointer. | 323 // Truncates an open file to end at the location of the current file pointer. |
324 // This is a cross-platform analog to Windows' SetEndOfFile() function. | 324 // This is a cross-platform analog to Windows' SetEndOfFile() function. |
325 BASE_EXPORT bool TruncateFile(FILE* file); | 325 BASE_EXPORT bool TruncateFile(FILE* file); |
326 | 326 |
327 // Reads the given number of bytes from the file into the buffer. Returns | 327 // Reads the given number of bytes from the file into the buffer. Returns |
328 // the number of read bytes, or -1 on error. | 328 // the number of read bytes, or -1 on error. |
329 BASE_EXPORT int ReadFile(const FilePath& filename, char* data, int size); | 329 BASE_EXPORT int ReadFile(const FilePath& filename, char* data, int size); |
330 | 330 |
| 331 // Writes the given buffer into the file, overwriting any data that was |
| 332 // previously there. Returns the number of bytes written, or -1 on error. |
| 333 BASE_EXPORT int WriteFile(const FilePath& filename, const char* data, |
| 334 int size); |
| 335 |
| 336 #if defined(OS_POSIX) |
| 337 // Append the data to |fd|. Does not close |fd| when done. |
| 338 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); |
| 339 #endif |
| 340 |
331 } // namespace base | 341 } // namespace base |
332 | 342 |
333 // ----------------------------------------------------------------------------- | 343 // ----------------------------------------------------------------------------- |
334 | 344 |
335 namespace file_util { | 345 namespace file_util { |
336 | 346 |
337 // Writes the given buffer into the file, overwriting any data that was | |
338 // previously there. Returns the number of bytes written, or -1 on error. | |
339 BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data, | |
340 int size); | |
341 #if defined(OS_POSIX) | |
342 // Append the data to |fd|. Does not close |fd| when done. | |
343 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); | |
344 #endif | |
345 // Append the given buffer into the file. Returns the number of bytes written, | 347 // Append the given buffer into the file. Returns the number of bytes written, |
346 // or -1 on error. | 348 // or -1 on error. |
347 BASE_EXPORT int AppendToFile(const base::FilePath& filename, | 349 BASE_EXPORT int AppendToFile(const base::FilePath& filename, |
348 const char* data, int size); | 350 const char* data, int size); |
349 | 351 |
350 // Gets the current working directory for the process. | 352 // Gets the current working directory for the process. |
351 BASE_EXPORT bool GetCurrentDirectory(base::FilePath* path); | 353 BASE_EXPORT bool GetCurrentDirectory(base::FilePath* path); |
352 | 354 |
353 // Sets the current working directory for the process. | 355 // Sets the current working directory for the process. |
354 BASE_EXPORT bool SetCurrentDirectory(const base::FilePath& path); | 356 BASE_EXPORT bool SetCurrentDirectory(const base::FilePath& path); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 // This function simulates Move(), but unlike Move() it works across volumes. | 483 // This function simulates Move(), but unlike Move() it works across volumes. |
482 // This function is not transactional. | 484 // This function is not transactional. |
483 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 485 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
484 const FilePath& to_path); | 486 const FilePath& to_path); |
485 #endif // defined(OS_WIN) | 487 #endif // defined(OS_WIN) |
486 | 488 |
487 } // namespace internal | 489 } // namespace internal |
488 } // namespace base | 490 } // namespace base |
489 | 491 |
490 #endif // BASE_FILE_UTIL_H_ | 492 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |