scoped_cffiledescriptorref.h 1.2 KB

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