1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* 7zBuf.c -- Byte Buffer 2cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky2013-01-21 : Igor Pavlov : Public domain */ 3cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 4cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#include "Precomp.h" 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "7zBuf.h" 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 8baa3858d3f5d128a5c8466b700098109edcad5f2repo syncvoid Buf_Init(CBuf *p) 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->data = 0; 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->size = 0; 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 14baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->size = 0; 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (size == 0) 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->data = 0; 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return 1; 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->data = (Byte *)alloc->Alloc(alloc, size); 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (p->data != 0) 24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->size = size; 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return 1; 27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return 0; 29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 31baa3858d3f5d128a5c8466b700098109edcad5f2repo syncvoid Buf_Free(CBuf *p, ISzAlloc *alloc) 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync alloc->Free(alloc, p->data); 34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->data = 0; 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync p->size = 0; 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 37