Skip to content

Commit

Permalink
Use setlocale() unconditionally, complain if non-UTF8 locale and no i…
Browse files Browse the repository at this point in the history
…conv

Hopefully setlocale() is ubiquitous. Certainly nl_langinfo() seems to be
more often available than iconv(), so we can certainly complain if we are
run in a legacy non-UTF8 locale and we *don't* have conversion support.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 29, 2014
1 parent 8c493f5 commit 7195e60
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
47 changes: 24 additions & 23 deletions configure.ac
Expand Up @@ -179,32 +179,33 @@ AC_CHECK_FUNCS(setenv unsetenv)
AC_ENABLE_SHARED
AC_DISABLE_STATIC

have_iconv=no
LIBICONV=
AC_MSG_CHECKING([for iconv support])
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <iconv.h>],[
iconv_t ic = iconv_open("","");])],
[AC_MSG_RESULT(yes)
have_iconv=yes],
[oldLIBS="$LIBS"
LIBS="$LIBS -liconv"
AC_CHECK_FUNC(nl_langinfo, [AC_DEFINE(HAVE_NL_LANGINFO, 1, [Have nl_langinfo() function])], [])

if test "$ac_cv_func_nl_langinfo" = "yes"; then
have_iconv=no
LIBICONV=
AC_MSG_CHECKING([for iconv support])
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <iconv.h>],[
iconv_t ic = iconv_open("","");])],
[AC_MSG_RESULT(yes (with -liconv))
have_iconv=yes
LIBICONV=-liconv],
[AC_MSG_RESULT(no)])
LIBS="$oldLIBS"])

if test "$have_iconv" = "yes"; then
AC_SUBST(LIBICONV)
AC_DEFINE(HAVE_ICONV, 1, [Have iconv() function])
#include <iconv.h>],[
iconv_t ic = iconv_open("","");])],
[AC_MSG_RESULT(yes)
have_iconv=yes],
[oldLIBS="$LIBS"
LIBS="$LIBS -liconv"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <iconv.h>],[
iconv_t ic = iconv_open("","");])],
[AC_MSG_RESULT(yes (with -liconv))
have_iconv=yes
LIBICONV=-liconv],
[AC_MSG_RESULT(no)])
LIBS="$oldLIBS"])
if test "$have_iconv" = "yes"; then
AC_SUBST(LIBICONV)
AC_DEFINE(HAVE_ICONV, 1, [Have iconv() function])
fi
fi

AC_CHECK_FUNC(nl_langinfo, [AC_DEFINE(HAVE_NL_LANGINFO, 1, [Have nl_langinfo() function])], [])

AC_ARG_ENABLE([nls],
[ --disable-nls do not use Native Language Support],
[USE_NLS=$enableval], [USE_NLS=yes])
Expand Down
26 changes: 20 additions & 6 deletions main.c
Expand Up @@ -38,6 +38,7 @@
#include <sys/types.h>
#include <getopt.h>
#include <time.h>
#include <locale.h>

#ifdef LIBPROXY_HDR
#include LIBPROXY_HDR
Expand All @@ -55,6 +56,12 @@
#include <termios.h>
#endif

#ifdef HAVE_NL_LANGINFO
#include <langinfo.h>

static const char *legacy_charset;
#endif

static int write_new_config(void *_vpninfo,
char *buf, int buflen);
static void write_progress(void *_vpninfo,
Expand Down Expand Up @@ -374,11 +381,8 @@ static void read_stdin(char **string, int hidden)
}
}

#elif defined(HAVE_NL_LANGINFO) && defined(HAVE_ICONV)
#elif defined(HAVE_ICONV)
#include <iconv.h>
#include <langinfo.h>

static const char *legacy_charset;

static int is_ascii(char *str)
{
Expand Down Expand Up @@ -906,12 +910,22 @@ int main(int argc, char **argv)

#ifdef ENABLE_NLS
bindtextdomain("openconnect", LOCALEDIR);
setlocale(LC_ALL, "");
#endif
#if defined(HAVE_NL_LANGINFO) && defined(HAVE_ICONV)

setlocale(LC_ALL, "");

#ifdef HAVE_NL_LANGINFO
legacy_charset = nl_langinfo(CODESET);
if (legacy_charset && !strcmp(legacy_charset, "UTF-8"))
legacy_charset = NULL;

#ifndef HAVE_ICONV
if (legacy_charset)
fprintf(stderr,
_("WARNING: This version of openconnect was built without iconv\n"
" support but you appear to be using the legacy character\n"
" set \"%s\". Expect strangeness.\n"), legacy_charset);
#endif
#endif

if (strcmp(openconnect_version_str, openconnect_binary_version)) {
Expand Down
1 change: 0 additions & 1 deletion openconnect-internal.h
Expand Up @@ -81,7 +81,6 @@
#endif

#ifdef ENABLE_NLS
#include <locale.h>
#include <libintl.h>
#define _(s) dgettext("openconnect", s)
#else
Expand Down

0 comments on commit 7195e60

Please sign in to comment.