7zBuffer.c 593 B

123456789101112131415161718192021222324252627282930
  1. /* 7zBuffer.c */
  2. #include "7zBuffer.h"
  3. #include "7zAlloc.h"
  4. void SzByteBufferInit(CSzByteBuffer *buffer)
  5. {
  6. buffer->Capacity = 0;
  7. buffer->Items = 0;
  8. }
  9. int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))
  10. {
  11. buffer->Capacity = newCapacity;
  12. if (newCapacity == 0)
  13. {
  14. buffer->Items = 0;
  15. return 1;
  16. }
  17. buffer->Items = (Byte *)allocFunc(newCapacity);
  18. return (buffer->Items != 0);
  19. }
  20. void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))
  21. {
  22. freeFunc(buffer->Items);
  23. buffer->Items = 0;
  24. buffer->Capacity = 0;
  25. }