Team Fortress 2 Source Code as on 22/4/2020
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
860 B

  1. /* 7zBuf2.c -- Byte Buffer
  2. 2013-11-12 : Igor Pavlov : Public domain */
  3. #include "Precomp.h"
  4. #include <string.h>
  5. #include "7zBuf.h"
  6. void DynBuf_Construct(CDynBuf *p)
  7. {
  8. p->data = 0;
  9. p->size = 0;
  10. p->pos = 0;
  11. }
  12. void DynBuf_SeekToBeg(CDynBuf *p)
  13. {
  14. p->pos = 0;
  15. }
  16. int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
  17. {
  18. if (size > p->size - p->pos)
  19. {
  20. size_t newSize = p->pos + size;
  21. Byte *data;
  22. newSize += newSize / 4;
  23. data = (Byte *)alloc->Alloc(alloc, newSize);
  24. if (data == 0)
  25. return 0;
  26. p->size = newSize;
  27. memcpy(data, p->data, p->pos);
  28. alloc->Free(alloc, p->data);
  29. p->data = data;
  30. }
  31. memcpy(p->data + p->pos, buf, size);
  32. p->pos += size;
  33. return 1;
  34. }
  35. void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
  36. {
  37. alloc->Free(alloc, p->data);
  38. p->data = 0;
  39. p->size = 0;
  40. p->pos = 0;
  41. }