Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: cedebug.cpp
  7. //
  8. // Contents: Debug support
  9. //
  10. //----------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #include "celib.h"
  14. #include <stdarg.h>
  15. //+-------------------------------------------------------------------------
  16. //
  17. // Function: ceDbgPrintf
  18. //
  19. // Synopsis: outputs debug info to stdout and debugger
  20. //
  21. // Returns: number of chars output
  22. //
  23. //--------------------------------------------------------------------------
  24. int WINAPIV
  25. ceDbgPrintf(
  26. IN BOOL fDebug,
  27. IN LPCSTR lpFmt,
  28. ...)
  29. {
  30. va_list arglist;
  31. CHAR ach[4096];
  32. int cch = 0;
  33. HANDLE hStdOut;
  34. DWORD dwErr;
  35. dwErr = GetLastError();
  36. if (fDebug)
  37. {
  38. __try
  39. {
  40. va_start(arglist, lpFmt);
  41. cch = _vsnprintf(ach, sizeof(ach), lpFmt, arglist);
  42. va_end(arglist);
  43. if (0 > cch)
  44. {
  45. strcpy(&ach[sizeof(ach) - 5], "...\n");
  46. }
  47. if (!IsDebuggerPresent())
  48. {
  49. hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  50. if (hStdOut != INVALID_HANDLE_VALUE)
  51. {
  52. fputs(ach, stdout);
  53. fflush(stdout);
  54. }
  55. }
  56. OutputDebugStringA(ach);
  57. }
  58. __except(EXCEPTION_EXECUTE_HANDLER)
  59. {
  60. // return failure
  61. cch = 0;
  62. }
  63. }
  64. SetLastError(dwErr);
  65. return(cch);
  66. }