ReactOS 0.4.16-dev-2208-g6350669
buf.h File Reference
#include <libxml/tree.h>
Include dependency graph for buf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

XML_HIDDEN xmlBufPtr xmlBufCreate (void)
 
XML_HIDDEN xmlBufPtr xmlBufCreateSize (size_t size)
 
XML_HIDDEN int xmlBufSetAllocationScheme (xmlBufPtr buf, xmlBufferAllocationScheme scheme)
 
XML_HIDDEN int xmlBufGetAllocationScheme (xmlBufPtr buf)
 
XML_HIDDEN void xmlBufFree (xmlBufPtr buf)
 
XML_HIDDEN void xmlBufEmpty (xmlBufPtr buf)
 
XML_HIDDEN int xmlBufGrow (xmlBufPtr buf, int len)
 
XML_HIDDEN int xmlBufResize (xmlBufPtr buf, size_t len)
 
XML_HIDDEN int xmlBufAdd (xmlBufPtr buf, const xmlChar *str, int len)
 
XML_HIDDEN int xmlBufCat (xmlBufPtr buf, const xmlChar *str)
 
XML_HIDDEN int xmlBufCCat (xmlBufPtr buf, const char *str)
 
XML_HIDDEN int xmlBufWriteQuotedString (xmlBufPtr buf, const xmlChar *string)
 
XML_HIDDEN size_t xmlBufAvail (const xmlBufPtr buf)
 
XML_HIDDEN size_t xmlBufLength (const xmlBufPtr buf)
 
XML_HIDDEN int xmlBufIsEmpty (const xmlBufPtr buf)
 
XML_HIDDEN int xmlBufAddLen (xmlBufPtr buf, size_t len)
 
XML_HIDDEN xmlCharxmlBufDetach (xmlBufPtr buf)
 
XML_HIDDEN size_t xmlBufDump (FILE *file, xmlBufPtr buf)
 
XML_HIDDEN xmlBufPtr xmlBufFromBuffer (xmlBufferPtr buffer)
 
XML_HIDDEN xmlBufferPtr xmlBufBackToBuffer (xmlBufPtr buf)
 
XML_HIDDEN int xmlBufMergeBuffer (xmlBufPtr buf, xmlBufferPtr buffer)
 
XML_HIDDEN int xmlBufResetInput (xmlBufPtr buf, xmlParserInputPtr input)
 
XML_HIDDEN int xmlBufUpdateInput (xmlBufPtr buf, xmlParserInputPtr input, size_t pos)
 

Function Documentation

◆ xmlBufAdd()

XML_HIDDEN int xmlBufAdd ( xmlBufPtr  buf,
const xmlChar str,
int  len 
)

xmlBufAdd: @buf: the buffer to dump @str: the xmlChar string @len: the number of xmlChar to add

Add a string range to an XML buffer. if len == -1, the length of str is recomputed.

Returns 0 successful, a positive error code number otherwise and -1 in case of internal or API error.

Definition at line 758 of file buf.c.

758 {
759 size_t needSize;
760
761 if ((str == NULL) || (buf == NULL) || (buf->error))
762 return -1;
764
765 if (len < -1) {
766 return -1;
767 }
768 if (len == 0) return 0;
769
770 if (len < 0)
771 len = xmlStrlen(str);
772
773 if (len < 0) return -1;
774 if (len == 0) return 0;
775
776 /* Note that both buf->size and buf->use can be zero here. */
777 if ((size_t) len >= buf->size - buf->use) {
778 if ((size_t) len >= SIZE_MAX - buf->use) {
779 xmlBufMemoryError(buf, "growing buffer past SIZE_MAX");
780 return(-1);
781 }
782 needSize = buf->use + len + 1;
783 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {
784 /*
785 * Used to provide parsing limits
786 */
787 if (needSize >= XML_MAX_TEXT_LENGTH) {
788 xmlBufMemoryError(buf, "buffer error: text too long\n");
789 return(-1);
790 }
791 }
792 if (!xmlBufResize(buf, needSize)){
793 xmlBufMemoryError(buf, "growing buffer");
794 return XML_ERR_NO_MEMORY;
795 }
796 }
797
798 memmove(&buf->content[buf->use], str, len);
799 buf->use += len;
800 buf->content[buf->use] = 0;
802 return 0;
803}
int xmlBufResize(xmlBufPtr buf, size_t size)
Definition: buf.c:629
#define SIZE_MAX
Definition: buf.c:30
#define UPDATE_COMPAT(buf)
Definition: buf.c:60
#define CHECK_COMPAT(buf)
Definition: buf.c:71
static void xmlBufMemoryError(xmlBufPtr buf, const char *extra)
Definition: buf.c:92
#define NULL
Definition: types.h:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define XML_MAX_TEXT_LENGTH
const WCHAR * str
@ XML_ERR_NO_MEMORY
Definition: xmlerror.h:102
XMLPUBFUN int xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:428

