| 1490 | |
| 1491 | #ifdef LIBXML_ICONV_ENABLED |
| 1492 | static int |
| 1493 | xmlCreateIconvHandler(const char *name, xmlCharEncodingHandler **out) { |
| 1494 | xmlCharEncodingHandlerPtr enc = NULL; |
| 1495 | iconv_t icv_in = (iconv_t) -1; |
| 1496 | iconv_t icv_out = (iconv_t) -1; |
| 1497 | int ret; |
| 1498 | |
| 1499 | *out = NULL; |
| 1500 | |
| 1501 | icv_in = iconv_open("UTF-8", name); |
| 1502 | if (icv_in == (iconv_t) -1) { |
| 1503 | if (errno == EINVAL) |
| 1504 | ret = XML_ERR_UNSUPPORTED_ENCODING; |
| 1505 | else if (errno == ENOMEM) |
| 1506 | ret = XML_ERR_NO_MEMORY; |
| 1507 | else |
| 1508 | ret = XML_ERR_SYSTEM; |
| 1509 | goto error; |
| 1510 | } |
| 1511 | |
| 1512 | icv_out = iconv_open(name, "UTF-8"); |
| 1513 | if (icv_out == (iconv_t) -1) { |
| 1514 | if (errno == EINVAL) |
| 1515 | ret = XML_ERR_UNSUPPORTED_ENCODING; |
| 1516 | else if (errno == ENOMEM) |
| 1517 | ret = XML_ERR_NO_MEMORY; |
| 1518 | else |
| 1519 | ret = XML_ERR_SYSTEM; |
| 1520 | goto error; |
| 1521 | } |
| 1522 | |
| 1523 | enc = xmlMalloc(sizeof(*enc)); |
| 1524 | if (enc == NULL) { |
| 1525 | ret = XML_ERR_NO_MEMORY; |
| 1526 | goto error; |
| 1527 | } |
| 1528 | memset(enc, 0, sizeof(*enc)); |
| 1529 | |
| 1530 | enc->name = xmlMemStrdup(name); |
| 1531 | if (enc->name == NULL) { |
| 1532 | ret = XML_ERR_NO_MEMORY; |
| 1533 | goto error; |
| 1534 | } |
| 1535 | enc->iconv_in = icv_in; |
| 1536 | enc->iconv_out = icv_out; |
| 1537 | |
| 1538 | *out = enc; |
| 1539 | return(0); |
| 1540 | |
| 1541 | error: |
| 1542 | if (enc != NULL) |
| 1543 | xmlFree(enc); |
| 1544 | if (icv_in != (iconv_t) -1) |
| 1545 | iconv_close(icv_in); |
| 1546 | if (icv_out != (iconv_t) -1) |
| 1547 | iconv_close(icv_out); |
| 1548 | return(ret); |
| 1549 | } |
no outgoing calls
no test coverage detected