Home | History | Annotate | Download | only in mac
      1 // Copyright 2012 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.
      4 
      5 #ifndef BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_
      6 #define BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_
      7 
      8 #include <CoreFoundation/CoreFoundation.h>
      9 
     10 #include "base/scoped_generic.h"
     11 
     12 namespace base {
     13 namespace mac {
     14 
     15 namespace internal {
     16 
     17 struct ScopedCFFileDescriptorRefTraits {
     18   static CFFileDescriptorRef InvalidValue() { return nullptr; }
     19   static void Free(CFFileDescriptorRef ref) {
     20     CFFileDescriptorInvalidate(ref);
     21     CFRelease(ref);
     22   }
     23 };
     24 
     25 }  // namespace internal
     26 
     27 // ScopedCFFileDescriptorRef is designed after ScopedCFTypeRef<>. On
     28 // destruction, it will invalidate the file descriptor.
     29 // ScopedCFFileDescriptorRef (unlike ScopedCFTypeRef<>) does not support RETAIN
     30 // semantics, copying, or assignment, as doing so would increase the chances
     31 // that a file descriptor is invalidated while still in use.
     32 using ScopedCFFileDescriptorRef =
     33     ScopedGeneric<CFFileDescriptorRef,
     34                   internal::ScopedCFFileDescriptorRefTraits>;
     35 
     36 }  // namespace mac
     37 }  // namespace base
     38 
     39 #endif  // BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_
     40