1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/check_op.h"
13 #include "base/logging.h"
17 char* CheckOpValueStr(int v) {
19 snprintf(buf, sizeof(buf), "%d", v);
23 char* CheckOpValueStr(unsigned v) {
25 snprintf(buf, sizeof(buf), "%u", v);
29 char* CheckOpValueStr(long v) {
31 snprintf(buf, sizeof(buf), "%ld", v);
35 char* CheckOpValueStr(unsigned long v) {
37 snprintf(buf, sizeof(buf), "%lu", v);
41 char* CheckOpValueStr(long long v) {
43 snprintf(buf, sizeof(buf), "%lld", v);
47 char* CheckOpValueStr(unsigned long long v) {
49 snprintf(buf, sizeof(buf), "%llu", v);
53 char* CheckOpValueStr(const void* v) {
55 snprintf(buf, sizeof(buf), "%p", v);
59 char* CheckOpValueStr(std::nullptr_t v) {
60 return strdup("nullptr");
63 char* CheckOpValueStr(const std::string& v) {
64 return strdup(v.c_str());
67 char* CheckOpValueStr(std::string_view v) {
68 // Ideally this would be `strndup`, but `strndup` is not portable.
69 char* ret = static_cast<char*>(malloc(v.size() + 1));
71 std::copy(v.begin(), v.end(), ret);
77 char* CheckOpValueStr(double v) {
79 snprintf(buf, sizeof(buf), "%.6lf", v);
83 char* StreamValToStr(const void* v,
84 void (*stream_func)(std::ostream&, const void*)) {
87 return strdup(ss.str().c_str());
90 char* CreateCheckOpLogMessageString(const char* expr_str,
94 ss << "Check failed: " << expr_str << " (" << v1_str << " vs. " << v2_str
98 return strdup(ss.str().c_str());
101 } // namespace logging