fclose_deleter.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright Andrey Semashev 2022.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file fclose_deleter.hpp
  9. * \author Andrey Semashev
  10. * \date 21.09.2022
  11. *
  12. * This header contains an \c fclose_deleter implementation. This is a deleter
  13. * function object that invokes <tt>std::fclose</tt> on the passed pointer to
  14. * a <tt>std::FILE</tt> structure.
  15. */
  16. #ifndef BHO_CORE_FCLOSE_DELETER_HPP
  17. #define BHO_CORE_FCLOSE_DELETER_HPP
  18. #include <cstdio>
  19. #include <asio2/bho/config.hpp>
  20. #ifdef BHO_HAS_PRAGMA_ONCE
  21. #pragma once
  22. #endif
  23. namespace bho {
  24. //! A function object that closes a file
  25. struct fclose_deleter
  26. {
  27. //! Function object result type
  28. typedef void result_type;
  29. /*!
  30. * Closes the file handle
  31. */
  32. void operator() (std::FILE* p) const BHO_NOEXCEPT
  33. {
  34. if (BHO_LIKELY(!!p))
  35. std::fclose(p);
  36. }
  37. };
  38. } // namespace bho
  39. #endif // BHO_CORE_FCLOSE_DELETER_HPP