diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-01-24 21:19:29 +0100 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-01-24 21:19:29 +0100 |
commit | 5ee5ea4f0a6027e0261e4ee769bedb0e598c41de (patch) | |
tree | 675298a99462f802c04db15fc32527b8d74b52cd /junklib.c | |
parent | aa4832661a52fbcdccafae62fccb9e4901777f3d (diff) |
iconv fixes for bsd compatibility
Diffstat (limited to 'junklib.c')
-rw-r--r-- | junklib.c | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -16,20 +16,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "junklib.h" -#include <iconv.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#define LIBICONV_PLUG +#include <iconv.h> #include "playlist.h" #include "utf8.h" #include "plugins.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif -#if HAVE_LIBICONV -#define iconv_open libiconv_open -#define iconv_close libiconv_close -#endif + +#define UTF8 "utf-8" //#define trace(...) { fprintf(stderr, __VA_ARGS__); } #define trace(fmt,...) @@ -297,10 +296,10 @@ convstr_id3v2_2to3 (const unsigned char* str, int sz) { } str++; sz--; - iconv_t cd = iconv_open ("utf8", enc); + iconv_t cd = iconv_open (UTF8, enc); if (cd == (iconv_t)-1) { trace ("iconv can't recoode from %s to utf8", enc); - return NULL; + return strdup ("-"); } else { size_t inbytesleft = sz; @@ -312,7 +311,6 @@ convstr_id3v2_2to3 (const unsigned char* str, int sz) { #endif char *pout = out; memset (out, 0, sizeof (out)); - printf ("%p %s %d %d\n", cd, pin, inbytesleft, outbytesleft); /*size_t res = */iconv (cd, &pin, &inbytesleft, &pout, &outbytesleft); iconv_close (cd); ret = out; @@ -359,10 +357,10 @@ convstr_id3v2_4 (const unsigned char* str, int sz) { } str++; sz--; - iconv_t cd = iconv_open ("utf8", enc); + iconv_t cd = iconv_open (UTF8, enc); if (cd == (iconv_t)-1) { - trace ("unknown encoding: %s\n", enc); - return NULL; + trace ("iconv can't recode from %s to utf8\n", enc); + return strdup ("-"); } else { size_t inbytesleft = sz; @@ -398,9 +396,10 @@ convstr_id3v1 (const char* str, int sz) { // check for utf8 (hack) iconv_t cd; - cd = iconv_open ("utf8", "utf8"); + cd = iconv_open (UTF8, UTF8); if (cd == (iconv_t)-1) { trace ("iconv doesn't support utf8\n"); + return str; } size_t inbytesleft = sz; size_t outbytesleft = 2047; @@ -423,10 +422,10 @@ convstr_id3v1 (const char* str, int sz) { if (can_be_russian (str)) { enc = "cp1251"; } - cd = iconv_open ("utf8", enc); + cd = iconv_open (UTF8, enc); if (cd == (iconv_t)-1) { trace ("iconv can't recode from %s to utf8\n", enc); - return NULL; + return str; } else { size_t inbytesleft = sz; @@ -1307,9 +1306,10 @@ junk_detect_charset (const char *s) { void junk_recode (const char *in, int inlen, char *out, int outlen, const char *cs) { - iconv_t cd = iconv_open ("utf8", cs); + iconv_t cd = iconv_open (UTF8, cs); if (cd == (iconv_t)-1) { trace ("iconv can't recode from %s to utf8\n", cs); + memcpy (out, in, min(inlen, outlen)); return; } else { |