Subject: | iconv_open failure patch |
Date: | Wed, 5 Sep 2012 21:01:59 -0700 (PDT) |
To: | "bug-Audio-TagLib [...] rt.cpan.org" <bug-Audio-TagLib [...] rt.cpan.org> |
From: | Festus Hagen <festushagen2002 [...] yahoo.com> |
Audio::TagLib v1.61
OS: Win32, FreeBSD tested. Should work for all.
Perl:: Should work for all.
iconv: ?? Should work for all.
Bug: iconv_open() fails, incorrect character set names, iconv expects a hyphen in UTF names.
Patch also resolves: warning: deprecated conversion from string constant to 'char*'
Changing where *fromcode is assigned it's value to a hyphenated version causes implications further down the line, including with Taglib.
So, My solution ...
diff -u -w -r -B --strip-trailing-cr Orig/tstring.xs Modded/tstring.xs
--- Orig/tstring.xs 2012-07-04 20:07:44.000000000 -0400
+++ Modded/tstring.xs 2012-09-05 17:59:24.000000000 -0400
@@ -14,7 +14,7 @@
TagLib::String::new(...)
PROTOTYPE: ;$$
PREINIT:
- char *encode, *fromcode;
+ const char *encode, *fromcode;
enum TagLib::String::Type t;
bool is_copy_from_string = TRUE;
iconv_t codec;
@@ -131,7 +131,18 @@
/* any other encodings converted to utf8 */
//sv_dump(ST(1));
//printf("fromcode = %s\n", fromcode);
- if(!(codec = iconv_open("UTF8", fromcode)))
+ const char *from_code;
+ if(strncasecmp(encode, "UTF8", 4) == 0) {
+ from_code = "UTF-8";
+ } else if(strncasecmp(encode, "UTF16BE", 7) == 0) {
+ from_code = "UTF-16BE";
+ } else if(strncasecmp(encode, "UTF16LE", 7) == 0) {
+ from_code = "UTF-16LE";
+ } else if(strncasecmp(encode, "UTF16", 5) == 0) {
+ from_code = "UTF-16";
+ } else
+ from_code = fromcode;
+ if(!(codec = iconv_open("UTF-8", from_code)))
croak("iconv_open failed, check your encode");
/* inlen MUST be the extract byte length of string */
/* the terminal '\0' should NOT be included in length */
-Enjoy
fh :)_~