Leaked source code of windows server 2003
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.

76 lines
1.5 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. ach[ARRAYSIZE(ach)-1] = L'\0';
  43. va_end(arglist);
  44. if (0 > cch)
  45. {
  46. strcpy(&ach[sizeof(ach) - 5], "...\n");
  47. }
  48. if (!IsDebuggerPresent())
  49. {
  50. hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  51. if (hStdOut != INVALID_HANDLE_VALUE)
  52. {
  53. fputs(ach, stdout);
  54. fflush(stdout);
  55. }
  56. }
  57. OutputDebugStringA(ach);
  58. }
  59. __except(EXCEPTION_EXECUTE_HANDLER)
  60. {
  61. // return failure
  62. cch = 0;
  63. }
  64. }
  65. SetLastError(dwErr);
  66. return(cch);
  67. }