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