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.

111 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. strlog.cxx
  5. Abstract:
  6. This module implements printing strings to a tracelog.
  7. Author:
  8. George V. Reilly (GeorgeRe) 22-Jun-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #include <strlog.hxx>
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. CStringTraceLog::CStringTraceLog(
  16. UINT cchEntrySize /* = 80 */,
  17. UINT cLogSize /* = 100 */)
  18. {
  19. m_Signature = SIGNATURE;
  20. m_cch = min(max(cchEntrySize, MIN_CCH), MAX_CCH);
  21. m_cch = (m_cch + sizeof(DWORD) - 1) & ~sizeof(DWORD);
  22. m_ptlog = CreateTraceLog(cLogSize, 0,
  23. sizeof(CLogEntry) - MAX_CCH + m_cch);
  24. }
  25. CStringTraceLog::~CStringTraceLog()
  26. {
  27. DestroyTraceLog(m_ptlog);
  28. m_Signature = SIGNATURE_X;
  29. }
  30. LONG __cdecl
  31. CStringTraceLog::Printf(
  32. LPCSTR pszFormat,
  33. ...)
  34. {
  35. DBG_ASSERT(this->m_Signature == SIGNATURE);
  36. DBG_ASSERT(this->m_ptlog != NULL);
  37. CLogEntry le;
  38. va_list argsList;
  39. va_start(argsList, pszFormat);
  40. INT cchOutput = _vsnprintf(le.m_ach, m_cch, pszFormat, argsList);
  41. va_end(argsList);
  42. //
  43. // The string length is long, we get back -1.
  44. // so we get the string length for partial data.
  45. //
  46. if ( cchOutput == -1 ) {
  47. //
  48. // terminate the string properly,
  49. // since _vsnprintf() does not terminate properly on failure.
  50. //
  51. cchOutput = m_cch - 1;
  52. le.m_ach[cchOutput] = '\0';
  53. }
  54. return WriteTraceLog(m_ptlog, &le);
  55. }
  56. LONG
  57. CStringTraceLog::Puts(
  58. LPCSTR psz)
  59. {
  60. DBG_ASSERT(this->m_Signature == SIGNATURE);
  61. DBG_ASSERT(this->m_ptlog != NULL);
  62. CLogEntry le;
  63. strncpy(le.m_ach, psz, m_cch);
  64. le.m_ach[m_cch - 1] = '\0';
  65. return WriteTraceLog(m_ptlog, &le);
  66. }
  67. void
  68. CStringTraceLog::ResetLog()
  69. {
  70. DBG_ASSERT(this->m_Signature == SIGNATURE);
  71. DBG_ASSERT(this->m_ptlog != NULL);
  72. ResetTraceLog(m_ptlog);
  73. }