Skip to content

Commit

Permalink
vlc: Convert command line arguments to UTF-8 on OS/2
Browse files Browse the repository at this point in the history
Signed-off-by: Rémi Denis-Courmont <[email protected]>
  • Loading branch information
komh authored and Rémi Denis-Courmont committed Oct 20, 2012
1 parent af76a67 commit 04dc219
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion bin/vlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,42 @@
#include <unistd.h>

#ifdef __OS2__
# include <iconv.h>

# define pthread_t int
# define pthread_self() _gettid()
#endif

static char *FromSystem(const void *str)
{
iconv_t handle = iconv_open ("UTF-8", "");
if (handle == (iconv_t)(-1))
return NULL;

size_t str_len = strlen (str);
char *out = NULL;
for (unsigned mul = 4; mul < 8; mul++)
{
size_t in_size = str_len;
const char *in = str;
size_t out_max = mul * str_len;
char *tmp = out = malloc (1 + out_max);
if (!out)
break;

if (iconv (handle, &in, &in_size, &tmp, &out_max) != (size_t)(-1)) {
*tmp = '\0';
break;
}
free(out);
out = NULL;

if (errno != E2BIG)
break;
}
iconv_close(handle);
return out;
}
#endif

extern void vlc_enable_override (void);

Expand Down Expand Up @@ -183,8 +215,18 @@ int main( int i_argc, const char *ppsz_argv[] )
if (i_argc >= 1 && !strncmp (*ppsz_argv, "-psn" , 4))
ppsz_argv++, i_argc--;
#endif
#ifdef __OS2__
for (int i = 0; i < i_argc; i++)
if ((argv[argc++] = FromSystem (ppsz_argv[i])) == NULL)
{
fprintf (stderr, "Converting '%s' to UTF-8 failed.\n",
ppsz_argv[i]);
return 1;
}
#else
memcpy (argv + argc, ppsz_argv, i_argc * sizeof (*argv));
argc += i_argc;
#endif
argv[argc] = NULL;

vlc_enable_override ();
Expand Down Expand Up @@ -237,5 +279,10 @@ int main( int i_argc, const char *ppsz_argv[] )
if (vlc != NULL)
libvlc_release (vlc);

#ifdef __OS2__
for (int i = 2; i < argc; i++)
free (argv[i]);
#endif

return 0;
}

0 comments on commit 04dc219

Please sign in to comment.