Referenced by xmlBufCat(), xmlBufMergeBuffer(), and xmlBufWriteQuotedString().

◆ xmlBufAddLen()

XML_HIDDEN int xmlBufAddLen ( xmlBufPtr  buf,
size_t  len 
)

xmlBufAddLen: @buf: the buffer @len: the size which were added at the end

Sometime data may be added at the end of the buffer without using the xmlBuf APIs that is used to expand the used space and set the zero terminating at the end of the buffer

Returns -1 in case of error and 0 otherwise

Definition at line 529 of file buf.c.

529 {
530 if ((buf == NULL) || (buf->error))
531 return(-1);
533 if (len >= (buf->size - buf->use))
534 return(-1);
535 buf->use += len;
536 buf->content[buf->use] = 0;
538 return(0);
539}

◆ xmlBufAvail()

XML_HIDDEN size_t xmlBufAvail ( const xmlBufPtr  buf)

xmlBufAvail: @buf: the buffer

Function to find how much free space is allocated but not used in the buffer. It reserves one byte for the NUL terminator character that is usually needed, so there is no need to subtract 1 from the result anymore.

Returns the amount, or 0 if none or if an error occurred.

Definition at line 592 of file buf.c.

593{
594 if ((!buf) || (buf->error))
595 return 0;
597
598 return((buf->size > buf->use) ? (buf->size - buf->use - 1) : 0);
599}

◆ xmlBufBackToBuffer()

XML_HIDDEN xmlBufferPtr xmlBufBackToBuffer ( xmlBufPtr  buf)

xmlBufBackToBuffer: @buf: new buffer wrapping the old one

Function to be called once internal processing had been done to update back the buffer provided by the user. This can lead to a failure in case the size accumulated in the xmlBuf is larger than what an xmlBuffer can support on 64 bits (INT_MAX) The xmlBufPtr @buf wrapper is deallocated by this call in any case.

Returns the old xmlBufferPtr unless the call failed and NULL is returned

Definition at line 938 of file buf.c.

938 {
939 xmlBufferPtr ret;
940
941 if (buf == NULL)
942 return(NULL);
944 if ((buf->error) || (buf->buffer == NULL)) {
946 return(NULL);
947 }
948
949 ret = buf->buffer;
950 /*
951 * What to do in case of error in the buffer ???
952 */
953 if (buf->use > INT_MAX) {
954 /*
955 * Worse case, we really allocated and used more than the
956 * maximum allowed memory for an xmlBuffer on this architecture.
957 * Keep the buffer but provide a truncated size value.
958 */
959 xmlBufOverflowError(buf, "Used size too big for xmlBuffer");
960 ret->use = INT_MAX;
961 ret->size = INT_MAX;
962 } else if (buf->size > INT_MAX) {
963 /*
964 * milder case, we allocated more than the maximum allowed memory
965 * for an xmlBuffer on this architecture, but used less than the
966 * limit.
967 * Keep the buffer but provide a truncated size value.
968 */
969 xmlBufOverflowError(buf, "Allocated size too big for xmlBuffer");
970 ret->use = buf->use;
971 ret->size = INT_MAX;
972 } else {
973 ret->use = buf->use;
974 ret->size = buf->size;
975 }
976 ret->alloc = buf->alloc;
977 ret->content = buf->content;
978 ret->contentIO = buf->contentIO;
979 xmlFree(buf);
980 return(ret);
981}
static void xmlBufOverflowError(xmlBufPtr buf, const char *extra)
Definition: buf.c:107
void xmlBufFree(xmlBufPtr buf)
Definition: buf.c:276
#define INT_MAX
Definition: limits.h:26
return ret
Definition: mutex.c:146
xmlFreeFunc xmlFree
Definition: globals.c:184

