* xmlEncOutputChunk: * @handler: encoding handler * @out: a pointer to an array of bytes to store the result * @outlen: the length of @out * @in: a pointer to an array of input bytes * @inlen: the length of @in * * Returns an XML_ENC_ERR code. * * The value of @inlen after return is the number of octets consumed * as the return value is 0, else unpredictable. * The value of @ou
| 2237 | * The value of @outlen after return is the number of octets produced. |
| 2238 | */ |
| 2239 | static int |
| 2240 | xmlEncOutputChunk(xmlCharEncodingHandler *handler, unsigned char *out, |
| 2241 | int *outlen, const unsigned char *in, int *inlen) { |
| 2242 | int ret; |
| 2243 | |
| 2244 | if (handler->output != NULL) { |
| 2245 | int oldinlen = *inlen; |
| 2246 | |
| 2247 | ret = handler->output(out, outlen, in, inlen); |
| 2248 | if (ret >= 0) { |
| 2249 | /* |
| 2250 | * The built-in converters don't signal XML_ENC_ERR_SPACE. |
| 2251 | */ |
| 2252 | if (*inlen < oldinlen) { |
| 2253 | if (*outlen > 0) |
| 2254 | ret = XML_ENC_ERR_SPACE; |
| 2255 | else |
| 2256 | ret = XML_ENC_ERR_PARTIAL; |
| 2257 | } else { |
| 2258 | ret = XML_ENC_ERR_SUCCESS; |
| 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | #ifdef LIBXML_ICONV_ENABLED |
| 2263 | else if (handler->iconv_out != NULL) { |
| 2264 | ret = xmlIconvWrapper(handler->iconv_out, out, outlen, in, inlen); |
| 2265 | } |
| 2266 | #endif /* LIBXML_ICONV_ENABLED */ |
| 2267 | #ifdef LIBXML_ICU_ENABLED |
| 2268 | else if (handler->uconv_out != NULL) { |
| 2269 | ret = xmlUconvWrapper(handler->uconv_out, 0, out, outlen, in, inlen); |
| 2270 | } |
| 2271 | #endif /* LIBXML_ICU_ENABLED */ |
| 2272 | else { |
| 2273 | *outlen = 0; |
| 2274 | *inlen = 0; |
| 2275 | ret = XML_ENC_ERR_INTERNAL; |
| 2276 | } |
| 2277 | |
| 2278 | /* We shouldn't generate partial sequences when writing. */ |
| 2279 | if (ret == XML_ENC_ERR_PARTIAL) |
| 2280 | ret = XML_ENC_ERR_INTERNAL; |
| 2281 | |
| 2282 | return(ret); |
| 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * xmlCharEncFirstLine: |
no test coverage detected