Paul Burba wrote:
> But I
> confess I'm a bit uneasy about how I modify argv. I pass &argv to
> svn_cmdline_args_from_ebcdic(), convert the args to utf-8 in a separately
> allocated char ** and then cast away argv's "constness" so I can point it
> at the converted char **. Is avoiding const like this legit? (Somewhere
> in the back of my head the ghostly voice of a CS TA is saying
> "Woooo...don't cast away a const!" :-)
>
The canonical prototype for main() is:
int main (int argc, const char *argv[]);
So, argv is an array of pointers to const char, but the argv array
itself is _not_ unmodifiable.
The correct way to modify the argv array is to replace the pointers in
place; like this:
svn_error_t *
svn_cmdline_args_from_ebcdic (int argc, const char *argv[],
apr_pool_t *pool)
{
int i;
for (i = 0; i < argc; ++i)
{
char *arg_utf8;
SVN_ERR(svn_utf_cstring_to_utf8_ex(&arg_utf, argv[i],
SVN_UTF_ETOU_XLATE_HANDLE,
pool);
argv[i] = arg_utf8;
}
return SVN_NO_ERROR;
}
-- Brane
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Feb 10 23:59:41 2006