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.

145 lines
3.6 KiB

  1. /*****************************************************************************\
  2. DEBUGAPI.C
  3. Confidential
  4. Copyright (c) Corporation 1998
  5. All rights reserved
  6. Debug API functions for the application to easily output information to
  7. the debugger.
  8. 12/98 - Jason Cohen (JCOHEN)
  9. 09/2000 - Stephen Lodwick (STELO)
  10. Ported OPK Wizard to Whistler
  11. \*****************************************************************************/
  12. //
  13. // Include File(s):
  14. //
  15. #include "pch.h"
  16. // We only want this code include if this is a debug version.
  17. //
  18. #ifdef DBG
  19. #include <windows.h>
  20. #include <tchar.h>
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. //
  24. // External Function(s):
  25. //
  26. INT DebugOutW(LPCWSTR lpFileName, LPCWSTR lpFormat, ...)
  27. {
  28. INT iChars = -1;
  29. va_list lpArgs;
  30. FILE * hFile;
  31. LPWSTR lpString;
  32. // Initialize the lpArgs parameter with va_start().
  33. //
  34. va_start(lpArgs, lpFormat);
  35. // Open the debug file for output if a file name was passed in.
  36. //
  37. if ( lpFileName && ( hFile = _wfopen(lpFileName, L"a") ) )
  38. {
  39. // Print the debug message to the file and close it.
  40. //
  41. iChars = vfwprintf(hFile, lpFormat, lpArgs);
  42. fclose(hFile);
  43. // Reinitialize the lpArgs parameter with va_start()
  44. // for the next call to a vptrintf function.
  45. //
  46. va_start(lpArgs, lpFormat);
  47. }
  48. // If something failed above, we won't know the size to use
  49. // for the string buffer, so just default to 2048 characters.
  50. //
  51. if ( iChars < 0 )
  52. iChars = 2047;
  53. // Allocate a buffer for the string.
  54. //
  55. if ( lpString = (LPWSTR) malloc((iChars + 1) * sizeof(WCHAR)) )
  56. {
  57. // Print out the string, send it to the debugger, and free it.
  58. //
  59. iChars = StringCchPrintf(lpString, iChars + 1, lpFormat, lpArgs);
  60. OutputDebugStringW(lpString);
  61. free(lpString);
  62. }
  63. else
  64. // Use -1 to return an error.
  65. //
  66. iChars = -1;
  67. // Return the number of characters printed.
  68. //
  69. return iChars;
  70. }
  71. INT DebugOutA(LPCSTR lpFileName, LPCSTR lpFormat, ...)
  72. {
  73. INT iChars = -1;
  74. va_list lpArgs;
  75. FILE * hFile;
  76. LPSTR lpString;
  77. // Initialize the lpArgs parameter with va_start().
  78. //
  79. va_start(lpArgs, lpFormat);
  80. // Open the debug file for output if a file name was passed in.
  81. //
  82. if ( lpFileName && ( hFile = fopen(lpFileName, "a") ) )
  83. {
  84. // Print the debug message to the file and close it.
  85. //
  86. iChars = vfprintf(hFile, lpFormat, lpArgs);
  87. fclose(hFile);
  88. // Reinitialize the lpArgs parameter with va_start()
  89. // for the next call to a vptrintf function.
  90. //
  91. va_start(lpArgs, lpFormat);
  92. }
  93. // If something failed above, we won't know the size to use
  94. // for the string buffer, so just default to 2048 characters.
  95. //
  96. if ( iChars < 0 )
  97. iChars = 2047;
  98. // Allocate a buffer for the string.
  99. //
  100. if ( lpString = (LPSTR) malloc((iChars + 1) * sizeof(CHAR)) )
  101. {
  102. // Print out the string, send it to the debugger, and free it.
  103. //
  104. iChars = StringCchPrintfA(lpString, iChars + 1, lpFormat, lpArgs);
  105. OutputDebugStringA(lpString);
  106. free(lpString);
  107. }
  108. else
  109. // Use -1 to return an error.
  110. //
  111. iChars = -1;
  112. // Return the number of characters printed.
  113. //
  114. return iChars;
  115. }
  116. #endif // DEBUG or _DEBUG