Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3164)

Unified Diff: base/files/scoped_file.h

Issue 196073002: Move ScopedFILE to base namespace and scoped_file.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/memory/shared_memory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/scoped_file.h
diff --git a/base/files/scoped_file.h b/base/files/scoped_file.h
index f5d7ecde7bf7b3cf18c927e301643351770fa12b..106f6ad94bf7f3b0e01799a61cb8dfcab914dd95 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 ScopedFILECloser {
+ 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::ScopedFILECloser> ScopedFILE;
+
} // namespace base
#endif // BASE_FILES_SCOPED_FILE_H_
« no previous file with comments | « no previous file | base/memory/shared_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698