mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
- encoding.c xmlIO.c: Fixing the problem reported by Marc Sanfacon
Daniel
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Thu Jan 4 11:46:40 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||||
|
|
||||||
|
* encoding.c xmlIO.c: Fixing the problem reported by Marc Sanfacon
|
||||||
|
on large files
|
||||||
|
|
||||||
Wed Jan 3 21:51:13 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
Wed Jan 3 21:51:13 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
|
||||||
|
|
||||||
* xmlIO.c: fixed xmlParserInputBufferCreateMem doc
|
* xmlIO.c: fixed xmlParserInputBufferCreateMem doc
|
||||||
|
17
encoding.c
17
encoding.c
@ -1812,7 +1812,7 @@ xmlCharEncInFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
|||||||
return(0);
|
return(0);
|
||||||
written = out->size - out->use;
|
written = out->size - out->use;
|
||||||
if (toconv * 2 >= written) {
|
if (toconv * 2 >= written) {
|
||||||
xmlBufferGrow(out, toconv * 2);
|
xmlBufferGrow(out, out->size + toconv * 2);
|
||||||
written = out->size - out->use - 1;
|
written = out->size - out->use - 1;
|
||||||
}
|
}
|
||||||
if (handler->input != NULL) {
|
if (handler->input != NULL) {
|
||||||
@ -1886,6 +1886,7 @@ xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out,
|
|||||||
xmlBufferPtr in) {
|
xmlBufferPtr in) {
|
||||||
int ret = -2;
|
int ret = -2;
|
||||||
int written;
|
int written;
|
||||||
|
int writtentot = 0;
|
||||||
int toconv;
|
int toconv;
|
||||||
int output = 0;
|
int output = 0;
|
||||||
|
|
||||||
@ -1937,6 +1938,7 @@ retry:
|
|||||||
in->content, &toconv);
|
in->content, &toconv);
|
||||||
xmlBufferShrink(in, toconv);
|
xmlBufferShrink(in, toconv);
|
||||||
out->use += written;
|
out->use += written;
|
||||||
|
writtentot += written;
|
||||||
out->content[out->use] = 0;
|
out->content[out->use] = 0;
|
||||||
}
|
}
|
||||||
#ifdef LIBXML_ICONV_ENABLED
|
#ifdef LIBXML_ICONV_ENABLED
|
||||||
@ -1945,8 +1947,17 @@ retry:
|
|||||||
&written, in->content, &toconv);
|
&written, in->content, &toconv);
|
||||||
xmlBufferShrink(in, toconv);
|
xmlBufferShrink(in, toconv);
|
||||||
out->use += written;
|
out->use += written;
|
||||||
|
writtentot += written;
|
||||||
out->content[out->use] = 0;
|
out->content[out->use] = 0;
|
||||||
if (ret == -1) ret = -3;
|
if (ret == -1) {
|
||||||
|
if (written > 0) {
|
||||||
|
/*
|
||||||
|
* Can be a limitation of iconv
|
||||||
|
*/
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
ret = -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* LIBXML_ICONV_ENABLED */
|
#endif /* LIBXML_ICONV_ENABLED */
|
||||||
else {
|
else {
|
||||||
@ -1971,11 +1982,11 @@ retry:
|
|||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"output conversion failed by lack of space\n");
|
"output conversion failed by lack of space\n");
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case -3:
|
case -3:
|
||||||
xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of output %d left\n",
|
xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of output %d left\n",
|
||||||
toconv, written, in->use);
|
toconv, written, in->use);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case -2: {
|
case -2: {
|
||||||
int len = in->use;
|
int len = in->use;
|
||||||
const xmlChar *utf = (const xmlChar *) in->content;
|
const xmlChar *utf = (const xmlChar *) in->content;
|
||||||
|
117
xmlIO.c
117
xmlIO.c
@ -1377,71 +1377,84 @@ xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *buf) {
|
xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *buf) {
|
||||||
int nbchars = 0, ret;
|
int nbchars = 0; /* number of chars to output to I/O */
|
||||||
|
int ret; /* return from function call */
|
||||||
|
int written = 0; /* number of char written to I/O so far */
|
||||||
|
int chunk; /* number of byte curreent processed from buf */
|
||||||
|
|
||||||
if (len < 0) return(0);
|
if (len < 0) return(0);
|
||||||
|
|
||||||
/*
|
do {
|
||||||
* first handle encoding stuff.
|
chunk = len;
|
||||||
*/
|
if (chunk > 4 * MINLEN)
|
||||||
if (out->encoder != NULL) {
|
chunk = 4 * MINLEN;
|
||||||
/*
|
|
||||||
* Store the data in the incoming raw buffer
|
|
||||||
*/
|
|
||||||
if (out->conv == NULL) {
|
|
||||||
out->conv = xmlBufferCreate();
|
|
||||||
}
|
|
||||||
xmlBufferAdd(out->buffer, (const xmlChar *) buf, len);
|
|
||||||
|
|
||||||
if (out->buffer->use < MINLEN)
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* convert as much as possible to the parser reading buffer.
|
* first handle encoding stuff.
|
||||||
*/
|
*/
|
||||||
nbchars = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer);
|
if (out->encoder != NULL) {
|
||||||
if (nbchars < 0) {
|
/*
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
* Store the data in the incoming raw buffer
|
||||||
"xmlOutputBufferWrite: encoder error\n");
|
*/
|
||||||
return(-1);
|
if (out->conv == NULL) {
|
||||||
|
out->conv = xmlBufferCreate();
|
||||||
|
}
|
||||||
|
xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk);
|
||||||
|
|
||||||
|
if ((out->buffer->use < MINLEN) && (chunk == len))
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* convert as much as possible to the parser reading buffer.
|
||||||
|
*/
|
||||||
|
ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer);
|
||||||
|
if (ret < 0) {
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"xmlOutputBufferWrite: encoder error\n");
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
nbchars = out->conv->use;
|
||||||
|
} else {
|
||||||
|
xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk);
|
||||||
|
nbchars = out->buffer->use;
|
||||||
}
|
}
|
||||||
nbchars = out->conv->use;
|
buf += chunk;
|
||||||
} else {
|
len -= chunk;
|
||||||
xmlBufferAdd(out->buffer, (const xmlChar *) buf, len);
|
|
||||||
nbchars = out->buffer->use;
|
|
||||||
}
|
|
||||||
if (nbchars < MINLEN)
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
if (!out->writecallback)
|
if ((nbchars < MINLEN) && (len <= 0))
|
||||||
return(nbchars);
|
goto done;
|
||||||
|
|
||||||
/*
|
if (out->writecallback) {
|
||||||
* second write the stuff to the I/O channel
|
/*
|
||||||
*/
|
* second write the stuff to the I/O channel
|
||||||
if (out->encoder != NULL) {
|
*/
|
||||||
ret = out->writecallback(out->context,
|
if (out->encoder != NULL) {
|
||||||
(const char *)out->conv->content, nbchars);
|
ret = out->writecallback(out->context,
|
||||||
if (ret >= 0)
|
(const char *)out->conv->content, nbchars);
|
||||||
xmlBufferShrink(out->conv, nbchars);
|
if (ret >= 0)
|
||||||
} else {
|
xmlBufferShrink(out->conv, nbchars);
|
||||||
ret = out->writecallback(out->context,
|
} else {
|
||||||
(const char *)out->buffer->content, nbchars);
|
ret = out->writecallback(out->context,
|
||||||
if (ret >= 0)
|
(const char *)out->buffer->content, nbchars);
|
||||||
xmlBufferShrink(out->buffer, nbchars);
|
if (ret >= 0)
|
||||||
}
|
xmlBufferShrink(out->buffer, nbchars);
|
||||||
if (ret < 0) {
|
}
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
if (ret < 0) {
|
||||||
"I/O: error %d writing %d bytes\n", ret, nbchars);
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
return(ret);
|
"I/O: error %d writing %d bytes\n", ret, nbchars);
|
||||||
}
|
return(ret);
|
||||||
out->written += ret;
|
}
|
||||||
|
out->written += ret;
|
||||||
|
}
|
||||||
|
written += nbchars;
|
||||||
|
} while (len > 0);
|
||||||
|
|
||||||
|
done:
|
||||||
#ifdef DEBUG_INPUT
|
#ifdef DEBUG_INPUT
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"I/O: wrote %d chars\n", ret);
|
"I/O: wrote %d chars\n", written);
|
||||||
#endif
|
#endif
|
||||||
return(nbchars);
|
return(written);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user