Index: mojo/edk/util/scoped_file.h |
diff --git a/mojo/edk/util/scoped_file.h b/mojo/edk/util/scoped_file.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7aeb868f975a8caea536f028d16dc5d5bb95e0b6 |
--- /dev/null |
+++ b/mojo/edk/util/scoped_file.h |
@@ -0,0 +1,32 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MOJO_EDK_UTIL_SCOPED_FILE_H_ |
+#define MOJO_EDK_UTIL_SCOPED_FILE_H_ |
+ |
+#include <stdio.h> |
+ |
+#include "base/memory/scoped_ptr.h" |
+ |
+namespace mojo { |
+namespace util { |
+namespace internal { |
+ |
+// Functor for |ScopedFILE| (below). |
+struct ScopedFILECloser { |
+ inline void operator()(FILE* x) const { |
+ if (x) |
+ fclose(x); |
+ } |
+}; |
+ |
+} // namespace internal |
+ |
+// Automatically closes |FILE*|s. |
+using ScopedFILE = scoped_ptr<FILE, internal::ScopedFILECloser>; |
+ |
+} // namespace util |
+} // namespace mojo |
+ |
+#endif // MOJO_EDK_UTIL_SCOPED_FILE_H_ |