LLVM 22.0.0git
Errno.h
Go to the documentation of this file.
1//===- llvm/Support/Errno.h - Portable+convenient errno handling -*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares some portable and convenient functions to deal with errno.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_ERRNO_H
14#define LLVM_SUPPORT_ERRNO_H
15
17#include <cerrno>
18#include <string>
19
20namespace llvm {
21namespace sys {
22
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.
27LLVM_ABI std::string StrError();
28
29/// Like the no-argument version above, but uses \p errnum instead of errno.
30LLVM_ABI std::string StrError(int errnum);
31
32template <typename FailT, typename Fun, typename... Args>
33inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F,
34 const Args &... As) {
35 decltype(F(As...)) Res;
36 do {
37 errno = 0;
38 Res = F(As...);
39 } while (Res == Fail && errno == EINTR);
40 return Res;
41}
42
43} // namespace sys
44} // namespace llvm
45
46#endif // LLVM_SUPPORT_ERRNO_H
#define Fail
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:55
Function * Fun
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F, const Args &... As)
Definition Errno.h:33
LLVM_ABI std::string StrError()
Returns a string representation of the errno value, using whatever thread-safe variant of strerror() ...
Definition Errno.cpp:26
This is an optimization pass for GlobalISel generic memory operations.