From a900d165403e0e21a7cd7ae88e8f046297424d89 Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 9 Sep 2007 05:19:40 +1000 Subject: [PATCH] Fix insane bytemark issue on Solaris darcs-hash:20070908191940-ac50b-f99e05c86f32a5c1c1aff35c1916951269a54d54.gz --- env_universal_common.c | 23 ++++++++++++++++++++--- etc/config.fish.in | 3 ++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/env_universal_common.c b/env_universal_common.c index 988dbfbd2..8c47e3239 100644 --- a/env_universal_common.c +++ b/env_universal_common.c @@ -215,7 +215,7 @@ wchar_t *utf2wcs( const char *in ) char **from_name = iconv_utf8_names; size_t in_len = strlen( in ); - size_t out_len = sizeof( wchar_t )*(in_len+1); + size_t out_len = sizeof( wchar_t )*(in_len+2); size_t nconv; char *nout; @@ -253,8 +253,7 @@ wchar_t *utf2wcs( const char *in ) return 0; } - - nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len ); + nconv = iconv( cd, (const char **)&in, &in_len, &nout, &out_len ); if (nconv == (size_t) -1) { @@ -263,6 +262,24 @@ wchar_t *utf2wcs( const char *in ) } *((wchar_t *) nout) = L'\0'; + + /* + Check for silly iconv behaviour inserting an bytemark in the output + string. + */ + if (*out == L'\xfeff' || *out == L'\xffef' || *out == L'\xefbbbf') + { + wchar_t *out_old = out; + out = wcsdup(out+1); + if (! out ) + { + debug(0, L"FNORD!!!!"); + free( out_old ); + return 0; + } + free( out_old ); + } + if (iconv_close (cd) != 0) wperror (L"iconv_close"); diff --git a/etc/config.fish.in b/etc/config.fish.in index 7940a402d..9ccf99b12 100644 --- a/etc/config.fish.in +++ b/etc/config.fish.in @@ -57,4 +57,5 @@ if test -d include for i in include/*.fish . $i end -end \ No newline at end of file +end +