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.

103 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. Author:
  7. Environment:
  8. Notes:
  9. Revision History:
  10. --*/
  11. #include <stdio.h> // vsprintf()
  12. #include <stdlib.h>
  13. #include <stdarg.h>
  14. #include <windows.h>
  15. #include <strsafe.h>
  16. #define DBGHDR "[cddump] "
  17. #define DBGHDRLEN (strlen( DBGHDR ))
  18. #if DBG
  19. //
  20. // Debug level global variable
  21. //
  22. // 0 = Extreme errors only
  23. // 1 = errors, major events
  24. // 2 = Standard debug level
  25. // 3 = Major code branches
  26. // 4+ = Step through code
  27. LONG DebugLevel = 0;
  28. VOID
  29. __cdecl
  30. CddumpDebugPrint(
  31. LONG DebugPrintLevel,
  32. PCHAR DebugMessage,
  33. ...
  34. )
  35. /*++
  36. Routine Description:
  37. Debug print for RedBook driver
  38. Arguments:
  39. Debug print level between 0 and x, with x being the most verbose.
  40. Return Value:
  41. None
  42. --*/
  43. {
  44. va_list ap;
  45. //
  46. // allow negative numbers
  47. //
  48. if ((DebugPrintLevel < 0) || (DebugPrintLevel <= DebugLevel)) {
  49. HRESULT hr;
  50. char buffer[200]; // Potential overflow
  51. //
  52. // single print so won't swap, obscuring message
  53. //
  54. va_start( ap, DebugMessage );
  55. RtlCopyMemory( buffer, DBGHDR, DBGHDRLEN );
  56. hr = StringCbVPrintfA(buffer+DBGHDRLEN,
  57. sizeof(buffer) - DBGHDRLEN,
  58. DebugMessage,
  59. ap);
  60. if (HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER || SUCCEEDED(hr)) {
  61. fprintf(stderr, buffer);
  62. }
  63. va_end(ap);
  64. }
  65. }
  66. #else
  67. // nothing
  68. #endif // DBG