};
/**
- * Create a new charset conversion tool.
+ * Create a new charset conversion tool controlling its behavior.
*
* Conversion tool will try to convert provided strings to UTF-8, just need
* to register known charsets with lms_charset_conv_add() and then call
* @return newly allocated conversion tool or NULL on error.
*/
lms_charset_conv_t *
-lms_charset_conv_new(void)
+lms_charset_conv_new_full(int use_check, int use_fallback)
{
lms_charset_conv_t *lcc;
return NULL;
}
- lcc->check = iconv_open("UTF-8", "UTF-8");
- if (lcc->check == (iconv_t)-1) {
- perror("ERROR: could not create conversion checker");
- goto error_check;
+ if (!use_check)
+ lcc->check = (iconv_t)-1;
+ else {
+ lcc->check = iconv_open("UTF-8", "UTF-8");
+ if (lcc->check == (iconv_t)-1) {
+ perror("ERROR: could not create conversion checker");
+ goto error_check;
+ }
}
- lcc->fallback = iconv_open("UTF-8//IGNORE", "UTF-8");
- if (lcc->fallback == (iconv_t)-1) {
- perror("ERROR: could not create conversion fallback");
- goto error_fallback;
+ if (!use_fallback)
+ lcc->fallback = (iconv_t)-1;
+ else {
+ lcc->fallback = iconv_open("UTF-8//IGNORE", "UTF-8");
+ if (lcc->fallback == (iconv_t)-1) {
+ perror("ERROR: could not create conversion fallback");
+ goto error_fallback;
+ }
}
lcc->size = 0;
return lcc;
error_fallback:
- iconv_close(lcc->check);
+ if (lcc->check != (iconv_t)-1)
+ iconv_close(lcc->check);
error_check:
free(lcc);
}
/**
+ * Create a new charset conversion tool.
+ *
+ * Conversion tool will try to convert provided strings to UTF-8, just need
+ * to register known charsets with lms_charset_conv_add() and then call
+ * lms_charset_conv().
+ *
+ * @return newly allocated conversion tool or NULL on error.
+ */
+lms_charset_conv_t *
+lms_charset_conv_new(void)
+{
+ return lms_charset_conv_new_full(1, 1);
+}
+
+/**
* Free existing charset conversion tool.
*
* @param lcc existing Light Media Scanner charset conversion.
if (!lcc)
return;
- iconv_close(lcc->check);
- iconv_close(lcc->fallback);
+ if (lcc->check != (iconv_t)-1)
+ iconv_close(lcc->check);
+ if (lcc->fallback != (iconv_t)-1)
+ iconv_close(lcc->fallback);
for (i = 0; i < lcc->size; i++) {
iconv_close(lcc->convs[i]);
char *inbuf, *outbuf;
size_t r, inlen, outlen;
+ if (lcc->check == (iconv_t)-1)
+ return -1;
+
inbuf = (char *)istr;
inlen = ilen;
outbuf = ostr;
if (_conv(lcc->convs[i], p_str, p_len, outstr, outlen) == 0)
return 0;
+ if (lcc->fallback == (iconv_t)-1)
+ return -5;
+
fprintf(stderr,
"WARNING: could not convert '%*s' to any charset, use fallback\n",
*p_len, *p_str);
if (_conv(lcc->convs[i], p_str, p_len, outstr, outlen) == 0)
return 0;
+ if (lcc->fallback == (iconv_t)-1)
+ return -5;
+
fprintf(stderr,
"WARNING: could not convert '%*s' to any charset, use fallback\n",
*p_len, *p_str);