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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // Writes the given buffer into the file, overwriting any data that was | 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. | 332 // previously there. Returns the number of bytes written, or -1 on error. |
333 BASE_EXPORT int WriteFile(const FilePath& filename, const char* data, | 333 BASE_EXPORT int WriteFile(const FilePath& filename, const char* data, |
334 int size); | 334 int size); |
335 | 335 |
336 #if defined(OS_POSIX) | 336 #if defined(OS_POSIX) |
337 // Append the data to |fd|. Does not close |fd| when done. | 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); | 338 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); |
339 #endif | 339 #endif |
340 | 340 |
| 341 // Append the given buffer into the file. Returns the number of bytes written, |
| 342 // or -1 on error. |
| 343 BASE_EXPORT int AppendToFile(const FilePath& filename, |
| 344 const char* data, int size); |
| 345 |
| 346 // Gets the current working directory for the process. |
| 347 BASE_EXPORT bool GetCurrentDirectory(FilePath* path); |
| 348 |
| 349 // Sets the current working directory for the process. |
| 350 BASE_EXPORT bool SetCurrentDirectory(const FilePath& path); |
| 351 |
341 } // namespace base | 352 } // namespace base |
342 | 353 |
343 // ----------------------------------------------------------------------------- | 354 // ----------------------------------------------------------------------------- |
344 | 355 |
345 namespace file_util { | 356 namespace file_util { |
346 | 357 |
347 // Append the given buffer into the file. Returns the number of bytes written, | |
348 // or -1 on error. | |
349 BASE_EXPORT int AppendToFile(const base::FilePath& filename, | |
350 const char* data, int size); | |
351 | |
352 // Gets the current working directory for the process. | |
353 BASE_EXPORT bool GetCurrentDirectory(base::FilePath* path); | |
354 | |
355 // Sets the current working directory for the process. | |
356 BASE_EXPORT bool SetCurrentDirectory(const base::FilePath& path); | |
357 | |
358 // Attempts to find a number that can be appended to the |path| to make it | 358 // Attempts to find a number that can be appended to the |path| to make it |
359 // unique. If |path| does not exist, 0 is returned. If it fails to find such | 359 // unique. If |path| does not exist, 0 is returned. If it fails to find such |
360 // a number, -1 is returned. If |suffix| is not empty, also checks the | 360 // a number, -1 is returned. If |suffix| is not empty, also checks the |
361 // existence of it with the given suffix. | 361 // existence of it with the given suffix. |
362 BASE_EXPORT int GetUniquePathNumber(const base::FilePath& path, | 362 BASE_EXPORT int GetUniquePathNumber(const base::FilePath& path, |
363 const base::FilePath::StringType& suffix); | 363 const base::FilePath::StringType& suffix); |
364 | 364 |
365 #if defined(OS_POSIX) | 365 #if defined(OS_POSIX) |
366 // Creates a directory with a guaranteed unique name based on |path|, returning | 366 // Creates a directory with a guaranteed unique name based on |path|, returning |
367 // the pathname if successful, or an empty path if there was an error creating | 367 // the pathname if successful, or an empty path if there was an error creating |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // This function simulates Move(), but unlike Move() it works across volumes. | 483 // This function simulates Move(), but unlike Move() it works across volumes. |
484 // This function is not transactional. | 484 // This function is not transactional. |
485 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 485 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
486 const FilePath& to_path); | 486 const FilePath& to_path); |
487 #endif // defined(OS_WIN) | 487 #endif // defined(OS_WIN) |
488 | 488 |
489 } // namespace internal | 489 } // namespace internal |
490 } // namespace base | 490 } // namespace base |
491 | 491 |
492 #endif // BASE_FILE_UTIL_H_ | 492 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |