mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
1a0b5f33b3
cmake/target.cmake defines macros for the supported platforms, this commit changes predefined system macros to our own macros. __linux__ --> OS_LINUX __APPLE__ --> OS_DARWIN __FreeBSD__ --> OS_FREEBSD
30 lines
773 B
C++
30 lines
773 B
C++
#include "errnoToString.h"
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
std::string errnoToString(int code, int the_errno)
|
|
{
|
|
const size_t buf_size = 128;
|
|
char buf[buf_size];
|
|
#ifndef _GNU_SOURCE
|
|
int rc = strerror_r(the_errno, buf, buf_size);
|
|
#ifdef OS_DARWIN
|
|
if (rc != 0 && rc != EINVAL)
|
|
#else
|
|
if (rc != 0)
|
|
#endif
|
|
{
|
|
std::string tmp = std::to_string(code);
|
|
const char * code_str = tmp.c_str();
|
|
const char * unknown_message = "Unknown error ";
|
|
strcpy(buf, unknown_message);
|
|
strcpy(buf + strlen(unknown_message), code_str);
|
|
}
|
|
return fmt::format("errno: {}, strerror: {}", the_errno, buf);
|
|
#else
|
|
(void)code;
|
|
return fmt::format("errno: {}, strerror: {}", the_errno, strerror_r(the_errno, buf, sizeof(buf)));
|
|
#endif
|
|
}
|