• Home
  • Raw
  • Download

Lines Matching refs:buf

64 #define UPDATE_COMPAT(buf)				    \  argument
65 if (buf->size < INT_MAX) buf->compat_size = buf->size; \
66 else buf->compat_size = INT_MAX; \
67 if (buf->use < INT_MAX) buf->compat_use = buf->use; \
68 else buf->compat_use = INT_MAX;
75 #define CHECK_COMPAT(buf) \ argument
76 if (buf->size != (size_t) buf->compat_size) \
77 if (buf->compat_size < INT_MAX) \
78 buf->size = buf->compat_size; \
79 if (buf->use != (size_t) buf->compat_use) \
80 if (buf->compat_use < INT_MAX) \
81 buf->use = buf->compat_use;
84 #define UPDATE_COMPAT(buf) argument
85 #define CHECK_COMPAT(buf) argument
96 xmlBufMemoryError(xmlBufPtr buf, const char *extra) in xmlBufMemoryError() argument
99 if ((buf) && (buf->error == 0)) in xmlBufMemoryError()
100 buf->error = XML_ERR_NO_MEMORY; in xmlBufMemoryError()
111 xmlBufOverflowError(xmlBufPtr buf, const char *extra) in xmlBufOverflowError() argument
114 if ((buf) && (buf->error == 0)) in xmlBufOverflowError()
115 buf->error = XML_BUF_OVERFLOW; in xmlBufOverflowError()
202 xmlBufDetach(xmlBufPtr buf) { in xmlBufDetach() argument
205 if (buf == NULL) in xmlBufDetach()
207 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufDetach()
209 if (buf->buffer != NULL) in xmlBufDetach()
211 if (buf->error) in xmlBufDetach()
214 ret = buf->content; in xmlBufDetach()
215 buf->content = NULL; in xmlBufDetach()
216 buf->size = 0; in xmlBufDetach()
217 buf->use = 0; in xmlBufDetach()
218 buf->compat_use = 0; in xmlBufDetach()
219 buf->compat_size = 0; in xmlBufDetach()
273 xmlBufGetAllocationScheme(xmlBufPtr buf) { in xmlBufGetAllocationScheme() argument
274 if (buf == NULL) { in xmlBufGetAllocationScheme()
281 return(buf->alloc); in xmlBufGetAllocationScheme()
294 xmlBufSetAllocationScheme(xmlBufPtr buf, in xmlBufSetAllocationScheme() argument
296 if ((buf == NULL) || (buf->error != 0)) { in xmlBufSetAllocationScheme()
303 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || in xmlBufSetAllocationScheme()
304 (buf->alloc == XML_BUFFER_ALLOC_IO)) in xmlBufSetAllocationScheme()
311 buf->alloc = scheme; in xmlBufSetAllocationScheme()
312 if (buf->buffer) in xmlBufSetAllocationScheme()
313 buf->buffer->alloc = scheme; in xmlBufSetAllocationScheme()
321 buf->alloc = XML_BUFFER_ALLOC_IO; in xmlBufSetAllocationScheme()
322 buf->contentIO = buf->content; in xmlBufSetAllocationScheme()
335 xmlBufFree(xmlBufPtr buf) { in xmlBufFree() argument
336 if (buf == NULL) { in xmlBufFree()
344 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && in xmlBufFree()
345 (buf->contentIO != NULL)) { in xmlBufFree()
346 xmlFree(buf->contentIO); in xmlBufFree()
347 } else if ((buf->content != NULL) && in xmlBufFree()
348 (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { in xmlBufFree()
349 xmlFree(buf->content); in xmlBufFree()
351 xmlFree(buf); in xmlBufFree()
361 xmlBufEmpty(xmlBufPtr buf) { in xmlBufEmpty() argument
362 if ((buf == NULL) || (buf->error != 0)) return; in xmlBufEmpty()
363 if (buf->content == NULL) return; in xmlBufEmpty()
364 CHECK_COMPAT(buf) in xmlBufEmpty()
365 buf->use = 0; in xmlBufEmpty()
366 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { in xmlBufEmpty()
367 buf->content = BAD_CAST ""; in xmlBufEmpty()
368 } else if ((buf->alloc == XML_BUFFER_ALLOC_IO) && in xmlBufEmpty()
369 (buf->contentIO != NULL)) { in xmlBufEmpty()
370 size_t start_buf = buf->content - buf->contentIO; in xmlBufEmpty()
372 buf->size += start_buf; in xmlBufEmpty()
373 buf->content = buf->contentIO; in xmlBufEmpty()
374 buf->content[0] = 0; in xmlBufEmpty()
376 buf->content[0] = 0; in xmlBufEmpty()
378 UPDATE_COMPAT(buf) in xmlBufEmpty()
394 xmlBufShrink(xmlBufPtr buf, size_t len) { in xmlBufShrink() argument
395 if ((buf == NULL) || (buf->error != 0)) return(0); in xmlBufShrink()
396 CHECK_COMPAT(buf) in xmlBufShrink()
398 if (len > buf->use) return(0); in xmlBufShrink()
400 buf->use -= len; in xmlBufShrink()
401 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || in xmlBufShrink()
402 ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL))) { in xmlBufShrink()
407 buf->content += len; in xmlBufShrink()
408 buf->size -= len; in xmlBufShrink()
414 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufShrink()
415 size_t start_buf = buf->content - buf->contentIO; in xmlBufShrink()
416 if (start_buf >= buf->size) { in xmlBufShrink()
417 memmove(buf->contentIO, &buf->content[0], buf->use); in xmlBufShrink()
418 buf->content = buf->contentIO; in xmlBufShrink()
419 buf->content[buf->use] = 0; in xmlBufShrink()
420 buf->size += start_buf; in xmlBufShrink()
424 memmove(buf->content, &buf->content[len], buf->use); in xmlBufShrink()
425 buf->content[buf->use] = 0; in xmlBufShrink()
427 UPDATE_COMPAT(buf) in xmlBufShrink()
443 xmlBufGrowInternal(xmlBufPtr buf, size_t len) { in xmlBufGrowInternal() argument
447 if ((buf == NULL) || (buf->error != 0)) return(0); in xmlBufGrowInternal()
448 CHECK_COMPAT(buf) in xmlBufGrowInternal()
450 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); in xmlBufGrowInternal()
451 if (len < buf->size - buf->use) in xmlBufGrowInternal()
452 return(buf->size - buf->use); in xmlBufGrowInternal()
454 if (len > SIZE_MAX - buf->use) in xmlBufGrowInternal()
457 if (buf->size > (size_t) len) { in xmlBufGrowInternal()
458 size = buf->size > SIZE_MAX / 2 ? SIZE_MAX : buf->size * 2; in xmlBufGrowInternal()
460 size = buf->use + len; in xmlBufGrowInternal()
464 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufGrowInternal()
468 if ((buf->use + len >= XML_MAX_TEXT_LENGTH) || in xmlBufGrowInternal()
469 (buf->size >= XML_MAX_TEXT_LENGTH)) { in xmlBufGrowInternal()
470 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufGrowInternal()
476 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufGrowInternal()
477 size_t start_buf = buf->content - buf->contentIO; in xmlBufGrowInternal()
479 newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size); in xmlBufGrowInternal()
481 xmlBufMemoryError(buf, "growing buffer"); in xmlBufGrowInternal()
484 buf->contentIO = newbuf; in xmlBufGrowInternal()
485 buf->content = newbuf + start_buf; in xmlBufGrowInternal()
487 newbuf = (xmlChar *) xmlRealloc(buf->content, size); in xmlBufGrowInternal()
489 xmlBufMemoryError(buf, "growing buffer"); in xmlBufGrowInternal()
492 buf->content = newbuf; in xmlBufGrowInternal()
494 buf->size = size; in xmlBufGrowInternal()
495 UPDATE_COMPAT(buf) in xmlBufGrowInternal()
496 return(buf->size - buf->use); in xmlBufGrowInternal()
510 xmlBufGrow(xmlBufPtr buf, int len) { in xmlBufGrow() argument
513 if ((buf == NULL) || (len < 0)) return(-1); in xmlBufGrow()
516 ret = xmlBufGrowInternal(buf, len); in xmlBufGrow()
517 if (buf->error != 0) in xmlBufGrow()
532 xmlBufInflate(xmlBufPtr buf, size_t len) { in xmlBufInflate() argument
533 if (buf == NULL) return(-1); in xmlBufInflate()
534 xmlBufGrowInternal(buf, len + buf->size); in xmlBufInflate()
535 if (buf->error) in xmlBufInflate()
549 xmlBufDump(FILE *file, xmlBufPtr buf) { in xmlBufDump() argument
552 if ((buf == NULL) || (buf->error != 0)) { in xmlBufDump()
559 if (buf->content == NULL) { in xmlBufDump()
566 CHECK_COMPAT(buf) in xmlBufDump()
569 ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file); in xmlBufDump()
583 xmlBufContent(const xmlBuf *buf) in xmlBufContent() argument
585 if ((!buf) || (buf->error)) in xmlBufContent()
588 return(buf->content); in xmlBufContent()
601 xmlBufEnd(xmlBufPtr buf) in xmlBufEnd() argument
603 if ((!buf) || (buf->error)) in xmlBufEnd()
605 CHECK_COMPAT(buf) in xmlBufEnd()
607 return(&buf->content[buf->use]); in xmlBufEnd()
622 xmlBufAddLen(xmlBufPtr buf, size_t len) { in xmlBufAddLen() argument
623 if ((buf == NULL) || (buf->error)) in xmlBufAddLen()
625 CHECK_COMPAT(buf) in xmlBufAddLen()
626 if (len > (buf->size - buf->use)) in xmlBufAddLen()
628 buf->use += len; in xmlBufAddLen()
629 UPDATE_COMPAT(buf) in xmlBufAddLen()
630 if (buf->size > buf->use) in xmlBufAddLen()
631 buf->content[buf->use] = 0; in xmlBufAddLen()
647 xmlBufErase(xmlBufPtr buf, size_t len) { in xmlBufErase() argument
648 if ((buf == NULL) || (buf->error)) in xmlBufErase()
650 CHECK_COMPAT(buf) in xmlBufErase()
651 if (len > buf->use) in xmlBufErase()
653 buf->use -= len; in xmlBufErase()
654 buf->content[buf->use] = 0; in xmlBufErase()
655 UPDATE_COMPAT(buf) in xmlBufErase()
669 xmlBufLength(const xmlBufPtr buf) in xmlBufLength() argument
671 if ((!buf) || (buf->error)) in xmlBufLength()
673 CHECK_COMPAT(buf) in xmlBufLength()
675 return(buf->use); in xmlBufLength()
688 xmlBufUse(const xmlBufPtr buf) in xmlBufUse() argument
690 if ((!buf) || (buf->error)) in xmlBufUse()
692 CHECK_COMPAT(buf) in xmlBufUse()
694 return(buf->use); in xmlBufUse()
709 xmlBufAvail(const xmlBufPtr buf) in xmlBufAvail() argument
711 if ((!buf) || (buf->error)) in xmlBufAvail()
713 CHECK_COMPAT(buf) in xmlBufAvail()
715 return(buf->size - buf->use); in xmlBufAvail()
727 xmlBufIsEmpty(const xmlBufPtr buf) in xmlBufIsEmpty() argument
729 if ((!buf) || (buf->error)) in xmlBufIsEmpty()
731 CHECK_COMPAT(buf) in xmlBufIsEmpty()
733 return(buf->use == 0); in xmlBufIsEmpty()
746 xmlBufResize(xmlBufPtr buf, size_t size) in xmlBufResize() argument
752 if ((buf == NULL) || (buf->error)) in xmlBufResize()
754 CHECK_COMPAT(buf) in xmlBufResize()
756 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); in xmlBufResize()
757 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufResize()
762 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufResize()
768 if (size < buf->size) in xmlBufResize()
772 switch (buf->alloc){ in xmlBufResize()
776 if (buf->size == 0) { in xmlBufResize()
779 newSize = buf->size; in xmlBufResize()
783 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
793 if (buf->use < BASE_BUFFER_SIZE) in xmlBufResize()
796 newSize = buf->size; in xmlBufResize()
799 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
812 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufResize()
813 start_buf = buf->content - buf->contentIO; in xmlBufResize()
817 memmove(buf->contentIO, buf->content, buf->use); in xmlBufResize()
818 buf->content = buf->contentIO; in xmlBufResize()
819 buf->content[buf->use] = 0; in xmlBufResize()
820 buf->size += start_buf; in xmlBufResize()
822 rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize); in xmlBufResize()
824 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
827 buf->contentIO = rebuf; in xmlBufResize()
828 buf->content = rebuf + start_buf; in xmlBufResize()
831 if (buf->content == NULL) { in xmlBufResize()
833 } else if (buf->size - buf->use < 100) { in xmlBufResize()
834 rebuf = (xmlChar *) xmlRealloc(buf->content, newSize); in xmlBufResize()
843 memcpy(rebuf, buf->content, buf->use); in xmlBufResize()
844 xmlFree(buf->content); in xmlBufResize()
845 rebuf[buf->use] = 0; in xmlBufResize()
849 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
852 buf->content = rebuf; in xmlBufResize()
854 buf->size = newSize; in xmlBufResize()
855 UPDATE_COMPAT(buf) in xmlBufResize()
873 xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) { in xmlBufAdd() argument
876 if ((str == NULL) || (buf == NULL) || (buf->error)) in xmlBufAdd()
878 CHECK_COMPAT(buf) in xmlBufAdd()
880 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufAdd()
896 if ((size_t) len >= buf->size - buf->use) { in xmlBufAdd()
897 if ((size_t) len >= SIZE_MAX - buf->use) in xmlBufAdd()
899 needSize = buf->use + len + 1; in xmlBufAdd()
900 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufAdd()
905 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufAdd()
909 if (!xmlBufResize(buf, needSize)){ in xmlBufAdd()
910 xmlBufMemoryError(buf, "growing buffer"); in xmlBufAdd()
915 memmove(&buf->content[buf->use], str, len*sizeof(xmlChar)); in xmlBufAdd()
916 buf->use += len; in xmlBufAdd()
917 buf->content[buf->use] = 0; in xmlBufAdd()
918 UPDATE_COMPAT(buf) in xmlBufAdd()
935 xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) { in xmlBufAddHead() argument
938 if ((buf == NULL) || (buf->error)) in xmlBufAddHead()
940 CHECK_COMPAT(buf) in xmlBufAddHead()
941 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufAddHead()
963 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufAddHead()
964 size_t start_buf = buf->content - buf->contentIO; in xmlBufAddHead()
970 buf->content -= len; in xmlBufAddHead()
971 memmove(&buf->content[0], str, len); in xmlBufAddHead()
972 buf->use += len; in xmlBufAddHead()
973 buf->size += len; in xmlBufAddHead()
974 UPDATE_COMPAT(buf) in xmlBufAddHead()
978 needSize = buf->use + len + 2; in xmlBufAddHead()
979 if (needSize > buf->size){ in xmlBufAddHead()
980 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufAddHead()
985 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufAddHead()
989 if (!xmlBufResize(buf, needSize)){ in xmlBufAddHead()
990 xmlBufMemoryError(buf, "growing buffer"); in xmlBufAddHead()
995 memmove(&buf->content[len], &buf->content[0], buf->use); in xmlBufAddHead()
996 memmove(&buf->content[0], str, len); in xmlBufAddHead()
997 buf->use += len; in xmlBufAddHead()
998 buf->content[buf->use] = 0; in xmlBufAddHead()
999 UPDATE_COMPAT(buf) in xmlBufAddHead()
1014 xmlBufCat(xmlBufPtr buf, const xmlChar *str) { in xmlBufCat() argument
1015 if ((buf == NULL) || (buf->error)) in xmlBufCat()
1017 CHECK_COMPAT(buf) in xmlBufCat()
1018 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufCat()
1020 return xmlBufAdd(buf, str, -1); in xmlBufCat()
1034 xmlBufCCat(xmlBufPtr buf, const char *str) { in xmlBufCCat() argument
1035 return xmlBufCat(buf, (const xmlChar *) str); in xmlBufCCat()
1050 xmlBufWriteCHAR(xmlBufPtr buf, const xmlChar *string) { in xmlBufWriteCHAR() argument
1051 if ((buf == NULL) || (buf->error)) in xmlBufWriteCHAR()
1053 CHECK_COMPAT(buf) in xmlBufWriteCHAR()
1054 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteCHAR()
1056 return(xmlBufCat(buf, string)); in xmlBufWriteCHAR()
1071 xmlBufWriteChar(xmlBufPtr buf, const char *string) { in xmlBufWriteChar() argument
1072 if ((buf == NULL) || (buf->error)) in xmlBufWriteChar()
1074 CHECK_COMPAT(buf) in xmlBufWriteChar()
1075 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteChar()
1077 return(xmlBufCCat(buf, string)); in xmlBufWriteChar()
1094 xmlBufWriteQuotedString(xmlBufPtr buf, const xmlChar *string) { in xmlBufWriteQuotedString() argument
1096 if ((buf == NULL) || (buf->error)) in xmlBufWriteQuotedString()
1098 CHECK_COMPAT(buf) in xmlBufWriteQuotedString()
1099 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteQuotedString()
1107 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1112 xmlBufAdd(buf, base, cur - base); in xmlBufWriteQuotedString()
1113 xmlBufAdd(buf, BAD_CAST "&quot;", 6); in xmlBufWriteQuotedString()
1122 xmlBufAdd(buf, base, cur - base); in xmlBufWriteQuotedString()
1123 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1126 xmlBufCCat(buf, "\'"); in xmlBufWriteQuotedString()
1127 xmlBufCat(buf, string); in xmlBufWriteQuotedString()
1128 xmlBufCCat(buf, "\'"); in xmlBufWriteQuotedString()
1131 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1132 xmlBufCat(buf, string); in xmlBufWriteQuotedString()
1133 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1187 xmlBufBackToBuffer(xmlBufPtr buf) { in xmlBufBackToBuffer() argument
1190 if (buf == NULL) in xmlBufBackToBuffer()
1192 CHECK_COMPAT(buf) in xmlBufBackToBuffer()
1193 if ((buf->error) || (buf->buffer == NULL)) { in xmlBufBackToBuffer()
1194 xmlBufFree(buf); in xmlBufBackToBuffer()
1198 ret = buf->buffer; in xmlBufBackToBuffer()
1202 if (buf->use > INT_MAX) { in xmlBufBackToBuffer()
1208 xmlBufOverflowError(buf, "Used size too big for xmlBuffer"); in xmlBufBackToBuffer()
1211 } else if (buf->size > INT_MAX) { in xmlBufBackToBuffer()
1218 xmlBufOverflowError(buf, "Allocated size too big for xmlBuffer"); in xmlBufBackToBuffer()
1219 ret->use = (int) buf->use; in xmlBufBackToBuffer()
1222 ret->use = (int) buf->use; in xmlBufBackToBuffer()
1223 ret->size = (int) buf->size; in xmlBufBackToBuffer()
1225 ret->alloc = buf->alloc; in xmlBufBackToBuffer()
1226 ret->content = buf->content; in xmlBufBackToBuffer()
1227 ret->contentIO = buf->contentIO; in xmlBufBackToBuffer()
1228 xmlFree(buf); in xmlBufBackToBuffer()
1242 xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer) { in xmlBufMergeBuffer() argument
1245 if ((buf == NULL) || (buf->error)) { in xmlBufMergeBuffer()
1249 CHECK_COMPAT(buf) in xmlBufMergeBuffer()
1252 ret = xmlBufAdd(buf, buffer->content, buffer->use); in xmlBufMergeBuffer()
1268 xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input) { in xmlBufResetInput() argument
1269 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufResetInput()
1271 CHECK_COMPAT(buf) in xmlBufResetInput()
1272 input->base = input->cur = buf->content; in xmlBufResetInput()
1273 input->end = &buf->content[buf->use]; in xmlBufResetInput()
1287 xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input) { in xmlBufGetInputBase() argument
1290 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufGetInputBase()
1292 CHECK_COMPAT(buf) in xmlBufGetInputBase()
1293 base = input->base - buf->content; in xmlBufGetInputBase()
1298 if (base > buf->size) { in xmlBufGetInputBase()
1299 xmlBufOverflowError(buf, "Input reference outside of the buffer"); in xmlBufGetInputBase()
1318 xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, in xmlBufSetInputBaseCur() argument
1322 if ((buf == NULL) || (buf->error)) { in xmlBufSetInputBaseCur()
1326 CHECK_COMPAT(buf) in xmlBufSetInputBaseCur()
1327 input->base = &buf->content[base]; in xmlBufSetInputBaseCur()
1329 input->end = &buf->content[buf->use]; in xmlBufSetInputBaseCur()