Fix insane bytemark issue on Solaris

darcs-hash:20070908191940-ac50b-f99e05c86f32a5c1c1aff35c1916951269a54d54.gz
This commit is contained in:
axel 2007-09-09 05:19:40 +10:00
parent 3fc1ba0f0e
commit a900d16540
2 changed files with 22 additions and 4 deletions

View file

@ -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");

View file

@ -57,4 +57,5 @@ if test -d include
for i in include/*.fish
. $i
end
end
end