◆ xmlBufCat()

XML_HIDDEN int xmlBufCat ( xmlBufPtr  buf,
const xmlChar str 
)

xmlBufCat: @buf: the buffer to add to @str: the xmlChar string

Append a zero terminated string to an XML buffer.

Returns 0 successful, a positive error code number otherwise and -1 in case of internal or API error.

Definition at line 816 of file buf.c.

816 {
817 if ((buf == NULL) || (buf->error))
818 return(-1);
820 if (str == NULL) return -1;
821 return xmlBufAdd(buf, str, -1);
822}
int xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len)
Definition: buf.c:758

Referenced by xmlBufCCat(), and xmlBufWriteQuotedString().

◆ xmlBufCCat()

XML_HIDDEN int xmlBufCCat ( xmlBufPtr  buf,
const char str 
)

xmlBufCCat: @buf: the buffer to dump @str: the C char string

Append a zero terminated C string to an XML buffer.

Returns 0 successful, a positive error code number otherwise and -1 in case of internal or API error.

Definition at line 835 of file buf.c.

835 {
836 return xmlBufCat(buf, (const xmlChar *) str);
837}
int xmlBufCat(xmlBufPtr buf, const xmlChar *str)
Definition: buf.c:816
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlBufWriteQuotedString().

◆ xmlBufCreate()

XML_HIDDEN xmlBufPtr xmlBufCreate ( void  )

xmlBufCreate:

routine to create an XML buffer. returns the new structure.

Definition at line 122 of file buf.c.

122 {
123 xmlBufPtr ret;
124
125 ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf));
126 if (ret == NULL) {
127 xmlBufMemoryError(NULL, "creating buffer");
128 return(NULL);
129 }
130 ret->use = 0;
131 ret->error = 0;
132 ret->buffer = NULL;
135 ret->alloc = xmlBufferAllocScheme;
136 ret->content = (xmlChar *) xmlMallocAtomic(ret->size);
137 if (ret->content == NULL) {
138 xmlBufMemoryError(ret, "creating buffer");
139 xmlFree(ret);
140 return(NULL);
141 }
142 ret->content[0] = 0;
143 ret->contentIO = NULL;
144 return(ret);
145}
xmlMallocFunc xmlMalloc
Definition: globals.c:193
int xmlDefaultBufferSize
Definition: globals.c:255
xmlMallocFunc xmlMallocAtomic
Definition: globals.c:204
xmlBufferAllocationScheme xmlBufferAllocScheme
Definition: globals.c:246

Referenced by xmlSwitchInputEncoding().

◆ xmlBufCreateSize()

XML_HIDDEN xmlBufPtr xmlBufCreateSize ( size_t  size)

xmlBufCreateSize: @size: initial size of buffer

routine to create an XML buffer. returns the new structure.

Definition at line 155 of file buf.c.

155 {
156 xmlBufPtr ret;
157
158 if (size == SIZE_MAX)
159 return(NULL);
160 ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf));
161 if (ret == NULL) {
162 xmlBufMemoryError(NULL, "creating buffer");
163 return(NULL);
164 }
165 ret->use = 0;
166 ret->error = 0;
167 ret->buffer = NULL;
168 ret->alloc = xmlBufferAllocScheme;
169 ret->size = (size ? size + 1 : 0); /* +1 for ending null */
171 if (ret->size){
172 ret->content = (xmlChar *) xmlMallocAtomic(ret->size);
173 if (ret->content == NULL) {
174 xmlBufMemoryError(ret, "creating buffer");
175 xmlFree(ret);
176 return(NULL);
177 }
178 ret->content[0] = 0;
179 } else
180 ret->content = NULL;
181 ret->contentIO = NULL;
182 return(ret);
183}
GLsizeiptr size
Definition: glext.h:5919

◆ xmlBufDetach()

XML_HIDDEN xmlChar * xmlBufDetach ( xmlBufPtr  buf)

xmlBufDetach: @buf: the buffer

Remove the string contained in a buffer and give it back to the caller. The buffer is reset to an empty content. This doesn't work with immutable buffers as they can't be reset.

Returns the previous string contained by the buffer.

Definition at line 196 of file buf.c.

196 {
197 xmlChar *ret;
198
199 if (buf == NULL)
200 return(NULL);
201 if (buf->buffer != NULL)
202 return(NULL);
203 if (buf->error)
204 return(NULL);
205
206 ret = buf->content;
207 buf->content = NULL;
208 buf->size = 0;
209 buf->use = 0;
211
212 return ret;
213}

Referenced by xmlLoadEntityContent().

◆ xmlBufDump()

XML_HIDDEN size_t xmlBufDump ( FILE file,
xmlBufPtr  buf 
)

Definition at line 464 of file buf.c.

464 {
465 size_t ret;
466
467 if ((buf == NULL) || (buf->error != 0)) {
468 return(0);
469 }
470 if (buf->content == NULL) {
471 return(0);
472 }
474 if (file == NULL)
475 file = stdout;
476 ret = fwrite(buf->content, 1, buf->use, file);
477 return(ret);
478}
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
Definition: file.c:4129
#define stdout
Definition: fci.c:127

◆ xmlBufEmpty()

XML_HIDDEN void xmlBufEmpty ( xmlBufPtr  buf)

xmlBufEmpty: @buf: the buffer

empty a buffer.

Definition at line 297 of file buf.c.

297 {
298 if ((buf == NULL) || (buf->error != 0)) return;
299 if (buf->content == NULL) return;
301 buf->use = 0;
302 if ((buf->alloc == XML_BUFFER_ALLOC_IO) &&
303 (buf->contentIO != NULL)) {
304 size_t start_buf = buf->content - buf->contentIO;
305
306 buf->size += start_buf;
307 buf->content = buf->contentIO;
308 buf->content[0] = 0;
309 } else {
310 buf->content[0] = 0;
311 }
313}

◆ xmlBufFree()

XML_HIDDEN void xmlBufFree ( xmlBufPtr  buf)

xmlBufFree: @buf: the buffer to free

Frees an XML buffer. It frees both the content and the structure which encapsulate it.

Definition at line 276 of file buf.c.

276 {
277 if (buf == NULL) {
278 return;
279 }
280
281 if ((buf->alloc == XML_BUFFER_ALLOC_IO) &&
282 (buf->contentIO != NULL)) {
283 xmlFree(buf->contentIO);
284 } else if (buf->content != NULL) {
285 xmlFree(buf->content);
286 }
287 xmlFree(buf);
288}

Referenced by xmlBufBackToBuffer().

◆ xmlBufFromBuffer()

XML_HIDDEN xmlBufPtr xmlBufFromBuffer ( xmlBufferPtr  buffer)

xmlBufFromBuffer: @buffer: incoming old buffer to convert to a new one

Helper routine to switch from the old buffer structures in use in various APIs. It creates a wrapper xmlBufPtr which will be used for internal processing until the xmlBufBackToBuffer() is issued.

Returns a new xmlBufPtr unless the call failed and NULL is returned

Definition at line 902 of file buf.c.

902 {
903 xmlBufPtr ret;
904
905 if (buffer == NULL)
906 return(NULL);
907
908 ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf));
909 if (ret == NULL) {
910 xmlBufMemoryError(NULL, "creating buffer");
911 return(NULL);
912 }
913 ret->use = buffer->use;
914 ret->size = buffer->size;
916 ret->error = 0;
917 ret->buffer = buffer;
918 ret->alloc = buffer->alloc;
919 ret->content = buffer->content;
920 ret->contentIO = buffer->contentIO;
921
922 return(ret);
923}
GLuint buffer
Definition: glext.h:5915

◆ xmlBufGetAllocationScheme()

XML_HIDDEN int xmlBufGetAllocationScheme ( xmlBufPtr  buf)

xmlBufGetAllocationScheme: @buf: the buffer

Get the buffer allocation scheme

Returns the scheme or -1 in case of error

Definition at line 224 of file buf.c.

224 {
225 if (buf == NULL) {
226 return(-1);
227 }
228 return(buf->alloc);
229}

◆ xmlBufGrow()

XML_HIDDEN int xmlBufGrow ( xmlBufPtr  buf,
int  len 
)

xmlBufGrow: @buf: the buffer @len: the minimum free size to allocate

Grow the available space of an XML buffer, @len is the target value This is been kept compatible with xmlBufferGrow() as much as possible

Returns -1 in case of error or the length made available otherwise

Definition at line 443 of file buf.c.

443 {
444 size_t ret;
445
446 if ((buf == NULL) || (len < 0)) return(-1);
447 if (len == 0)
448 return(0);
450 if (buf->error != 0)
451 return(-1);
452 return(ret > INT_MAX ? INT_MAX : ret);
453}
static size_t xmlBufGrowInternal(xmlBufPtr buf, size_t len)
Definition: buf.c:376

◆ xmlBufIsEmpty()

XML_HIDDEN int xmlBufIsEmpty ( const xmlBufPtr  buf)

xmlBufIsEmpty: @buf: the buffer

Tell if a buffer is empty

Returns 0 if no, 1 if yes and -1 in case of error

Definition at line 610 of file buf.c.

611{
612 if ((!buf) || (buf->error))
613 return(-1);
615
616 return(buf->use == 0);
617}

Referenced by xmlParseDocument(), and xmlSwitchInputEncoding().

◆ xmlBufLength()

XML_HIDDEN size_t xmlBufLength ( const xmlBufPtr  buf)

xmlBufLength: @buf: the buffer

Function to get the length of a buffer

Returns the length of data in the internal content

Definition at line 551 of file buf.c.

552{
553 if ((!buf) || (buf->error))
554 return 0;
556
557 return(buf->use);
558}

◆ xmlBufMergeBuffer()

XML_HIDDEN int xmlBufMergeBuffer ( xmlBufPtr  buf,
xmlBufferPtr  buffer 
)

xmlBufMergeBuffer: @buf: an xmlBufPtr @buffer: the buffer to consume into @buf

The content of @buffer is appended to @buf and @buffer is freed

Returns -1 in case of error, 0 otherwise, in any case @buffer is freed

Definition at line 993 of file buf.c.

993 {
994 int ret = 0;
995
996 if ((buf == NULL) || (buf->error)) {
997 xmlBufferFree(buffer);
998 return(-1);
999 }
1001 if ((buffer != NULL) && (buffer->content != NULL) &&
1002 (buffer->use > 0)) {
1003 ret = xmlBufAdd(buf, buffer->content, buffer->use);
1004 }
1005 xmlBufferFree(buffer);
1006 return(ret);
1007}

◆ xmlBufResetInput()

XML_HIDDEN int xmlBufResetInput ( xmlBufPtr  buf,
xmlParserInputPtr  input 
)

xmlBufResetInput: @buf: an xmlBufPtr @input: an xmlParserInputPtr

Update the input to use the current set of pointers from the buffer.

Returns -1 in case of error, 0 otherwise

Definition at line 1019 of file buf.c.

1019 {
1020 if (input == NULL)
1021 return(-1);
1022 if ((buf == NULL) || (buf->error)) {
1023 input->base = input->cur = input->end = BAD_CAST "";
1024 return(-1);
1025 }
1027 input->base = input->cur = buf->content;
1028 input->end = &buf->content[buf->use];
1029 return(0);
1030}
GLenum GLenum GLenum input
Definition: glext.h:9031
#define BAD_CAST
Definition: xmlstring.h:35

Referenced by xmlCreateDocParserCtxt(), xmlCreateMemoryParserCtxt(), xmlCtxtResetPush(), xmlLoadEntityContent(), xmlNewInputFromFile(), xmlNewIOInputStream(), xmlNewStringInputStream(), and xmlSwitchInputEncoding().

◆ xmlBufResize()

XML_HIDDEN int xmlBufResize ( xmlBufPtr  buf,
size_t  size 
)

xmlBufResize: @buf: the buffer to resize @size: the desired size

Resize a buffer to accommodate minimum size of @size.

Returns 0 in case of problems, 1 otherwise

Definition at line 629 of file buf.c.

630{
631 size_t newSize;
632 xmlChar* rebuf = NULL;
633 size_t start_buf;
634
635 if ((buf == NULL) || (buf->error))
636 return(0);
638
639 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {
640 /*
641 * Used to provide parsing limits
642 */
643 if (size >= XML_MAX_TEXT_LENGTH) {
644 xmlBufMemoryError(buf, "buffer error: text too long\n");
645 return(0);
646 }
647 }
648
649 /* Don't resize if we don't have to */
650 if (size < buf->size)
651 return 1;
652
653 /* figure out new size */
654 switch (buf->alloc){
655 case XML_BUFFER_ALLOC_IO:
656 case XML_BUFFER_ALLOC_DOUBLEIT:
657 /*take care of empty case*/
658 if (buf->size == 0) {
659 newSize = (size > SIZE_MAX - 10 ? SIZE_MAX : size + 10);
660 } else {
661 newSize = buf->size;
662 }
663 while (size > newSize) {
664 if (newSize > SIZE_MAX / 2) {
665 xmlBufMemoryError(buf, "growing buffer");
666 return 0;
667 }
668 newSize *= 2;
669 }
670 break;
671 case XML_BUFFER_ALLOC_EXACT:
672 newSize = (size > SIZE_MAX - 10 ? SIZE_MAX : size + 10);
673 break;
674 case XML_BUFFER_ALLOC_HYBRID:
675 if (buf->use < BASE_BUFFER_SIZE)
676 newSize = size;
677 else {
678 newSize = buf->size;
679 while (size > newSize) {
680 if (newSize > SIZE_MAX / 2) {
681 xmlBufMemoryError(buf, "growing buffer");
682 return 0;
683 }
684 newSize *= 2;
685 }
686 }
687 break;
688
689 default:
690 newSize = (size > SIZE_MAX - 10 ? SIZE_MAX : size + 10);
691 break;
692 }
693
694 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {
695 start_buf = buf->content - buf->contentIO;
696
697 if (start_buf > newSize) {
698 /* move data back to start */
699 memmove(buf->contentIO, buf->content, buf->use);
700 buf->content = buf->contentIO;
701 buf->content[buf->use] = 0;
702 buf->size += start_buf;
703 } else {
704 rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize);
705 if (rebuf == NULL) {
706 xmlBufMemoryError(buf, "growing buffer");
707 return 0;
708 }
709 buf->contentIO = rebuf;
710 buf->content = rebuf + start_buf;
711 }
712 } else {
713 if (buf->content == NULL) {
714 rebuf = (xmlChar *) xmlMallocAtomic(newSize);
715 buf->use = 0;
716 if (rebuf != NULL)
717 rebuf[buf->use] = 0;
718 } else if (buf->size - buf->use < 100) {
719 rebuf = (xmlChar *) xmlRealloc(buf->content, newSize);
720 } else {
721 /*
722 * if we are reallocating a buffer far from being full, it's
723 * better to make a new allocation and copy only the used range
724 * and free the old one.
725 */
726 rebuf = (xmlChar *) xmlMallocAtomic(newSize);
727 if (rebuf != NULL) {
728 memcpy(rebuf, buf->content, buf->use);
729 xmlFree(buf->content);
730 rebuf[buf->use] = 0;
731 }
732 }
733 if (rebuf == NULL) {
734 xmlBufMemoryError(buf, "growing buffer");
735 return 0;
736 }
737 buf->content = rebuf;
738 }
739 buf->size = newSize;
741
742 return 1;
743}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
xmlReallocFunc xmlRealloc
Definition: globals.c:214

Referenced by xmlBufAdd().

◆ xmlBufSetAllocationScheme()

XML_HIDDEN int xmlBufSetAllocationScheme ( xmlBufPtr  buf,
xmlBufferAllocationScheme  scheme 
)

xmlBufSetAllocationScheme: @buf: the buffer to tune @scheme: allocation scheme to use

Sets the allocation scheme for this buffer

returns 0 in case of success and -1 in case of failure

Definition at line 241 of file buf.c.

242 {
243 if ((buf == NULL) || (buf->error != 0)) {
244 return(-1);
245 }
246 if (buf->alloc == XML_BUFFER_ALLOC_IO)
247 return(-1);
248 if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) ||
249 (scheme == XML_BUFFER_ALLOC_EXACT) ||
250 (scheme == XML_BUFFER_ALLOC_HYBRID) ||
251 (scheme == XML_BUFFER_ALLOC_BOUNDED)) {
252 buf->alloc = scheme;
253 if (buf->buffer)
254 buf->buffer->alloc = scheme;
255 return(0);
256 }
257 /*
258 * Switching a buffer ALLOC_IO has the side effect of initializing
259 * the contentIO field with the current content
260 */
261 if (scheme == XML_BUFFER_ALLOC_IO) {
262 buf->alloc = XML_BUFFER_ALLOC_IO;
263 buf->contentIO = buf->content;
264 }
265 return(-1);
266}
DWORD scheme

◆ xmlBufUpdateInput()

XML_HIDDEN int xmlBufUpdateInput ( xmlBufPtr  buf,
xmlParserInputPtr  input,
size_t  pos 
)

xmlBufUpdateInput: @buf: an xmlBufPtr @input: an xmlParserInputPtr @pos: the cur value relative to the beginning of the buffer

Update the input to use the base and cur relative to the buffer after a possible reallocation of its content

Returns -1 in case of error, 0 otherwise

Definition at line 1044 of file buf.c.

1044 {
1045 if (input == NULL)
1046 return(-1);
1047 /*
1048 * TODO: It might be safer to keep using the buffer content if there
1049 * was an error.
1050 */
1051 if ((buf == NULL) || (buf->error)) {
1052 input->base = input->cur = input->end = BAD_CAST "";
1053 return(-1);
1054 }
1056 input->base = buf->content;
1057 input->cur = input->base + pos;
1058 input->end = &buf->content[buf->use];
1059 return(0);
1060}

Referenced by xmlCtxtResetPush(), xmlParserGrow(), and xmlParserShrink().

◆ xmlBufWriteQuotedString()

XML_HIDDEN int xmlBufWriteQuotedString ( xmlBufPtr  buf,
const xmlChar string 
)

xmlBufWriteQuotedString: @buf: the XML buffer output @string: the string to add

routine which manage and grows an output buffer. This one writes a quoted or double quoted xmlChar string, checking first if it holds quote or double-quotes internally

Returns 0 if successful, a positive error code number otherwise and -1 in case of internal or API error.

Definition at line 852 of file buf.c.

852 {
853 const xmlChar *cur, *base;
854 if ((buf == NULL) || (buf->error))
855 return(-1);
857 if (xmlStrchr(string, '\"')) {
858 if (xmlStrchr(string, '\'')) {
859 xmlBufCCat(buf, "\"");
860 base = cur = string;
861 while(*cur != 0){
862 if(*cur == '"'){
863 if (base != cur)
865 xmlBufAdd(buf, BAD_CAST "&quot;", 6);
866 cur++;
867 base = cur;
868 }
869 else {
870 cur++;
871 }
872 }
873 if (base != cur)
875 xmlBufCCat(buf, "\"");
876 }
877 else{
878 xmlBufCCat(buf, "\'");
879 xmlBufCat(buf, string);
880 xmlBufCCat(buf, "\'");
881 }
882 } else {
883 xmlBufCCat(buf, "\"");
884 xmlBufCat(buf, string);
885 xmlBufCCat(buf, "\"");
886 }
887 return(0);
888}
int xmlBufCCat(xmlBufPtr buf, const char *str)
Definition: buf.c:835
FxCollectionEntry * cur
char string[160]
Definition: util.h:11
XMLPUBFUN const xmlChar * xmlStrchr(const xmlChar *str, xmlChar val)
Definition: xmlstring.c:327