Lines Matching refs:pBuf

138 static void ebFree(ExpandBuf* pBuf)  in ebFree()  argument
140 if (pBuf != NULL) { in ebFree()
141 free(pBuf->storage); in ebFree()
142 free(pBuf); in ebFree()
152 static inline unsigned char* ebGetBuffer(ExpandBuf* pBuf) in ebGetBuffer() argument
154 return pBuf->storage; in ebGetBuffer()
160 static inline size_t ebGetLength(ExpandBuf* pBuf) in ebGetLength() argument
162 return pBuf->curLen; in ebGetLength()
168 static void ebClear(ExpandBuf* pBuf) in ebClear() argument
170 pBuf->curLen = 0; in ebClear()
176 static int ebEnsureCapacity(ExpandBuf* pBuf, int size) in ebEnsureCapacity() argument
180 if (pBuf->curLen + size > pBuf->maxLen) { in ebEnsureCapacity()
181 int newSize = pBuf->curLen + size + 128; /* oversize slightly */ in ebEnsureCapacity()
182 unsigned char* newStorage = realloc(pBuf->storage, newSize); in ebEnsureCapacity()
188 pBuf->storage = newStorage; in ebEnsureCapacity()
189 pBuf->maxLen = newSize; in ebEnsureCapacity()
192 assert(pBuf->curLen + size <= pBuf->maxLen); in ebEnsureCapacity()
199 static int ebAddData(ExpandBuf* pBuf, const void* data, size_t count) in ebAddData() argument
201 ebEnsureCapacity(pBuf, count); in ebAddData()
202 memcpy(pBuf->storage + pBuf->curLen, data, count); in ebAddData()
203 pBuf->curLen += count; in ebAddData()
210 static int ebReadString(ExpandBuf* pBuf, FILE* in) in ebReadString() argument
215 ebEnsureCapacity(pBuf, 1); in ebReadString()
223 pBuf->storage[pBuf->curLen++] = (unsigned char) ic; in ebReadString()
235 static int ebReadData(ExpandBuf* pBuf, FILE* in, size_t count, int eofExpected) in ebReadData() argument
241 ebEnsureCapacity(pBuf, count); in ebReadData()
242 actual = fread(pBuf->storage + pBuf->curLen, 1, count, in); in ebReadData()
252 pBuf->curLen += count; in ebReadData()
253 assert(pBuf->curLen <= pBuf->maxLen); in ebReadData()
261 static int ebWriteData(ExpandBuf* pBuf, FILE* out) in ebWriteData() argument
265 assert(pBuf->curLen > 0); in ebWriteData()
266 assert(pBuf->curLen <= pBuf->maxLen); in ebWriteData()
268 actual = fwrite(pBuf->storage, 1, pBuf->curLen, out); in ebWriteData()
269 if (actual != pBuf->curLen) { in ebWriteData()
270 fprintf(stderr, "ERROR: write %zu of %zu bytes\n", actual, pBuf->curLen); in ebWriteData()
274 pBuf->curLen = 0; in ebWriteData()
440 static int processHeapDump(ExpandBuf* pBuf, FILE* out, int flags) in processHeapDump() argument
443 unsigned char* origBuf = ebGetBuffer(pBuf); in processHeapDump()
445 int len = ebGetLength(pBuf); in processHeapDump()
450 pBuf = NULL; /* we just use the raw pointer from here forward */ in processHeapDump()
607 ExpandBuf* pBuf; in filterData() local
610 pBuf = ebAlloc(); in filterData()
611 if (pBuf == NULL) in filterData()
617 if (ebReadString(pBuf, in) != 0) in filterData()
620 magicString = (const char*)ebGetBuffer(pBuf); in filterData()
631 (ebGetBuffer(pBuf))[17] = '2'; in filterData()
632 if (ebWriteData(pBuf, out) != 0) in filterData()
640 if (ebReadData(pBuf, in, 12, FALSE) != 0) in filterData()
642 if (ebWriteData(pBuf, out) != 0) in filterData()
652 assert(ebGetLength(pBuf) == 0); in filterData()
655 if (ebReadData(pBuf, in, 1, TRUE) != 0) in filterData()
661 if (ebReadData(pBuf, in, kRecHdrLen-1, FALSE) != 0) in filterData()
664 unsigned char* buf = ebGetBuffer(pBuf); in filterData()
675 if (ebReadData(pBuf, in, length, FALSE) != 0) in filterData()
683 if (processHeapDump(pBuf, out, flags) != 0) in filterData()
685 ebClear(pBuf); in filterData()
689 if (ebWriteData(pBuf, out) != 0) in filterData()
697 ebFree(pBuf); in filterData()