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.

48 lines
1.1 KiB

  1. /*****************************************************************************
  2. *
  3. * diqary.c
  4. *
  5. * Dynamic array manager.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. #pragma BEGIN_CONST_DATA
  10. /*****************************************************************************
  11. *
  12. * Dary_AppendCbx
  13. *
  14. * Grow if necessary, then copy the goo in if requested.
  15. *
  16. *****************************************************************************/
  17. int EXTERNAL
  18. Dary_AppendCbx(PDARY pdary, PCV pvX, int cbX)
  19. {
  20. if (pdary->cx >= pdary->cxMax) {
  21. PV rg2;
  22. int cxNew;
  23. if (pdary->rgx) {
  24. cxNew = pdary->cxMax * 2 + 1;
  25. rg2 = LocalReAlloc(pdary->rgx, cxNew * cbX, LMEM_MOVEABLE);
  26. } else {
  27. cxNew = 5;
  28. rg2 = LocalAlloc(LMEM_FIXED, cxNew * cbX);
  29. }
  30. if (rg2) {
  31. pdary->cxMax = cxNew;
  32. pdary->rgx = rg2;
  33. } else {
  34. return -1;
  35. }
  36. }
  37. if (pvX) {
  38. CopyMemory(Dary_GetPtrCbx(pdary, pdary->cx, cbX), pvX, cbX);
  39. }
  40. return pdary->cx++;
  41. }