Chromium Code Reviews| Index: base/files/scoped_file.h |
| diff --git a/base/files/scoped_file.h b/base/files/scoped_file.h |
| index f5d7ecde7bf7b3cf18c927e301643351770fa12b..a8a80f1d687844535562f24e3b8dc51532bb5a62 100644 |
| --- a/base/files/scoped_file.h |
| +++ b/base/files/scoped_file.h |
| @@ -9,6 +9,7 @@ |
| #include "base/base_export.h" |
| #include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/scoped_generic.h" |
| #include "build/build_config.h" |
| @@ -25,8 +26,18 @@ struct BASE_EXPORT ScopedFDCloseTraits { |
| }; |
| #endif |
| +// Functor for |ScopedFILE| (below). |
| +struct ScopedFILEClose { |
|
viettrungluu
2014/03/14 21:41:56
Since scoped_ptr.h refers to its functor as a "del
|
| + inline void operator()(FILE* x) const { |
| + if (x) |
| + fclose(x); |
| + } |
| +}; |
| + |
| } // namespace internal |
| +// ----------------------------------------------------------------------------- |
| + |
| #if defined(OS_POSIX) |
| // A low-level Posix file descriptor closer class. Use this when writing |
| // platform-specific code, especially that does non-file-like things with the |
| @@ -42,6 +53,9 @@ struct BASE_EXPORT ScopedFDCloseTraits { |
| typedef ScopedGeneric<int, internal::ScopedFDCloseTraits> ScopedFD; |
| #endif |
| +// Automatically closes |FILE*|s. |
| +typedef scoped_ptr<FILE, internal::ScopedFILEClose> ScopedFILE; |
| + |
| } // namespace base |
| #endif // BASE_FILES_SCOPED_FILE_H_ |