1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_glue_Debug_h
8 #define mozilla_glue_Debug_h
10 /* This header file intends to supply debugging utilities for use in code
11 * that cannot use XPCOM debugging facilities like nsDebug.h.
12 * e.g. mozglue, browser/app
14 * NB: printf_stderr() is in the global namespace, so include this file with
15 * care; avoid including from header files.
21 #endif // defined(XP_WIN)
22 #include "mozilla/Attributes.h"
23 #include "mozilla/Sprintf.h"
25 #if defined(MOZILLA_INTERNAL_API)
26 # error Do not include this file from XUL sources.
29 // Though this is a separate implementation than nsDebug's, we want to make the
30 // declarations compatible to avoid confusing the linker if both headers are
36 void printf_stderr(const char* fmt
, ...) MOZ_FORMAT_PRINTF(1, 2);
37 inline void printf_stderr(const char* fmt
, ...) {
39 if (IsDebuggerPresent()) {
43 VsprintfLiteral(buf
, fmt
, args
);
45 OutputDebugStringA(buf
);
47 #endif // defined(XP_WIN)
49 // stderr is unbuffered by default so we open a new FILE (which is buffered)
50 // so that calls to printf_stderr are not as likely to get mixed together.
51 int fd
= _fileno(stderr
);
54 FILE* fp
= _fdopen(_dup(fd
), "a");
59 vfprintf(fp
, fmt
, args
);
69 #endif // mozilla_glue_Debug_h