/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef XP_WIN # include <io.h> # include <windows.h> #endif
#ifdef ANDROID # include <android/log.h> #endif
#ifndef ANDROID staticvoid vprintf_stderr_buffered(constchar* aFmt, va_list aArgs) { // Avoid interleaving by writing to an on-stack buffer and then writing in one // go with fputs, as long as the output fits into the buffer. char buffer[1024];
va_list argsCpy;
va_copy(argsCpy, aArgs); int n = VsprintfLiteral(buffer, aFmt, aArgs); if (n < int(sizeof(buffer))) {
fputs(buffer, stderr);
} else { // Message too long for buffer. Just print it, not worrying about // interleaving. (We could malloc, but the underlying write() syscall could // get interleaved if the output is too big anyway.)
vfprintf(stderr, aFmt, argsCpy);
}
va_end(argsCpy);
fflush(stderr);
} #endif
#ifdefined(XP_WIN)
MFBT_API void vprintf_stderr(constchar* aFmt, va_list aArgs) { if (IsDebuggerPresent()) { int lengthNeeded = _vscprintf(aFmt, aArgs); if (lengthNeeded) {
lengthNeeded++; auto buf = mozilla::MakeUnique<char[]>(lengthNeeded); if (buf) {
va_list argsCpy;
va_copy(argsCpy, aArgs);
vsnprintf(buf.get(), lengthNeeded, aFmt, argsCpy);
buf[lengthNeeded - 1] = '\0';
va_end(argsCpy);
OutputDebugStringA(buf.get());
}
}
}
MFBT_API void print_stderr(std::stringstream& aStr) { #ifdefined(ANDROID) // On Android logcat output is truncated to 1024 chars per line, and // we usually use std::stringstream to build up giant multi-line gobs // of output. So to avoid the truncation we find the newlines and // print the lines individually.
std::string line; while (std::getline(aStr, line)) {
printf_stderr("%s\n", line.c_str());
} #else
printf_stderr("%s", aStr.str().c_str()); #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.