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.

67 lines
1.9 KiB

  1. // rowitem.cpp CRowItem implementation
  2. #include "stdafx.h"
  3. #include "rowitem.h"
  4. CRowItem::CRowItem(int cAttributes)
  5. {
  6. ASSERT(cAttributes > 0);
  7. // Actual attr count is user count plus internal
  8. int cActual = cAttributes + INTERNAL_ATTR_COUNT;
  9. // allocate space for offsets and default parameter storage
  10. int bcInitial = sizeof(BufferHdr) + cActual * (sizeof(int) + DEFAULT_ATTR_SIZE);
  11. m_pBuff = (BufferHdr*)malloc(bcInitial);
  12. if (m_pBuff == NULL)
  13. THROW_ERROR(E_OUTOFMEMORY)
  14. // Set all offsets to -1
  15. memset(m_pBuff->aiOffset, 0xff, cActual * sizeof(int));
  16. m_pBuff->nRefCnt = 1;
  17. m_pBuff->nAttrCnt = cAttributes;
  18. m_pBuff->bcSize = bcInitial;
  19. m_pBuff->bcFree = cActual * DEFAULT_ATTR_SIZE;
  20. }
  21. HRESULT
  22. CRowItem::SetAttributePriv(int iAttr, LPCWSTR pszAttr)
  23. {
  24. ASSERT(m_pBuff != NULL);
  25. ASSERT(pszAttr != NULL);
  26. iAttr += INTERNAL_ATTR_COUNT;
  27. // For the current implementaion a given attribute can only be set once.
  28. // There is no facility for freeing the previous value.
  29. ASSERT(m_pBuff->aiOffset[iAttr] == -1);
  30. int bcAttrSize = (wcslen(pszAttr) + 1) * sizeof(WCHAR);
  31. // if no room, realocate buffer
  32. if (bcAttrSize > m_pBuff->bcFree)
  33. {
  34. BufferHdr* pBuffNew = (BufferHdr*)realloc(m_pBuff, m_pBuff->bcSize + bcAttrSize + EXTENSION_SIZE);
  35. if (pBuffNew == NULL)
  36. return E_OUTOFMEMORY;
  37. m_pBuff = pBuffNew;
  38. m_pBuff->bcSize += (bcAttrSize + EXTENSION_SIZE);
  39. m_pBuff->bcFree += (bcAttrSize + EXTENSION_SIZE);
  40. }
  41. // Append new attribute to end of memory block
  42. m_pBuff->aiOffset[iAttr] = m_pBuff->bcSize - m_pBuff->bcFree;
  43. memcpy(reinterpret_cast<BYTE*>(m_pBuff) + m_pBuff->aiOffset[iAttr], pszAttr, bcAttrSize);
  44. // adjust free space
  45. m_pBuff->bcFree -= bcAttrSize;
  46. return S_OK;
  47. }