1 //===- llvm/Support/Errno.h - Portable+convenient errno handling -*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares some portable and convenient functions to deal with errno.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_SUPPORT_ERRNO_H
14 #define LLVM_SUPPORT_ERRNO_H
18 #include <type_traits>
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();
29 /// Like the no-argument version above, but uses \p errnum instead of errno.
30 std::string
StrError(int errnum
);
32 template <typename FailT
, typename Fun
, typename
... Args
>
33 inline auto RetryAfterSignal(const FailT
&Fail
, const Fun
&F
,
34 const Args
&... As
) -> decltype(F(As
...)) {
35 decltype(F(As
...)) Res
;
39 } while (Res
== Fail
&& errno
== EINTR
);
46 #endif // LLVM_SYSTEM_ERRNO_H