[vlc-devel] [PATCH 1/9] Workaround for OS/2 iconv(), which 1. supports UCS-2 only not UTF-16 2. does not treat a string as a pathname by default
Rémi Denis-Courmont
remi at remlab.net
Sat Nov 26 15:39:12 CET 2011
Le samedi 26 novembre 2011 08:05:21 KO Myung-Hun, vous avez écrit :
> ---
> src/extras/libc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 44 insertions(+), 0 deletions(-)
>
> diff --git a/src/extras/libc.c b/src/extras/libc.c
> index 5b028a6..ff40aa0 100644
> --- a/src/extras/libc.c
> +++ b/src/extras/libc.c
> @@ -37,6 +37,15 @@
> # include <iconv.h>
> #endif
>
> +#if defined(__OS2__) && defined(__INNOTEK_LIBC__)
> +# include <uconv.h>
> +
> +typedef struct os2_iconv_t
> +{
> + UconvObject from;
> +} os2_iconv_t;
> +#endif
> +
> /*************************************************************************
> **** * Local conversion routine from ISO_6937 to UTF-8 charset. Support for
> this * is still missing in libiconv, hence multiple operating systems lack
> it. @@ -326,7 +335,42 @@ vlc_iconv_t vlc_iconv_open( const char *tocode,
> const char *fromcode ) return (vlc_iconv_t)(-2);
> #endif
> #if defined(HAVE_ICONV)
> +# if defined(__OS2__) && defined(__INNOTEK_LIBC__)
> + char tocode_ucs2[] = "UCS-2LE";
> + char fromcode_ucs2[] = "UCS-2LE";
This should be const char *. There is no point in copying the strings on the
stack every time.
> + os2_iconv_t *p_os2_iconv;
> +
> + /* Workaround for UTF-16 because OS/2 supports UCS-2 only not UTF-16
> */ + if( !strncmp( tocode, "UTF-16", 6 ))
> + {
> + strncpy( tocode_ucs2 + 5, tocode + 6, 2 );
> + tocode = tocode_ucs2;
> + }
> +
> + if( !strncmp( fromcode, "UTF-16", 6 ))
> + {
> + strncpy( fromcode_ucs2 + 5, fromcode + 6, 2 );
> + fromcode = fromcode_ucs2;
> + }
> +
> + p_os2_iconv = ( os2_iconv_t * )iconv_open( tocode, fromcode );
> +
> + if( p_os2_iconv != ( iconv_t )(-1))
> + {
> + /* Assume strings contain pathnames */
> + uconv_attribute_t attr;
The string is not necessarily a path here. If you need special decoding for
path names, it belongs in the OS-specific filesystem functions.
> +
> + UniQueryUconvObject( p_os2_iconv->from, &attr,
> + sizeof( uconv_attribute_t ),
> + NULL, NULL, NULL );
> + attr.converttype |= CVTTYPE_PATH;
> + UniSetUconvObject( p_os2_iconv->from, &attr );
> + }
> +
> + return ( vlc_iconv_t )p_os2_iconv;
> +# else
> return iconv_open( tocode, fromcode );
> +# endif
> #else
> return (vlc_iconv_t)(-1);
> #endif
--
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis
More information about the vlc-devel
mailing list