From: Max Kellermann Date: Thu, 2 Oct 2008 17:02:07 +0000 (+0200) Subject: fix compiler errors without locale.h X-Git-Tag: v0.12_alpha1~101 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2fa18f35d878e280bbd8299aa4048bb59e183165;p=ncmpc.git fix compiler errors without locale.h The code did not compile when HAVE_LOCALE_H was not set. Also don't compile all that code in charset.c, when there is no locale.h. --- diff --git a/src/charset.c b/src/charset.c index 42c0e60..095817d 100644 --- a/src/charset.c +++ b/src/charset.c @@ -23,6 +23,7 @@ #include #include +#ifdef HAVE_LOCALE_H static bool noconvert = true; static const char *charset; @@ -31,13 +32,16 @@ charset_init(void) { noconvert = g_get_charset(&charset); return charset; + return NULL; } +#endif unsigned utf8_width(const char *str) { assert(str != NULL); +#ifdef HAVE_LOCALE_H if (g_utf8_validate(str, -1, NULL)) { size_t len = g_utf8_strlen(str, -1); unsigned width = 0; @@ -51,12 +55,14 @@ utf8_width(const char *str) return width; } else +#endif return strlen(str); } char * utf8_to_locale(const char *utf8str) { +#ifdef HAVE_LOCALE_H gchar *str; GError *error; @@ -75,11 +81,15 @@ utf8_to_locale(const char *utf8str) } return str; +#else + return g_strdup(utf8str); +#endif } char * locale_to_utf8(const char *localestr) { +#ifdef HAVE_LOCALE_H gchar *str; GError *error; @@ -98,4 +108,7 @@ locale_to_utf8(const char *localestr) } return str; +#else + return g_strdup(localestr); +#endif } diff --git a/src/charset.h b/src/charset.h index 70173d1..0cb69d1 100644 --- a/src/charset.h +++ b/src/charset.h @@ -20,11 +20,15 @@ #ifndef CHARSET_H #define CHARSET_H +#include "config.h" + #include #include +#ifdef HAVE_LOCALE_H const char * charset_init(void); +#endif /** * Returns the number of terminal cells occupied by this string. diff --git a/src/main.c b/src/main.c index 07198e7..668d5aa 100644 --- a/src/main.c +++ b/src/main.c @@ -323,7 +323,9 @@ int main(int argc, const char *argv[]) { struct sigaction act; +#ifdef HAVE_LOCALE_H const char *charset = NULL; +#endif GIOChannel *keyboard_channel; #ifdef HAVE_LOCALE_H @@ -335,7 +337,6 @@ main(int argc, const char *argv[]) setlocale(LC_CTYPE,""); /* initialize charset conversions */ charset = charset_init(); -#endif /* initialize i18n support */ #ifdef ENABLE_NLS @@ -343,6 +344,7 @@ main(int argc, const char *argv[]) bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, charset); textdomain(GETTEXT_PACKAGE); +#endif #endif /* initialize options */