Lines Matching refs:buf
60 #define UPDATE_COMPAT(buf) \ argument
61 if (buf->size < INT_MAX) buf->compat_size = buf->size; \
62 else buf->compat_size = INT_MAX; \
63 if (buf->use < INT_MAX) buf->compat_use = buf->use; \
64 else buf->compat_use = INT_MAX;
71 #define CHECK_COMPAT(buf) \ argument
72 if (buf->size != (size_t) buf->compat_size) \
73 if (buf->compat_size < INT_MAX) \
74 buf->size = buf->compat_size; \
75 if (buf->use != (size_t) buf->compat_use) \
76 if (buf->compat_use < INT_MAX) \
77 buf->use = buf->compat_use;
80 #define UPDATE_COMPAT(buf) argument
81 #define CHECK_COMPAT(buf) argument
92 xmlBufMemoryError(xmlBufPtr buf, const char *extra) in xmlBufMemoryError() argument
95 if ((buf) && (buf->error == 0)) in xmlBufMemoryError()
96 buf->error = XML_ERR_NO_MEMORY; in xmlBufMemoryError()
107 xmlBufOverflowError(xmlBufPtr buf, const char *extra) in xmlBufOverflowError() argument
110 if ((buf) && (buf->error == 0)) in xmlBufOverflowError()
111 buf->error = XML_BUF_OVERFLOW; in xmlBufOverflowError()
196 xmlBufDetach(xmlBufPtr buf) { in xmlBufDetach() argument
199 if (buf == NULL) in xmlBufDetach()
201 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufDetach()
203 if (buf->buffer != NULL) in xmlBufDetach()
205 if (buf->error) in xmlBufDetach()
208 ret = buf->content; in xmlBufDetach()
209 buf->content = NULL; in xmlBufDetach()
210 buf->size = 0; in xmlBufDetach()
211 buf->use = 0; in xmlBufDetach()
212 buf->compat_use = 0; in xmlBufDetach()
213 buf->compat_size = 0; in xmlBufDetach()
267 xmlBufGetAllocationScheme(xmlBufPtr buf) { in xmlBufGetAllocationScheme() argument
268 if (buf == NULL) { in xmlBufGetAllocationScheme()
275 return(buf->alloc); in xmlBufGetAllocationScheme()
288 xmlBufSetAllocationScheme(xmlBufPtr buf, in xmlBufSetAllocationScheme() argument
290 if ((buf == NULL) || (buf->error != 0)) { in xmlBufSetAllocationScheme()
297 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || in xmlBufSetAllocationScheme()
298 (buf->alloc == XML_BUFFER_ALLOC_IO)) in xmlBufSetAllocationScheme()
305 buf->alloc = scheme; in xmlBufSetAllocationScheme()
306 if (buf->buffer) in xmlBufSetAllocationScheme()
307 buf->buffer->alloc = scheme; in xmlBufSetAllocationScheme()
315 buf->alloc = XML_BUFFER_ALLOC_IO; in xmlBufSetAllocationScheme()
316 buf->contentIO = buf->content; in xmlBufSetAllocationScheme()
329 xmlBufFree(xmlBufPtr buf) { in xmlBufFree() argument
330 if (buf == NULL) { in xmlBufFree()
338 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && in xmlBufFree()
339 (buf->contentIO != NULL)) { in xmlBufFree()
340 xmlFree(buf->contentIO); in xmlBufFree()
341 } else if ((buf->content != NULL) && in xmlBufFree()
342 (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { in xmlBufFree()
343 xmlFree(buf->content); in xmlBufFree()
345 xmlFree(buf); in xmlBufFree()
355 xmlBufEmpty(xmlBufPtr buf) { in xmlBufEmpty() argument
356 if ((buf == NULL) || (buf->error != 0)) return; in xmlBufEmpty()
357 if (buf->content == NULL) return; in xmlBufEmpty()
358 CHECK_COMPAT(buf) in xmlBufEmpty()
359 buf->use = 0; in xmlBufEmpty()
360 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { in xmlBufEmpty()
361 buf->content = BAD_CAST ""; in xmlBufEmpty()
362 } else if ((buf->alloc == XML_BUFFER_ALLOC_IO) && in xmlBufEmpty()
363 (buf->contentIO != NULL)) { in xmlBufEmpty()
364 size_t start_buf = buf->content - buf->contentIO; in xmlBufEmpty()
366 buf->size += start_buf; in xmlBufEmpty()
367 buf->content = buf->contentIO; in xmlBufEmpty()
368 buf->content[0] = 0; in xmlBufEmpty()
370 buf->content[0] = 0; in xmlBufEmpty()
372 UPDATE_COMPAT(buf) in xmlBufEmpty()
388 xmlBufShrink(xmlBufPtr buf, size_t len) { in xmlBufShrink() argument
389 if ((buf == NULL) || (buf->error != 0)) return(0); in xmlBufShrink()
390 CHECK_COMPAT(buf) in xmlBufShrink()
392 if (len > buf->use) return(0); in xmlBufShrink()
394 buf->use -= len; in xmlBufShrink()
395 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || in xmlBufShrink()
396 ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL))) { in xmlBufShrink()
401 buf->content += len; in xmlBufShrink()
402 buf->size -= len; in xmlBufShrink()
408 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufShrink()
409 size_t start_buf = buf->content - buf->contentIO; in xmlBufShrink()
410 if (start_buf >= buf->size) { in xmlBufShrink()
411 memmove(buf->contentIO, &buf->content[0], buf->use); in xmlBufShrink()
412 buf->content = buf->contentIO; in xmlBufShrink()
413 buf->content[buf->use] = 0; in xmlBufShrink()
414 buf->size += start_buf; in xmlBufShrink()
418 memmove(buf->content, &buf->content[len], buf->use); in xmlBufShrink()
419 buf->content[buf->use] = 0; in xmlBufShrink()
421 UPDATE_COMPAT(buf) in xmlBufShrink()
437 xmlBufGrowInternal(xmlBufPtr buf, size_t len) { in xmlBufGrowInternal() argument
441 if ((buf == NULL) || (buf->error != 0)) return(0); in xmlBufGrowInternal()
442 CHECK_COMPAT(buf) in xmlBufGrowInternal()
444 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); in xmlBufGrowInternal()
445 if (buf->use + len < buf->size) in xmlBufGrowInternal()
446 return(buf->size - buf->use); in xmlBufGrowInternal()
455 if (buf->size > (size_t) len) in xmlBufGrowInternal()
456 size = buf->size * 2; in xmlBufGrowInternal()
458 size = buf->use + len + 100; in xmlBufGrowInternal()
460 size = buf->use + len + 100; in xmlBufGrowInternal()
463 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufGrowInternal()
467 if ((buf->use + len >= XML_MAX_TEXT_LENGTH) || in xmlBufGrowInternal()
468 (buf->size >= XML_MAX_TEXT_LENGTH)) { in xmlBufGrowInternal()
469 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufGrowInternal()
475 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufGrowInternal()
476 size_t start_buf = buf->content - buf->contentIO; in xmlBufGrowInternal()
478 newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size); in xmlBufGrowInternal()
480 xmlBufMemoryError(buf, "growing buffer"); in xmlBufGrowInternal()
483 buf->contentIO = newbuf; in xmlBufGrowInternal()
484 buf->content = newbuf + start_buf; in xmlBufGrowInternal()
486 newbuf = (xmlChar *) xmlRealloc(buf->content, size); in xmlBufGrowInternal()
488 xmlBufMemoryError(buf, "growing buffer"); in xmlBufGrowInternal()
491 buf->content = newbuf; in xmlBufGrowInternal()
493 buf->size = size; in xmlBufGrowInternal()
494 UPDATE_COMPAT(buf) in xmlBufGrowInternal()
495 return(buf->size - buf->use); in xmlBufGrowInternal()
509 xmlBufGrow(xmlBufPtr buf, int len) { in xmlBufGrow() argument
512 if ((buf == NULL) || (len < 0)) return(-1); in xmlBufGrow()
515 ret = xmlBufGrowInternal(buf, len); in xmlBufGrow()
516 if (buf->error != 0) in xmlBufGrow()
531 xmlBufInflate(xmlBufPtr buf, size_t len) { in xmlBufInflate() argument
532 if (buf == NULL) return(-1); in xmlBufInflate()
533 xmlBufGrowInternal(buf, len + buf->size); in xmlBufInflate()
534 if (buf->error) in xmlBufInflate()
548 xmlBufDump(FILE *file, xmlBufPtr buf) { in xmlBufDump() argument
551 if ((buf == NULL) || (buf->error != 0)) { in xmlBufDump()
558 if (buf->content == NULL) { in xmlBufDump()
565 CHECK_COMPAT(buf) in xmlBufDump()
568 ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file); in xmlBufDump()
582 xmlBufContent(const xmlBuf *buf) in xmlBufContent() argument
584 if ((!buf) || (buf->error)) in xmlBufContent()
587 return(buf->content); in xmlBufContent()
600 xmlBufEnd(xmlBufPtr buf) in xmlBufEnd() argument
602 if ((!buf) || (buf->error)) in xmlBufEnd()
604 CHECK_COMPAT(buf) in xmlBufEnd()
606 return(&buf->content[buf->use]); in xmlBufEnd()
621 xmlBufAddLen(xmlBufPtr buf, size_t len) { in xmlBufAddLen() argument
622 if ((buf == NULL) || (buf->error)) in xmlBufAddLen()
624 CHECK_COMPAT(buf) in xmlBufAddLen()
625 if (len > (buf->size - buf->use)) in xmlBufAddLen()
627 buf->use += len; in xmlBufAddLen()
628 UPDATE_COMPAT(buf) in xmlBufAddLen()
629 if (buf->size > buf->use) in xmlBufAddLen()
630 buf->content[buf->use] = 0; in xmlBufAddLen()
646 xmlBufErase(xmlBufPtr buf, size_t len) { in xmlBufErase() argument
647 if ((buf == NULL) || (buf->error)) in xmlBufErase()
649 CHECK_COMPAT(buf) in xmlBufErase()
650 if (len > buf->use) in xmlBufErase()
652 buf->use -= len; in xmlBufErase()
653 buf->content[buf->use] = 0; in xmlBufErase()
654 UPDATE_COMPAT(buf) in xmlBufErase()
668 xmlBufLength(const xmlBufPtr buf) in xmlBufLength() argument
670 if ((!buf) || (buf->error)) in xmlBufLength()
672 CHECK_COMPAT(buf) in xmlBufLength()
674 return(buf->use); in xmlBufLength()
687 xmlBufUse(const xmlBufPtr buf) in xmlBufUse() argument
689 if ((!buf) || (buf->error)) in xmlBufUse()
691 CHECK_COMPAT(buf) in xmlBufUse()
693 return(buf->use); in xmlBufUse()
708 xmlBufAvail(const xmlBufPtr buf) in xmlBufAvail() argument
710 if ((!buf) || (buf->error)) in xmlBufAvail()
712 CHECK_COMPAT(buf) in xmlBufAvail()
714 return(buf->size - buf->use); in xmlBufAvail()
726 xmlBufIsEmpty(const xmlBufPtr buf) in xmlBufIsEmpty() argument
728 if ((!buf) || (buf->error)) in xmlBufIsEmpty()
730 CHECK_COMPAT(buf) in xmlBufIsEmpty()
732 return(buf->use == 0); in xmlBufIsEmpty()
745 xmlBufResize(xmlBufPtr buf, size_t size) in xmlBufResize() argument
751 if ((buf == NULL) || (buf->error)) in xmlBufResize()
753 CHECK_COMPAT(buf) in xmlBufResize()
755 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); in xmlBufResize()
756 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufResize()
761 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufResize()
767 if (size < buf->size) in xmlBufResize()
771 switch (buf->alloc){ in xmlBufResize()
775 newSize = (buf->size ? buf->size*2 : size + 10); in xmlBufResize()
778 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
788 if (buf->use < BASE_BUFFER_SIZE) in xmlBufResize()
791 newSize = buf->size * 2; in xmlBufResize()
794 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
807 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufResize()
808 start_buf = buf->content - buf->contentIO; in xmlBufResize()
812 memmove(buf->contentIO, buf->content, buf->use); in xmlBufResize()
813 buf->content = buf->contentIO; in xmlBufResize()
814 buf->content[buf->use] = 0; in xmlBufResize()
815 buf->size += start_buf; in xmlBufResize()
817 rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize); in xmlBufResize()
819 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
822 buf->contentIO = rebuf; in xmlBufResize()
823 buf->content = rebuf + start_buf; in xmlBufResize()
826 if (buf->content == NULL) { in xmlBufResize()
828 } else if (buf->size - buf->use < 100) { in xmlBufResize()
829 rebuf = (xmlChar *) xmlRealloc(buf->content, newSize); in xmlBufResize()
838 memcpy(rebuf, buf->content, buf->use); in xmlBufResize()
839 xmlFree(buf->content); in xmlBufResize()
840 rebuf[buf->use] = 0; in xmlBufResize()
844 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
847 buf->content = rebuf; in xmlBufResize()
849 buf->size = newSize; in xmlBufResize()
850 UPDATE_COMPAT(buf) in xmlBufResize()
868 xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) { in xmlBufAdd() argument
871 if ((str == NULL) || (buf == NULL) || (buf->error)) in xmlBufAdd()
873 CHECK_COMPAT(buf) in xmlBufAdd()
875 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufAdd()
891 needSize = buf->use + len + 2; in xmlBufAdd()
892 if (needSize > buf->size){ in xmlBufAdd()
893 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufAdd()
898 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufAdd()
902 if (!xmlBufResize(buf, needSize)){ in xmlBufAdd()
903 xmlBufMemoryError(buf, "growing buffer"); in xmlBufAdd()
908 memmove(&buf->content[buf->use], str, len*sizeof(xmlChar)); in xmlBufAdd()
909 buf->use += len; in xmlBufAdd()
910 buf->content[buf->use] = 0; in xmlBufAdd()
911 UPDATE_COMPAT(buf) in xmlBufAdd()
928 xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) { in xmlBufAddHead() argument
931 if ((buf == NULL) || (buf->error)) in xmlBufAddHead()
933 CHECK_COMPAT(buf) in xmlBufAddHead()
934 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufAddHead()
956 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufAddHead()
957 size_t start_buf = buf->content - buf->contentIO; in xmlBufAddHead()
963 buf->content -= len; in xmlBufAddHead()
964 memmove(&buf->content[0], str, len); in xmlBufAddHead()
965 buf->use += len; in xmlBufAddHead()
966 buf->size += len; in xmlBufAddHead()
967 UPDATE_COMPAT(buf) in xmlBufAddHead()
971 needSize = buf->use + len + 2; in xmlBufAddHead()
972 if (needSize > buf->size){ in xmlBufAddHead()
973 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) { in xmlBufAddHead()
978 xmlBufMemoryError(buf, "buffer error: text too long\n"); in xmlBufAddHead()
982 if (!xmlBufResize(buf, needSize)){ in xmlBufAddHead()
983 xmlBufMemoryError(buf, "growing buffer"); in xmlBufAddHead()
988 memmove(&buf->content[len], &buf->content[0], buf->use); in xmlBufAddHead()
989 memmove(&buf->content[0], str, len); in xmlBufAddHead()
990 buf->use += len; in xmlBufAddHead()
991 buf->content[buf->use] = 0; in xmlBufAddHead()
992 UPDATE_COMPAT(buf) in xmlBufAddHead()
1007 xmlBufCat(xmlBufPtr buf, const xmlChar *str) { in xmlBufCat() argument
1008 if ((buf == NULL) || (buf->error)) in xmlBufCat()
1010 CHECK_COMPAT(buf) in xmlBufCat()
1011 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufCat()
1013 return xmlBufAdd(buf, str, -1); in xmlBufCat()
1027 xmlBufCCat(xmlBufPtr buf, const char *str) { in xmlBufCCat() argument
1030 if ((buf == NULL) || (buf->error)) in xmlBufCCat()
1032 CHECK_COMPAT(buf) in xmlBufCCat()
1033 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufCCat()
1042 if (buf->use + 10 >= buf->size) { in xmlBufCCat()
1043 if (!xmlBufResize(buf, buf->use+10)){ in xmlBufCCat()
1044 xmlBufMemoryError(buf, "growing buffer"); in xmlBufCCat()
1048 buf->content[buf->use++] = *cur; in xmlBufCCat()
1050 buf->content[buf->use] = 0; in xmlBufCCat()
1051 UPDATE_COMPAT(buf) in xmlBufCCat()
1067 xmlBufWriteCHAR(xmlBufPtr buf, const xmlChar *string) { in xmlBufWriteCHAR() argument
1068 if ((buf == NULL) || (buf->error)) in xmlBufWriteCHAR()
1070 CHECK_COMPAT(buf) in xmlBufWriteCHAR()
1071 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteCHAR()
1073 return(xmlBufCat(buf, string)); in xmlBufWriteCHAR()
1088 xmlBufWriteChar(xmlBufPtr buf, const char *string) { in xmlBufWriteChar() argument
1089 if ((buf == NULL) || (buf->error)) in xmlBufWriteChar()
1091 CHECK_COMPAT(buf) in xmlBufWriteChar()
1092 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteChar()
1094 return(xmlBufCCat(buf, string)); in xmlBufWriteChar()
1111 xmlBufWriteQuotedString(xmlBufPtr buf, const xmlChar *string) { in xmlBufWriteQuotedString() argument
1113 if ((buf == NULL) || (buf->error)) in xmlBufWriteQuotedString()
1115 CHECK_COMPAT(buf) in xmlBufWriteQuotedString()
1116 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteQuotedString()
1124 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1129 xmlBufAdd(buf, base, cur - base); in xmlBufWriteQuotedString()
1130 xmlBufAdd(buf, BAD_CAST """, 6); in xmlBufWriteQuotedString()
1139 xmlBufAdd(buf, base, cur - base); in xmlBufWriteQuotedString()
1140 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1143 xmlBufCCat(buf, "\'"); in xmlBufWriteQuotedString()
1144 xmlBufCat(buf, string); in xmlBufWriteQuotedString()
1145 xmlBufCCat(buf, "\'"); in xmlBufWriteQuotedString()
1148 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1149 xmlBufCat(buf, string); in xmlBufWriteQuotedString()
1150 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1204 xmlBufBackToBuffer(xmlBufPtr buf) { in xmlBufBackToBuffer() argument
1207 if ((buf == NULL) || (buf->error)) in xmlBufBackToBuffer()
1209 CHECK_COMPAT(buf) in xmlBufBackToBuffer()
1210 if (buf->buffer == NULL) { in xmlBufBackToBuffer()
1211 xmlBufFree(buf); in xmlBufBackToBuffer()
1215 ret = buf->buffer; in xmlBufBackToBuffer()
1219 if (buf->use > INT_MAX) { in xmlBufBackToBuffer()
1225 xmlBufOverflowError(buf, "Used size too big for xmlBuffer"); in xmlBufBackToBuffer()
1228 } else if (buf->size > INT_MAX) { in xmlBufBackToBuffer()
1235 xmlBufOverflowError(buf, "Allocated size too big for xmlBuffer"); in xmlBufBackToBuffer()
1238 ret->use = (int) buf->use; in xmlBufBackToBuffer()
1239 ret->size = (int) buf->size; in xmlBufBackToBuffer()
1240 ret->alloc = buf->alloc; in xmlBufBackToBuffer()
1241 ret->content = buf->content; in xmlBufBackToBuffer()
1242 ret->contentIO = buf->contentIO; in xmlBufBackToBuffer()
1243 xmlFree(buf); in xmlBufBackToBuffer()
1257 xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer) { in xmlBufMergeBuffer() argument
1260 if ((buf == NULL) || (buf->error)) { in xmlBufMergeBuffer()
1264 CHECK_COMPAT(buf) in xmlBufMergeBuffer()
1267 ret = xmlBufAdd(buf, buffer->content, buffer->use); in xmlBufMergeBuffer()
1283 xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input) { in xmlBufResetInput() argument
1284 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufResetInput()
1286 CHECK_COMPAT(buf) in xmlBufResetInput()
1287 input->base = input->cur = buf->content; in xmlBufResetInput()
1288 input->end = &buf->content[buf->use]; in xmlBufResetInput()
1302 xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input) { in xmlBufGetInputBase() argument
1305 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufGetInputBase()
1307 CHECK_COMPAT(buf) in xmlBufGetInputBase()
1308 base = input->base - buf->content; in xmlBufGetInputBase()
1313 if (base > buf->size) { in xmlBufGetInputBase()
1314 xmlBufOverflowError(buf, "Input reference outside of the buffer"); in xmlBufGetInputBase()
1333 xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, in xmlBufSetInputBaseCur() argument
1335 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufSetInputBaseCur()
1337 CHECK_COMPAT(buf) in xmlBufSetInputBaseCur()
1338 input->base = &buf->content[base]; in xmlBufSetInputBaseCur()
1340 input->end = &buf->content[buf->use]; in xmlBufSetInputBaseCur()