Lines Matching refs:buf
59 #define UPDATE_COMPAT(buf) \ argument
60 if (buf->size < INT_MAX) buf->compat_size = buf->size; \
61 else buf->compat_size = INT_MAX; \
62 if (buf->use < INT_MAX) buf->compat_use = buf->use; \
63 else buf->compat_use = INT_MAX;
70 #define CHECK_COMPAT(buf) \ argument
71 if (buf->size != (size_t) buf->compat_size) \
72 if (buf->compat_size < INT_MAX) \
73 buf->size = buf->compat_size; \
74 if (buf->use != (size_t) buf->compat_use) \
75 if (buf->compat_use < INT_MAX) \
76 buf->use = buf->compat_use;
79 #define UPDATE_COMPAT(buf) argument
80 #define CHECK_COMPAT(buf) argument
91 xmlBufMemoryError(xmlBufPtr buf, const char *extra) in xmlBufMemoryError() argument
94 if ((buf) && (buf->error == 0)) in xmlBufMemoryError()
95 buf->error = XML_ERR_NO_MEMORY; in xmlBufMemoryError()
106 xmlBufOverflowError(xmlBufPtr buf, const char *extra) in xmlBufOverflowError() argument
109 if ((buf) && (buf->error == 0)) in xmlBufOverflowError()
110 buf->error = XML_BUF_OVERFLOW; in xmlBufOverflowError()
195 xmlBufDetach(xmlBufPtr buf) { in xmlBufDetach() argument
198 if (buf == NULL) in xmlBufDetach()
200 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufDetach()
202 if (buf->buffer != NULL) in xmlBufDetach()
204 if (buf->error) in xmlBufDetach()
207 ret = buf->content; in xmlBufDetach()
208 buf->content = NULL; in xmlBufDetach()
209 buf->size = 0; in xmlBufDetach()
210 buf->use = 0; in xmlBufDetach()
211 buf->compat_use = 0; in xmlBufDetach()
212 buf->compat_size = 0; in xmlBufDetach()
266 xmlBufGetAllocationScheme(xmlBufPtr buf) { in xmlBufGetAllocationScheme() argument
267 if (buf == NULL) { in xmlBufGetAllocationScheme()
274 return(buf->alloc); in xmlBufGetAllocationScheme()
287 xmlBufSetAllocationScheme(xmlBufPtr buf, in xmlBufSetAllocationScheme() argument
289 if ((buf == NULL) || (buf->error != 0)) { in xmlBufSetAllocationScheme()
296 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || in xmlBufSetAllocationScheme()
297 (buf->alloc == XML_BUFFER_ALLOC_IO)) in xmlBufSetAllocationScheme()
303 buf->alloc = scheme; in xmlBufSetAllocationScheme()
304 if (buf->buffer) in xmlBufSetAllocationScheme()
305 buf->buffer->alloc = scheme; in xmlBufSetAllocationScheme()
313 buf->alloc = XML_BUFFER_ALLOC_IO; in xmlBufSetAllocationScheme()
314 buf->contentIO = buf->content; in xmlBufSetAllocationScheme()
327 xmlBufFree(xmlBufPtr buf) { in xmlBufFree() argument
328 if (buf == NULL) { in xmlBufFree()
336 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && in xmlBufFree()
337 (buf->contentIO != NULL)) { in xmlBufFree()
338 xmlFree(buf->contentIO); in xmlBufFree()
339 } else if ((buf->content != NULL) && in xmlBufFree()
340 (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { in xmlBufFree()
341 xmlFree(buf->content); in xmlBufFree()
343 xmlFree(buf); in xmlBufFree()
353 xmlBufEmpty(xmlBufPtr buf) { in xmlBufEmpty() argument
354 if ((buf == NULL) || (buf->error != 0)) return; in xmlBufEmpty()
355 if (buf->content == NULL) return; in xmlBufEmpty()
356 CHECK_COMPAT(buf) in xmlBufEmpty()
357 buf->use = 0; in xmlBufEmpty()
358 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { in xmlBufEmpty()
359 buf->content = BAD_CAST ""; in xmlBufEmpty()
360 } else if ((buf->alloc == XML_BUFFER_ALLOC_IO) && in xmlBufEmpty()
361 (buf->contentIO != NULL)) { in xmlBufEmpty()
362 size_t start_buf = buf->content - buf->contentIO; in xmlBufEmpty()
364 buf->size += start_buf; in xmlBufEmpty()
365 buf->content = buf->contentIO; in xmlBufEmpty()
366 buf->content[0] = 0; in xmlBufEmpty()
368 buf->content[0] = 0; in xmlBufEmpty()
370 UPDATE_COMPAT(buf) in xmlBufEmpty()
386 xmlBufShrink(xmlBufPtr buf, size_t len) { in xmlBufShrink() argument
387 if ((buf == NULL) || (buf->error != 0)) return(0); in xmlBufShrink()
388 CHECK_COMPAT(buf) in xmlBufShrink()
390 if (len > buf->use) return(0); in xmlBufShrink()
392 buf->use -= len; in xmlBufShrink()
393 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || in xmlBufShrink()
394 ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL))) { in xmlBufShrink()
399 buf->content += len; in xmlBufShrink()
400 buf->size -= len; in xmlBufShrink()
406 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufShrink()
407 size_t start_buf = buf->content - buf->contentIO; in xmlBufShrink()
408 if (start_buf >= buf->size) { in xmlBufShrink()
409 memmove(buf->contentIO, &buf->content[0], buf->use); in xmlBufShrink()
410 buf->content = buf->contentIO; in xmlBufShrink()
411 buf->content[buf->use] = 0; in xmlBufShrink()
412 buf->size += start_buf; in xmlBufShrink()
416 memmove(buf->content, &buf->content[len], buf->use); in xmlBufShrink()
417 buf->content[buf->use] = 0; in xmlBufShrink()
419 UPDATE_COMPAT(buf) in xmlBufShrink()
435 xmlBufGrowInternal(xmlBufPtr buf, size_t len) { in xmlBufGrowInternal() argument
439 if ((buf == NULL) || (buf->error != 0)) return(0); in xmlBufGrowInternal()
440 CHECK_COMPAT(buf) in xmlBufGrowInternal()
442 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); in xmlBufGrowInternal()
443 if (buf->use + len < buf->size) in xmlBufGrowInternal()
444 return(buf->size - buf->use); in xmlBufGrowInternal()
453 if (buf->size > (size_t) len) in xmlBufGrowInternal()
454 size = buf->size * 2; in xmlBufGrowInternal()
456 size = buf->use + len + 100; in xmlBufGrowInternal()
458 size = buf->use + len + 100; in xmlBufGrowInternal()
461 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufGrowInternal()
462 size_t start_buf = buf->content - buf->contentIO; in xmlBufGrowInternal()
464 newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size); in xmlBufGrowInternal()
466 xmlBufMemoryError(buf, "growing buffer"); in xmlBufGrowInternal()
469 buf->contentIO = newbuf; in xmlBufGrowInternal()
470 buf->content = newbuf + start_buf; in xmlBufGrowInternal()
472 newbuf = (xmlChar *) xmlRealloc(buf->content, size); in xmlBufGrowInternal()
474 xmlBufMemoryError(buf, "growing buffer"); in xmlBufGrowInternal()
477 buf->content = newbuf; in xmlBufGrowInternal()
479 buf->size = size; in xmlBufGrowInternal()
480 UPDATE_COMPAT(buf) in xmlBufGrowInternal()
481 return(buf->size - buf->use); in xmlBufGrowInternal()
495 xmlBufGrow(xmlBufPtr buf, int len) { in xmlBufGrow() argument
498 if ((buf == NULL) || (len < 0)) return(-1); in xmlBufGrow()
501 ret = xmlBufGrowInternal(buf, len); in xmlBufGrow()
502 if (buf->error != 0) in xmlBufGrow()
517 xmlBufInflate(xmlBufPtr buf, size_t len) { in xmlBufInflate() argument
518 if (buf == NULL) return(-1); in xmlBufInflate()
519 xmlBufGrowInternal(buf, len + buf->size); in xmlBufInflate()
520 if (buf->error) in xmlBufInflate()
534 xmlBufDump(FILE *file, xmlBufPtr buf) { in xmlBufDump() argument
537 if ((buf == NULL) || (buf->error != 0)) { in xmlBufDump()
544 if (buf->content == NULL) { in xmlBufDump()
551 CHECK_COMPAT(buf) in xmlBufDump()
554 ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file); in xmlBufDump()
568 xmlBufContent(const xmlBufPtr buf) in xmlBufContent() argument
570 if ((!buf) || (buf->error)) in xmlBufContent()
573 return(buf->content); in xmlBufContent()
586 xmlBufEnd(const xmlBufPtr buf) in xmlBufEnd() argument
588 if ((!buf) || (buf->error)) in xmlBufEnd()
590 CHECK_COMPAT(buf) in xmlBufEnd()
592 return(&buf->content[buf->use]); in xmlBufEnd()
607 xmlBufAddLen(xmlBufPtr buf, size_t len) { in xmlBufAddLen() argument
608 if ((buf == NULL) || (buf->error)) in xmlBufAddLen()
610 CHECK_COMPAT(buf) in xmlBufAddLen()
611 if (len > (buf->size - buf->use)) in xmlBufAddLen()
613 buf->use += len; in xmlBufAddLen()
614 UPDATE_COMPAT(buf) in xmlBufAddLen()
615 if (buf->size > buf->use) in xmlBufAddLen()
616 buf->content[buf->use] = 0; in xmlBufAddLen()
632 xmlBufErase(xmlBufPtr buf, size_t len) { in xmlBufErase() argument
633 if ((buf == NULL) || (buf->error)) in xmlBufErase()
635 CHECK_COMPAT(buf) in xmlBufErase()
636 if (len > buf->use) in xmlBufErase()
638 buf->use -= len; in xmlBufErase()
639 buf->content[buf->use] = 0; in xmlBufErase()
640 UPDATE_COMPAT(buf) in xmlBufErase()
654 xmlBufLength(const xmlBufPtr buf) in xmlBufLength() argument
656 if ((!buf) || (buf->error)) in xmlBufLength()
658 CHECK_COMPAT(buf) in xmlBufLength()
660 return(buf->use); in xmlBufLength()
673 xmlBufUse(const xmlBufPtr buf) in xmlBufUse() argument
675 if ((!buf) || (buf->error)) in xmlBufUse()
677 CHECK_COMPAT(buf) in xmlBufUse()
679 return(buf->use); in xmlBufUse()
694 xmlBufAvail(const xmlBufPtr buf) in xmlBufAvail() argument
696 if ((!buf) || (buf->error)) in xmlBufAvail()
698 CHECK_COMPAT(buf) in xmlBufAvail()
700 return(buf->size - buf->use); in xmlBufAvail()
712 xmlBufIsEmpty(const xmlBufPtr buf) in xmlBufIsEmpty() argument
714 if ((!buf) || (buf->error)) in xmlBufIsEmpty()
716 CHECK_COMPAT(buf) in xmlBufIsEmpty()
718 return(buf->use == 0); in xmlBufIsEmpty()
731 xmlBufResize(xmlBufPtr buf, size_t size) in xmlBufResize() argument
737 if ((buf == NULL) || (buf->error)) in xmlBufResize()
739 CHECK_COMPAT(buf) in xmlBufResize()
741 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); in xmlBufResize()
744 if (size < buf->size) in xmlBufResize()
748 switch (buf->alloc){ in xmlBufResize()
752 newSize = (buf->size ? buf->size*2 : size + 10); in xmlBufResize()
755 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
765 if (buf->use < BASE_BUFFER_SIZE) in xmlBufResize()
768 newSize = buf->size * 2; in xmlBufResize()
771 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
784 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufResize()
785 start_buf = buf->content - buf->contentIO; in xmlBufResize()
789 memmove(buf->contentIO, buf->content, buf->use); in xmlBufResize()
790 buf->content = buf->contentIO; in xmlBufResize()
791 buf->content[buf->use] = 0; in xmlBufResize()
792 buf->size += start_buf; in xmlBufResize()
794 rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize); in xmlBufResize()
796 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
799 buf->contentIO = rebuf; in xmlBufResize()
800 buf->content = rebuf + start_buf; in xmlBufResize()
803 if (buf->content == NULL) { in xmlBufResize()
805 } else if (buf->size - buf->use < 100) { in xmlBufResize()
806 rebuf = (xmlChar *) xmlRealloc(buf->content, newSize); in xmlBufResize()
815 memcpy(rebuf, buf->content, buf->use); in xmlBufResize()
816 xmlFree(buf->content); in xmlBufResize()
817 rebuf[buf->use] = 0; in xmlBufResize()
821 xmlBufMemoryError(buf, "growing buffer"); in xmlBufResize()
824 buf->content = rebuf; in xmlBufResize()
826 buf->size = newSize; in xmlBufResize()
827 UPDATE_COMPAT(buf) in xmlBufResize()
845 xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) { in xmlBufAdd() argument
848 if ((str == NULL) || (buf == NULL) || (buf->error)) in xmlBufAdd()
850 CHECK_COMPAT(buf) in xmlBufAdd()
852 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufAdd()
868 needSize = buf->use + len + 2; in xmlBufAdd()
869 if (needSize > buf->size){ in xmlBufAdd()
870 if (!xmlBufResize(buf, needSize)){ in xmlBufAdd()
871 xmlBufMemoryError(buf, "growing buffer"); in xmlBufAdd()
876 memmove(&buf->content[buf->use], str, len*sizeof(xmlChar)); in xmlBufAdd()
877 buf->use += len; in xmlBufAdd()
878 buf->content[buf->use] = 0; in xmlBufAdd()
879 UPDATE_COMPAT(buf) in xmlBufAdd()
896 xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) { in xmlBufAddHead() argument
899 if ((buf == NULL) || (buf->error)) in xmlBufAddHead()
901 CHECK_COMPAT(buf) in xmlBufAddHead()
902 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufAddHead()
924 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { in xmlBufAddHead()
925 size_t start_buf = buf->content - buf->contentIO; in xmlBufAddHead()
931 buf->content -= len; in xmlBufAddHead()
932 memmove(&buf->content[0], str, len); in xmlBufAddHead()
933 buf->use += len; in xmlBufAddHead()
934 buf->size += len; in xmlBufAddHead()
935 UPDATE_COMPAT(buf) in xmlBufAddHead()
939 needSize = buf->use + len + 2; in xmlBufAddHead()
940 if (needSize > buf->size){ in xmlBufAddHead()
941 if (!xmlBufResize(buf, needSize)){ in xmlBufAddHead()
942 xmlBufMemoryError(buf, "growing buffer"); in xmlBufAddHead()
947 memmove(&buf->content[len], &buf->content[0], buf->use); in xmlBufAddHead()
948 memmove(&buf->content[0], str, len); in xmlBufAddHead()
949 buf->use += len; in xmlBufAddHead()
950 buf->content[buf->use] = 0; in xmlBufAddHead()
951 UPDATE_COMPAT(buf) in xmlBufAddHead()
966 xmlBufCat(xmlBufPtr buf, const xmlChar *str) { in xmlBufCat() argument
967 if ((buf == NULL) || (buf->error)) in xmlBufCat()
969 CHECK_COMPAT(buf) in xmlBufCat()
970 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufCat()
972 return xmlBufAdd(buf, str, -1); in xmlBufCat()
986 xmlBufCCat(xmlBufPtr buf, const char *str) { in xmlBufCCat() argument
989 if ((buf == NULL) || (buf->error)) in xmlBufCCat()
991 CHECK_COMPAT(buf) in xmlBufCCat()
992 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; in xmlBufCCat()
1001 if (buf->use + 10 >= buf->size) { in xmlBufCCat()
1002 if (!xmlBufResize(buf, buf->use+10)){ in xmlBufCCat()
1003 xmlBufMemoryError(buf, "growing buffer"); in xmlBufCCat()
1007 buf->content[buf->use++] = *cur; in xmlBufCCat()
1009 buf->content[buf->use] = 0; in xmlBufCCat()
1010 UPDATE_COMPAT(buf) in xmlBufCCat()
1026 xmlBufWriteCHAR(xmlBufPtr buf, const xmlChar *string) { in xmlBufWriteCHAR() argument
1027 if ((buf == NULL) || (buf->error)) in xmlBufWriteCHAR()
1029 CHECK_COMPAT(buf) in xmlBufWriteCHAR()
1030 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteCHAR()
1032 return(xmlBufCat(buf, string)); in xmlBufWriteCHAR()
1047 xmlBufWriteChar(xmlBufPtr buf, const char *string) { in xmlBufWriteChar() argument
1048 if ((buf == NULL) || (buf->error)) in xmlBufWriteChar()
1050 CHECK_COMPAT(buf) in xmlBufWriteChar()
1051 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteChar()
1053 return(xmlBufCCat(buf, string)); in xmlBufWriteChar()
1070 xmlBufWriteQuotedString(xmlBufPtr buf, const xmlChar *string) { in xmlBufWriteQuotedString() argument
1072 if ((buf == NULL) || (buf->error)) in xmlBufWriteQuotedString()
1074 CHECK_COMPAT(buf) in xmlBufWriteQuotedString()
1075 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) in xmlBufWriteQuotedString()
1083 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1088 xmlBufAdd(buf, base, cur - base); in xmlBufWriteQuotedString()
1089 xmlBufAdd(buf, BAD_CAST """, 6); in xmlBufWriteQuotedString()
1098 xmlBufAdd(buf, base, cur - base); in xmlBufWriteQuotedString()
1099 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1102 xmlBufCCat(buf, "\'"); in xmlBufWriteQuotedString()
1103 xmlBufCat(buf, string); in xmlBufWriteQuotedString()
1104 xmlBufCCat(buf, "\'"); in xmlBufWriteQuotedString()
1107 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1108 xmlBufCat(buf, string); in xmlBufWriteQuotedString()
1109 xmlBufCCat(buf, "\""); in xmlBufWriteQuotedString()
1163 xmlBufBackToBuffer(xmlBufPtr buf) { in xmlBufBackToBuffer() argument
1166 if ((buf == NULL) || (buf->error)) in xmlBufBackToBuffer()
1168 CHECK_COMPAT(buf) in xmlBufBackToBuffer()
1169 if (buf->buffer == NULL) { in xmlBufBackToBuffer()
1170 xmlBufFree(buf); in xmlBufBackToBuffer()
1174 ret = buf->buffer; in xmlBufBackToBuffer()
1178 if (buf->use > INT_MAX) { in xmlBufBackToBuffer()
1184 xmlBufOverflowError(buf, "Used size too big for xmlBuffer"); in xmlBufBackToBuffer()
1187 } else if (buf->size > INT_MAX) { in xmlBufBackToBuffer()
1194 xmlBufOverflowError(buf, "Allocated size too big for xmlBuffer"); in xmlBufBackToBuffer()
1197 ret->use = (int) buf->use; in xmlBufBackToBuffer()
1198 ret->size = (int) buf->size; in xmlBufBackToBuffer()
1199 ret->alloc = buf->alloc; in xmlBufBackToBuffer()
1200 ret->content = buf->content; in xmlBufBackToBuffer()
1201 ret->contentIO = buf->contentIO; in xmlBufBackToBuffer()
1202 xmlFree(buf); in xmlBufBackToBuffer()
1216 xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer) { in xmlBufMergeBuffer() argument
1219 if ((buf == NULL) || (buf->error)) { in xmlBufMergeBuffer()
1223 CHECK_COMPAT(buf) in xmlBufMergeBuffer()
1226 ret = xmlBufAdd(buf, buffer->content, buffer->use); in xmlBufMergeBuffer()
1242 xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input) { in xmlBufResetInput() argument
1243 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufResetInput()
1245 CHECK_COMPAT(buf) in xmlBufResetInput()
1246 input->base = input->cur = buf->content; in xmlBufResetInput()
1247 input->end = &buf->content[buf->use]; in xmlBufResetInput()
1261 xmlBufGetInputBase(xmlBufPtr buf, xmlParserInputPtr input) { in xmlBufGetInputBase() argument
1264 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufGetInputBase()
1266 CHECK_COMPAT(buf) in xmlBufGetInputBase()
1267 base = input->base - buf->content; in xmlBufGetInputBase()
1272 if (base > buf->size) { in xmlBufGetInputBase()
1273 xmlBufOverflowError(buf, "Input reference outside of the buffer"); in xmlBufGetInputBase()
1292 xmlBufSetInputBaseCur(xmlBufPtr buf, xmlParserInputPtr input, in xmlBufSetInputBaseCur() argument
1294 if ((input == NULL) || (buf == NULL) || (buf->error)) in xmlBufSetInputBaseCur()
1296 CHECK_COMPAT(buf) in xmlBufSetInputBaseCur()
1297 input->base = &buf->content[base]; in xmlBufSetInputBaseCur()
1299 input->end = &buf->content[buf->use]; in xmlBufSetInputBaseCur()