#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "absl/strings/string_view.h"
#if defined(WEBRTC_ANDROID)
#define RTC_LOG_TAG_ANDROID …
#include <android/log.h>
#endif
#if defined(WEBRTC_WIN)
#include <windows.h>
#endif
#if defined(WEBRTC_WIN)
#define LAST_SYSTEM_ERROR …
#elif defined(__native_client__) && __native_client__
#define LAST_SYSTEM_ERROR …
#elif defined(WEBRTC_POSIX)
#include <errno.h>
#define LAST_SYSTEM_ERROR …
#endif
#include "rtc_base/checks.h"
namespace {
#if defined(__GNUC__)
__attribute__((__format__(__printf__, 2, 3)))
#endif
void AppendFormat(std::string* s, const char* fmt, ...) { … }
}
namespace rtc {
namespace webrtc_checks_impl {
#if !defined(WEBRTC_CHROMIUM_BUILD)
RTC_NORETURN void WriteFatalLog(absl::string_view output) {
#if defined(WEBRTC_ANDROID)
std::string output_str(output);
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n",
output_str.c_str());
#endif
fflush(stdout);
fwrite(output.data(), output.size(), 1, stderr);
fflush(stderr);
#if defined(WEBRTC_WIN)
DebugBreak();
#endif
abort();
}
RTC_NORETURN void WriteFatalLog(const char* file,
int line,
absl::string_view output) {
WriteFatalLog(output);
}
#endif
#if RTC_CHECK_MSG_ENABLED
bool ParseArg(va_list* args, const CheckArgType** fmt, std::string* s) { … }
RTC_NORETURN void FatalLog(const char* file,
int line,
const char* message,
const CheckArgType* fmt,
...) { … }
#else
RTC_NORETURN void FatalLog(const char* file, int line) {
std::string s;
AppendFormat(&s,
"\n\n"
"#\n"
"# Fatal error in: %s, line %d\n"
"# last system error: %u\n"
"# Check failed.\n"
"# ",
file, line, LAST_SYSTEM_ERROR);
WriteFatalLog(file, line, s);
}
#endif
#if RTC_DCHECK_IS_ON
RTC_NORETURN void UnreachableCodeReached(const char* file, int line) { … }
#else
RTC_NORETURN void UnreachableCodeReached() {
std::string s;
AppendFormat(&s,
"\n\n"
"#\n"
"# Unreachable code reached (file and line unknown)\n"
"# last system error: %u\n"
"# ",
LAST_SYSTEM_ERROR);
WriteFatalLog(s);
}
#endif
}
}
RTC_NORETURN void rtc_FatalMessage(const char* file,
int line,
const char* msg) { … }