diff options
Diffstat (limited to 'src/url.c')
-rw-r--r-- | src/url.c | 106 |
1 files changed, 54 insertions, 52 deletions
@@ -51,7 +51,7 @@ as that of the covered work. */ #endif /* def __VMS */ #ifdef TESTING -#include "test.h" +#include "../tests/unit-tests.h" #endif enum { @@ -1551,13 +1551,13 @@ append_uri_pathel (const char *b, const char *e, bool escaped, static char * convert_fname (char *fname) { - char *converted_fname = fname; + char *converted_fname; const char *from_encoding = opt.encoding_remote; const char *to_encoding = opt.locale; iconv_t cd; size_t len, done, inlen, outlen; char *s; - const char *orig_fname = fname; + const char *orig_fname; /* Defaults for remote and local encodings. */ if (!from_encoding) @@ -1567,62 +1567,64 @@ convert_fname (char *fname) cd = iconv_open (to_encoding, from_encoding); if (cd == (iconv_t) (-1)) - logprintf (LOG_VERBOSE, _ ("Conversion from %s to %s isn't supported\n"), - quote (from_encoding), quote (to_encoding)); - else { - inlen = strlen (fname); - len = outlen = inlen * 2; - converted_fname = s = xmalloc (outlen + 1); - done = 0; + logprintf (LOG_VERBOSE, _ ("Conversion from %s to %s isn't supported\n"), + quote (from_encoding), quote (to_encoding)); + return fname; + } + + orig_fname = fname; + inlen = strlen (fname); + len = outlen = inlen * 2; + converted_fname = s = xmalloc (outlen + 1); + done = 0; - for (;;) + for (;;) + { + errno = 0; + if (iconv (cd, (ICONV_CONST char **) &fname, &inlen, &s, &outlen) == 0 + && iconv (cd, NULL, NULL, &s, &outlen) == 0) { - errno = 0; - if (iconv (cd, (ICONV_CONST char **) &fname, &inlen, &s, &outlen) == 0 - && iconv (cd, NULL, NULL, &s, &outlen) == 0) - { - *(converted_fname + len - outlen - done) = '\0'; - iconv_close (cd); - DEBUGP (("Converted file name '%s' (%s) -> '%s' (%s)\n", - orig_fname, from_encoding, converted_fname, to_encoding)); - xfree (orig_fname); - return converted_fname; - } + *(converted_fname + len - outlen - done) = '\0'; + iconv_close (cd); + DEBUGP (("Converted file name '%s' (%s) -> '%s' (%s)\n", + orig_fname, from_encoding, converted_fname, to_encoding)); + xfree (orig_fname); + return converted_fname; + } - /* Incomplete or invalid multibyte sequence */ - if (errno == EINVAL || errno == EILSEQ || errno == 0) - { - if (errno) - logprintf (LOG_VERBOSE, - _ ("Incomplete or invalid multibyte sequence encountered\n")); - else - logprintf (LOG_VERBOSE, - _ ("Unconvertable multibyte sequence encountered\n")); - xfree (converted_fname); - converted_fname = (char *) orig_fname; - break; - } - else if (errno == E2BIG) /* Output buffer full */ - { - done = len; - len = outlen = done + inlen * 2; - converted_fname = xrealloc (converted_fname, outlen + 1); - s = converted_fname + done; - } - else /* Weird, we got an unspecified error */ - { - logprintf (LOG_VERBOSE, _ ("Unhandled errno %d\n"), errno); - xfree (converted_fname); - converted_fname = (char *) orig_fname; - break; - } + /* Incomplete or invalid multibyte sequence */ + if (errno == EINVAL || errno == EILSEQ || errno == 0) + { + if (errno) + logprintf (LOG_VERBOSE, + _ ("Incomplete or invalid multibyte sequence encountered\n")); + else + logprintf (LOG_VERBOSE, + _ ("Unconvertable multibyte sequence encountered\n")); + xfree (converted_fname); + converted_fname = (char *) orig_fname; + break; + } + else if (errno == E2BIG) /* Output buffer full */ + { + done = len; + len = outlen = done + inlen * 2; + converted_fname = xrealloc (converted_fname, outlen + 1); + s = converted_fname + done; + } + else /* Weird, we got an unspecified error */ + { + logprintf (LOG_VERBOSE, _ ("Unhandled errno %d\n"), errno); + xfree (converted_fname); + converted_fname = (char *) orig_fname; + break; } - DEBUGP (("Failed to convert file name '%s' (%s) -> '?' (%s)\n", - orig_fname, from_encoding, to_encoding)); } + DEBUGP (("Failed to convert file name '%s' (%s) -> '?' (%s)\n", + orig_fname, from_encoding, to_encoding)); - iconv_close(cd); + iconv_close (cd); return converted_fname; } |