OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 // Append the data to |fd|. Does not close |fd| when done. | 358 // Append the data to |fd|. Does not close |fd| when done. |
359 int WriteFileDescriptor(const int fd, const char* data, int size); | 359 int WriteFileDescriptor(const int fd, const char* data, int size); |
360 #endif | 360 #endif |
361 | 361 |
362 // Gets the current working directory for the process. | 362 // Gets the current working directory for the process. |
363 bool GetCurrentDirectory(FilePath* path); | 363 bool GetCurrentDirectory(FilePath* path); |
364 | 364 |
365 // Sets the current working directory for the process. | 365 // Sets the current working directory for the process. |
366 bool SetCurrentDirectory(const FilePath& path); | 366 bool SetCurrentDirectory(const FilePath& path); |
367 | 367 |
368 // A class to handle auto-closing of FILE*'s. | 368 inline void ScopedFILEClose(FILE* f) { |
369 class ScopedFILEClose { | 369 fclose(f); |
370 public: | 370 } |
371 inline void operator()(FILE* x) const { | |
372 if (x) { | |
373 fclose(x); | |
374 } | |
375 } | |
376 }; | |
377 | 371 |
378 typedef scoped_ptr_malloc<FILE, ScopedFILEClose> ScopedFILE; | 372 typedef scoped_ptr_malloc<FILE, ScopedFILEClose> ScopedFILE; |
379 | 373 |
380 #if defined(OS_POSIX) | 374 #if defined(OS_POSIX) |
381 // A class to handle auto-closing of FDs. | 375 // A class to handle auto-closing of FDs. |
382 class ScopedFDClose { | 376 inline void ScopedFDClose(int* x) { |
383 public: | 377 if (x && *x >= 0) { |
384 inline void operator()(int* x) const { | 378 if (HANDLE_EINTR(close(*x)) < 0) |
385 if (x && *x >= 0) { | 379 PLOG(ERROR) << "close"; |
386 if (HANDLE_EINTR(close(*x)) < 0) | |
387 PLOG(ERROR) << "close"; | |
388 } | |
389 } | 380 } |
390 }; | 381 } |
391 | 382 |
392 typedef scoped_ptr_malloc<int, ScopedFDClose> ScopedFD; | 383 typedef scoped_ptr_malloc<int, ScopedFDClose> ScopedFD; |
393 #endif // OS_POSIX | 384 #endif // OS_POSIX |
394 | 385 |
395 // A class for enumerating the files in a provided path. The order of the | 386 // A class for enumerating the files in a provided path. The order of the |
396 // results is not guaranteed. | 387 // results is not guaranteed. |
397 // | 388 // |
398 // DO NOT USE FROM THE MAIN THREAD of your application unless it is a test | 389 // DO NOT USE FROM THE MAIN THREAD of your application unless it is a test |
399 // program where latency does not matter. This class is blocking. | 390 // program where latency does not matter. This class is blocking. |
400 class FileEnumerator { | 391 class FileEnumerator { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 bool PreReadImage(const wchar_t* file_path, size_t size_to_read, | 603 bool PreReadImage(const wchar_t* file_path, size_t size_to_read, |
613 size_t step_size); | 604 size_t step_size); |
614 #endif // OS_WIN | 605 #endif // OS_WIN |
615 } // namespace file_util | 606 } // namespace file_util |
616 | 607 |
617 // Deprecated functions have been moved to this separate header file, | 608 // Deprecated functions have been moved to this separate header file, |
618 // which must be included last after all the above definitions. | 609 // which must be included last after all the above definitions. |
619 #include "base/file_util_deprecated.h" | 610 #include "base/file_util_deprecated.h" |
620 | 611 |
621 #endif // BASE_FILE_UTIL_H_ | 612 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |