MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlBufferAddHead

Function xmlBufferAddHead

ThirdParty/libxml2/vtklibxml2/tree.c:7581–7629  ·  view source on GitHub ↗

* xmlBufferAddHead: * @buf: the buffer * @str: the #xmlChar string * @len: the number of #xmlChar to add * * Add a string range to the beginning of 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. */

Source from the content-addressed store, hash-verified

7579 * and -1 in case of internal or API error.
7580 */
7581int
7582xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) {
7583 unsigned int needSize;
7584
7585 if (buf == NULL)
7586 return(-1);
7587 if (str == NULL) {
7588 return -1;
7589 }
7590 if (len < -1) {
7591 return -1;
7592 }
7593 if (len == 0) return 0;
7594
7595 if (len < 0)
7596 len = xmlStrlen(str);
7597
7598 if (len <= 0) return -1;
7599
7600 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {
7601 size_t start_buf = buf->content - buf->contentIO;
7602
7603 if (start_buf > (unsigned int) len) {
7604 /*
7605 * We can add it in the space previously shrunk
7606 */
7607 buf->content -= len;
7608 memmove(&buf->content[0], str, len);
7609 buf->use += len;
7610 buf->size += len;
7611 buf->content[buf->use] = 0;
7612 return(0);
7613 }
7614 }
7615 /* Note that both buf->size and buf->use can be zero here. */
7616 if ((unsigned) len >= buf->size - buf->use) {
7617 if ((unsigned) len >= UINT_MAX - buf->use)
7618 return(-1);
7619 needSize = buf->use + len + 1;
7620 if (!xmlBufferResize(buf, needSize))
7621 return(-1);
7622 }
7623
7624 memmove(&buf->content[len], &buf->content[0], buf->use);
7625 memmove(&buf->content[0], str, len);
7626 buf->use += len;
7627 buf->content[buf->use] = 0;
7628 return 0;
7629}
7630
7631/**
7632 * xmlBufferCat:

Callers

nothing calls this directly

Calls 2

xmlStrlenFunction · 0.85
xmlBufferResizeFunction · 0.85

Tested by

no test coverage detected