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.

87 lines
1.7 KiB

  1. #include "cleanupwiz.h"
  2. #include "dblnul.h"
  3. //
  4. // Use of Zero-initialized memory keeps us from having to add nul terminators.
  5. //
  6. BOOL
  7. DblNulTermList::AddString(
  8. LPCTSTR psz, // String to copy.
  9. int cch // Length of psz in chars (excl nul term).
  10. )
  11. {
  12. while((m_cchAlloc - m_cchUsed) < (cch + 2))
  13. {
  14. if (!Grow())
  15. return false;
  16. }
  17. ASSERT(NULL != m_psz);
  18. if (SUCCEEDED(StringCchCopy(m_psz + m_cchUsed, m_cchAlloc - m_cchUsed, psz)))
  19. {
  20. m_cchUsed += cch + 1;
  21. m_cStrings++;
  22. return true;
  23. }
  24. else
  25. {
  26. return false;
  27. }
  28. }
  29. BOOL
  30. DblNulTermList::Grow(
  31. void
  32. )
  33. {
  34. BOOL fRet;
  35. ASSERT(m_cchGrow > 0);
  36. if (!m_psz)
  37. {
  38. int cb = m_cchGrow * sizeof(TCHAR);
  39. m_psz = (LPTSTR)LocalAlloc(LPTR, cb);
  40. if (m_psz)
  41. {
  42. *m_psz = TEXT('\0');
  43. m_cchAlloc = m_cchGrow;
  44. fRet = TRUE;
  45. }
  46. else
  47. {
  48. fRet = FALSE;
  49. }
  50. }
  51. else
  52. {
  53. int cb = (m_cchAlloc + m_cchGrow) * sizeof(TCHAR);
  54. LPTSTR p = (LPTSTR)LocalReAlloc(m_psz, cb, LMEM_MOVEABLE | LMEM_ZEROINIT);
  55. if (!p)
  56. {
  57. fRet = FALSE;
  58. }
  59. else
  60. {
  61. m_psz = p;
  62. m_cchAlloc += m_cchGrow;
  63. fRet = TRUE;
  64. }
  65. }
  66. return fRet;
  67. }
  68. BOOL
  69. DblNulTermListIter::Next(
  70. LPCTSTR *ppszItem
  71. )
  72. {
  73. if (*m_pszCurrent)
  74. {
  75. *ppszItem = m_pszCurrent;
  76. m_pszCurrent += lstrlen(m_pszCurrent) + 1;
  77. return true;
  78. }
  79. return false;
  80. }