OpenVPN 3 Core Library
Loading...
Searching...
No Matches
strerror.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_COMMON_STRERROR_H
13#define OPENVPN_COMMON_STRERROR_H
14
15#include <string.h>
16#include <string>
17
18#include <errno.h>
19
20namespace openvpn {
21inline std::string strerror_str(const int errnum)
22{
23 static const char unknown_err[] = "UNKNOWN_SYSTEM_ERROR";
24 char buf[128];
25
26#if defined(__GLIBC__) && (!defined(__USE_XOPEN2K) || defined(__USE_GNU))
27 // GNU
28 const char *errstr = ::strerror_r(errnum, buf, sizeof(buf));
29 if (errstr)
30 return std::string(errstr);
31#else
32 // POSIX
33 if (::strerror_r(errnum, buf, sizeof(buf)) == 0)
34 return std::string(buf);
35#endif
36 return std::string(unknown_err);
37}
38} // namespace openvpn
39
40#endif
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
std::string strerror_str(const int errnum)
Definition strerror.hpp:21