Home | History | Annotate | Download | only in hprof-conv

Lines Matching full:pbuf

124 static void ebFree(ExpandBuf* pBuf)
126 if (pBuf != NULL) {
127 free(pBuf->storage);
128 free(pBuf);
138 static inline unsigned char* ebGetBuffer(ExpandBuf* pBuf)
140 return pBuf->storage;
146 static inline size_t ebGetLength(ExpandBuf* pBuf)
148 return pBuf->curLen;
154 static void ebClear(ExpandBuf* pBuf)
156 pBuf->curLen = 0;
162 static int ebEnsureCapacity(ExpandBuf* pBuf, int size)
166 if (pBuf->curLen + size > pBuf->maxLen) {
167 int newSize = pBuf->curLen + size + 128; /* oversize slightly */
168 unsigned char* newStorage = realloc(pBuf->storage, newSize);
174 pBuf->storage = newStorage;
175 pBuf->maxLen = newSize;
178 assert(pBuf->curLen + size <= pBuf->maxLen);
185 static int ebAddData(ExpandBuf* pBuf, const void* data, size_t count)
187 ebEnsureCapacity(pBuf, count);
188 memcpy(pBuf->storage + pBuf->curLen, data, count);
189 pBuf->curLen += count;
196 static int ebReadString(ExpandBuf* pBuf, FILE* in)
201 ebEnsureCapacity(pBuf, 1);
209 pBuf->storage[pBuf->curLen++] = (unsigned char) ic;
221 static int ebReadData(ExpandBuf* pBuf, FILE* in, size_t count, int eofExpected)
227 ebEnsureCapacity(pBuf, count);
228 actual = fread(pBuf->storage + pBuf->curLen, 1, count, in);
238 pBuf->curLen += count;
239 assert(pBuf->curLen <= pBuf->maxLen);
247 static int ebWriteData(ExpandBuf* pBuf, FILE* out)
251 assert(pBuf->curLen > 0);
252 assert(pBuf->curLen <= pBuf->maxLen);
254 actual = fwrite(pBuf->storage, 1, pBuf->curLen, out);
255 if (actual != pBuf->curLen) {
256 fprintf(stderr, "ERROR: write %d of %d bytes\n", actual, pBuf->curLen);
260 pBuf->curLen = 0;
426 static int processHeapDump(ExpandBuf* pBuf, FILE* out)
429 unsigned char* origBuf = ebGetBuffer(pBuf);
431 int len = ebGetLength(pBuf);
434 pBuf = NULL; /* we just use the raw pointer from here forward */
576 ExpandBuf* pBuf;
579 pBuf = ebAlloc();
580 if (pBuf == NULL)
586 if (ebReadString(pBuf, in) != 0)
589 magicString = (const char*)ebGetBuffer(pBuf);
600 (ebGetBuffer(pBuf))[17] = '2';
601 if (ebWriteData(pBuf, out) != 0)
609 if (ebReadData(pBuf, in, 12, FALSE) != 0)
611 if (ebWriteData(pBuf, out) != 0)
621 assert(ebGetLength(pBuf) == 0);
624 if (ebReadData(pBuf, in, 1, TRUE) != 0)
630 if (ebReadData(pBuf, in, kRecHdrLen-1, FALSE) != 0)
633 pBuf);
644 if (ebReadData(pBuf, in, length, FALSE) != 0)
653 if (processHeapDump(pBuf, out) != 0)
655 ebClear(pBuf);
659 if (ebWriteData(pBuf, out) != 0)
667 ebFree(pBuf);