Errno.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. namespace llvm {
  22. namespace sys {
  23. /// Returns a string representation of the errno value, using whatever
  24. /// thread-safe variant of strerror() is available. Be sure to call this
  25. /// immediately after the function that set errno, or errno may have been
  26. /// overwritten by an intervening call.
  27. std::string StrError();
  28. /// Like the no-argument version above, but uses \p errnum instead of errno.
  29. std::string StrError(int errnum);
  30. template <typename FailT, typename Fun, typename... Args>
  31. inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F,
  32. const Args &... As) {
  33. decltype(F(As...)) Res;
  34. do {
  35. errno = 0;
  36. Res = F(As...);
  37. } while (Res == Fail && errno == EINTR);
  38. return Res;
  39. }
  40. } // namespace sys
  41. } // namespace llvm
  42. #endif // LLVM_SUPPORT_ERRNO_H
  43. #ifdef __GNUC__
  44. #pragma GCC diagnostic pop
  45. #endif