Errno.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Support/Errno.h - Portable+convenient errno handling -*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares some portable and convenient functions to deal with errno.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_SUPPORT_ERRNO_H
  18. #define LLVM_SUPPORT_ERRNO_H
  19. #include <cerrno>
  20. #include <string>
  21. #include <type_traits>
  22. namespace llvm {
  23. namespace sys {
  24. /// Returns a string representation of the errno value, using whatever
  25. /// thread-safe variant of strerror() is available. Be sure to call this
  26. /// immediately after the function that set errno, or errno may have been
  27. /// overwritten by an intervening call.
  28. std::string StrError();
  29. /// Like the no-argument version above, but uses \p errnum instead of errno.
  30. std::string StrError(int errnum);
  31. template <typename FailT, typename Fun, typename... Args>
  32. inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F,
  33. const Args &... As) {
  34. decltype(F(As...)) Res;
  35. do {
  36. errno = 0;
  37. Res = F(As...);
  38. } while (Res == Fail && errno == EINTR);
  39. return Res;
  40. }
  41. } // namespace sys
  42. } // namespace llvm
  43. #endif // LLVM_SUPPORT_ERRNO_H
  44. #ifdef __GNUC__
  45. #pragma GCC diagnostic pop
  46. #endif