* xmlParserInputBufferGrow: * @in: a buffered parser input * @len: indicative value of the amount of chars to read * * Grow up the content of the input buffer, the old data are preserved * This routine handle the I18N transcoding to internal UTF-8 * This routine is used when operating the parser in normal (pull) mode * * TODO: one should be able to remove one extra copy by copying direct
| 2342 | * in case of error. |
| 2343 | */ |
| 2344 | int |
| 2345 | xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) { |
| 2346 | xmlBufPtr buf; |
| 2347 | int res = 0; |
| 2348 | |
| 2349 | if ((in == NULL) || (in->error)) return(-1); |
| 2350 | if ((len <= MINLEN) && (len != 4)) |
| 2351 | len = MINLEN; |
| 2352 | |
| 2353 | if (in->encoder == NULL) { |
| 2354 | if (in->readcallback == NULL) |
| 2355 | return(0); |
| 2356 | buf = in->buffer; |
| 2357 | } else { |
| 2358 | if (in->raw == NULL) { |
| 2359 | in->raw = xmlBufCreate(); |
| 2360 | } |
| 2361 | buf = in->raw; |
| 2362 | } |
| 2363 | |
| 2364 | /* |
| 2365 | * Call the read method for this I/O type. |
| 2366 | */ |
| 2367 | if (in->readcallback != NULL) { |
| 2368 | if (xmlBufGrow(buf, len + 1) < 0) { |
| 2369 | in->error = XML_ERR_NO_MEMORY; |
| 2370 | return(-1); |
| 2371 | } |
| 2372 | |
| 2373 | res = in->readcallback(in->context, (char *)xmlBufEnd(buf), len); |
| 2374 | if (res <= 0) |
| 2375 | in->readcallback = endOfInput; |
| 2376 | if (res < 0) { |
| 2377 | if (res == -1) |
| 2378 | in->error = XML_IO_UNKNOWN; |
| 2379 | else |
| 2380 | in->error = -res; |
| 2381 | return(-1); |
| 2382 | } |
| 2383 | |
| 2384 | if (xmlBufAddLen(buf, res) < 0) { |
| 2385 | in->error = XML_ERR_NO_MEMORY; |
| 2386 | return(-1); |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | /* |
| 2391 | * try to establish compressed status of input if not done already |
| 2392 | */ |
| 2393 | if (in->compressed == -1) { |
| 2394 | #ifdef LIBXML_LZMA_ENABLED |
| 2395 | if (in->readcallback == xmlXzfileRead) |
| 2396 | in->compressed = __libxml2_xzcompressed(in->context); |
| 2397 | #endif |
| 2398 | } |
| 2399 | |
| 2400 | if (in->encoder != NULL) { |
| 2401 | res = xmlCharEncInput(in); |
no test coverage detected