scoped_cffiledescriptorref.h 1.2 KB

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