1 //===- llvm/Support/Errno.h - Portable+convenient errno handling -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares some portable and convenient functions to deal with errno.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_ERRNO_H
15 #define LLVM_SUPPORT_ERRNO_H
19 #include <type_traits>
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();
30 /// Like the no-argument version above, but uses \p errnum instead of errno.
31 std::string StrError(int errnum);
33 template <typename Fun, typename... Args,
34 typename ResultT = std::result_of<Fun const &(const Args &...)>>
35 inline typename ResultT::type RetryAfterSignal(typename ResultT::type Fail,
38 typename ResultT::type Res;
41 while (Res == Fail && errno == EINTR);
48 #endif // LLVM_SYSTEM_ERRNO_H