Style/readability clean-up for certificate reporting code
[chromium-blink-merge.git] / base / files / scoped_file.h
blob106f6ad94bf7f3b0e01799a61cb8dfcab914dd95
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_FILES_SCOPED_FILE_H_
6 #define BASE_FILES_SCOPED_FILE_H_
8 #include <stdio.h>
10 #include "base/base_export.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/scoped_generic.h"
14 #include "build/build_config.h"
16 namespace base {
18 namespace internal {
20 #if defined(OS_POSIX)
21 struct BASE_EXPORT ScopedFDCloseTraits {
22 static int InvalidValue() {
23 return -1;
25 static void Free(int fd);
27 #endif
29 // Functor for |ScopedFILE| (below).
30 struct ScopedFILECloser {
31 inline void operator()(FILE* x) const {
32 if (x)
33 fclose(x);
37 } // namespace internal
39 // -----------------------------------------------------------------------------
41 #if defined(OS_POSIX)
42 // A low-level Posix file descriptor closer class. Use this when writing
43 // platform-specific code, especially that does non-file-like things with the
44 // FD (like sockets).
46 // If you're writing low-level Windows code, see base/win/scoped_handle.h
47 // which provides some additional functionality.
49 // If you're writing cross-platform code that deals with actual files, you
50 // should generally use base::File instead which can be constructed with a
51 // handle, and in addition to handling ownership, has convenient cross-platform
52 // file manipulation functions on it.
53 typedef ScopedGeneric<int, internal::ScopedFDCloseTraits> ScopedFD;
54 #endif
56 // Automatically closes |FILE*|s.
57 typedef scoped_ptr<FILE, internal::ScopedFILECloser> ScopedFILE;
59 } // namespace base
61 #endif // BASE_FILES_SCOPED_FILE_H_