E.g. in OpenWrt libiconv is an optional package.
---
configure | 1 +
convert.c | 13 +++++++++++++
scripts/checks.sh | 37 +++++++++++++++++++++++++++++++++----
ui_curses.c | 11 +++++++++++
4 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index daf6f10..96d0cdb 100755
--- a/configure
+++ b/configure
@@ -407,6 +407,7 @@ config_header config/mp4.h USE_MPEG4IP
config_header config/curses.h HAVE_RESIZETERM HAVE_USE_DEFAULT_COLORS
config_header config/ffmpeg.h USE_FALLBACK_IP
config_header config/utils.h HAVE_BYTESWAP_H
+config_header config/iconv.h HAVE_ICONV
makefile_vars bindir datadir libdir mandir exampledir
makefile_vars CONFIG_FLAC CONFIG_MAD CONFIG_MIKMOD CONFIG_MODPLUG CONFIG_MPC CONFIG_VORBIS CONFIG_WAVPACK CONFIG_WAV CONFIG_MP4 CONFIG_AAC CONFIG_FFMPEG
diff --git a/convert.c b/convert.c
index 27a266e..f372fb5 100644
--- a/convert.c
+++ b/convert.c
@@ -19,8 +19,11 @@
#include "convert.h"
#include "xmalloc.h"
+#include "config/iconv.h"
+#ifdef HAVE_ICONV
#include <iconv.h>
+#endif
#include <string.h>
#include <errno.h>
@@ -28,6 +31,7 @@ ssize_t convert(const char *inbuf, ssize_t inbuf_size,
char **outbuf, ssize_t outbuf_estimate,
const char *tocode, const char *fromcode)
{
+#ifdef HAVE_ICONV
const char *in;
char *out;
size_t outbuf_size, inbytesleft, outbytesleft;
@@ -78,6 +82,15 @@ error:
iconv_close(cd);
errno = err_save;
return -1;
+
+#else
+ if (inbuf_size < 0)
+ inbuf_size = strlen(inbuf);
+ *outbuf = xnew(char, inbuf_size + 1);
+ memcpy(*outbuf, inbuf, inbuf_size);
+ (*outbuf)[inbuf_size] = '\0';
+ return inbuf_size;
+#endif
}
int utf8_encode(const char *inbuf, const char *encoding, char **outbuf)
diff --git a/scripts/checks.sh b/scripts/checks.sh
index e6e1d67..c2f048f 100644
--- a/scripts/checks.sh
+++ b/scripts/checks.sh
@@ -670,10 +670,39 @@ check_dl()
# adds ICONV_CFLAGS and ICONV_LIBS to config.mk
check_iconv()
{
- check_library ICONV "" "-liconv" && return 0
+ HAVE_ICONV=n
+ if check_library ICONV "" "-liconv"
+ then
+ echo "taking iconv from libiconv"
+ else
+ echo "assuming libc contains iconv"
+ makefile_var ICONV_CFLAGS ""
+ makefile_var ICONV_LIBS ""
+ fi
+ msg_checking "for working iconv"
+ if try_compile_link '
+#include <stdio.h>
+#include <string.h>
+#include <iconv.h>
+int main(int argc, char *argv[]) {
+ char buf[128], *out = buf, *in = argv[1];
+ size_t outleft = 127, inleft = strlen(in);
+ iconv_t cd = iconv_open("UTF-8", "ISO-8859-1");
+ iconv(cd, &in, &inleft, &out, &outleft);
+ *out = 0;
+ printf("%s", buf);
+ iconv_close(cd);
+ return 0;
+}' $ICONV_CFLAGS $ICONV_LIBS
+ then
+ msg_result "yes"
+ HAVE_ICONV=y
+ else
+ msg_result "no"
+ msg_error "Your system doesn't have iconv!"
+ msg_error "This means that no charset conversion can be done, so all"
+ msg_error "your tracks need to be encoded in your system charset!"
+ fi
- echo "assuming libc contains iconv"
- makefile_var ICONV_CFLAGS ""
- makefile_var ICONV_LIBS ""
return 0
}
diff --git a/ui_curses.c b/ui_curses.c
index 217ed41..50a0df5 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -47,6 +47,7 @@
#include "input.h"
#include "file.h"
#include "config/curses.h"
+#include "config/iconv.h"
#include <unistd.h>
#include <stdlib.h>
@@ -57,7 +58,9 @@
#include <dirent.h>
#include <locale.h>
#include <langinfo.h>
+#ifdef HAVE_ICONV
#include <iconv.h>
+#endif
#include <signal.h>
#include <stdarg.h>
#include <math.h>
@@ -288,6 +291,7 @@ int track_format_valid(const char *format)
static void utf8_encode(const char *buffer)
{
+#ifdef HAVE_ICONV
static iconv_t cd = (iconv_t)-1;
size_t is, os;
const char *i;
@@ -312,10 +316,14 @@ static void utf8_encode(const char *buffer)
d_print("iconv failed: %s\n", strerror(errno));
return;
}
+#else
+ strcpy(conv_buffer, buffer);
+#endif
}
static void utf8_decode(const char *buffer)
{
+#ifdef HAVE_ICONV
static iconv_t cd = (iconv_t)-1;
size_t is, os;
const char *i;
@@ -340,6 +348,9 @@ static void utf8_decode(const char *buffer)
d_print("iconv failed: %s\n", strerror(errno));
return;
}
+#else
+ strcpy(conv_buffer, buffer);
+#endif
}
/* screen updates {{{ */
--
1.7.4.1