openIcuConverter(const char* name, int toUnicode)
{
  UErrorCode status = U_ZERO_ERROR;
  uconv_t *conv = (uconv_t *) xmlMalloc(sizeof(uconv_t));
  if (conv == NULL)
    return NULL;

  conv->uconv = ucnv_open(name, &status);
  if (U_FAILURE(status))
    goto error;

  status = U_ZERO_ERROR;
  if (toUnicode) {
    ucnv_setToUCallBack(conv->uconv, UCNV_TO_U_CALLBACK_STOP,
                        NULL, NULL, NULL, &status);
  }
  else {
    ucnv_setFromUCallBack(conv->uconv, UCNV_FROM_U_CALLBACK_STOP,
                        NULL, NULL, NULL, &status);
  }
  if (U_FAILURE(status))
    goto error;

  status = U_ZERO_ERROR;
  conv->utf8 = ucnv_open("UTF-8", &status);
  if (U_SUCCESS(status))
    return conv;

error:
  if (conv->uconv)
    ucnv_close(conv->uconv);
  xmlFree(conv);
  return NULL;
}
openIcuConverter(const char* name, int toUnicode)
{
  UErrorCode status = U_ZERO_ERROR;
  uconv_t *conv = (uconv_t *) xmlMalloc(sizeof(uconv_t));
  if (conv == NULL)
    return NULL;

  conv->uconv = ucnv_open(name, &status);
  if (U_FAILURE(status))
    goto error;

  status = U_ZERO_ERROR;
  if (toUnicode) {
    ucnv_setToUCallBack(conv->uconv, UCNV_TO_U_CALLBACK_STOP,
                        NULL, NULL, NULL, &status);
  }
  else {
    ucnv_setFromUCallBack(conv->uconv, UCNV_FROM_U_CALLBACK_STOP,
                        NULL, NULL, NULL, &status);
  }
  if (U_FAILURE(status))
    goto error;

  status = U_ZERO_ERROR;
  conv->utf8 = ucnv_open("UTF-8", &status);
  if (U_SUCCESS(status))
    return conv;

error:
  if (conv->uconv)
    ucnv_close(conv->uconv);
  xmlFree(conv);
  return NULL;
}