summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2020-10-31 08:07:57 +0100
committerGitHub <noreply@github.com>2020-10-31 08:07:57 +0100
commit882ac2972c6479932fc63fb806106f9f65feac1c (patch)
tree7feba3cb7d1ec15ab6c83a40d35ce684987c5d0d
parentc58e663ce4cbff76a705b4f73bd9d31d07eb3d88 (diff)
parent7eca2632a3213dadb8a5ff09e35020c688d0608f (diff)
downloadlibmtp-882ac2972c6479932fc63fb806106f9f65feac1c.tar.gz
Merge pull request #66 from dirkhh/cleanup
cleanup: don't declare variables unless they are used
-rw-r--r--src/unicode.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/unicode.c b/src/unicode.c
index cb686c6..629924b 100644
--- a/src/unicode.c
+++ b/src/unicode.c
@@ -76,16 +76,16 @@ int ucs2_strlen(uint16_t const * const unicstr)
*/
char *utf16_to_utf8(LIBMTP_mtpdevice_t *device, const uint16_t *unicstr)
{
+ char loclstr[STRING_BUFFER_LENGTH*3+1]; // UTF-8 encoding is max 3 bytes per UCS2 char.
+
+ loclstr[0]='\0';
+ #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
PTPParams *params = (PTPParams *) device->params;
char *stringp = (char *) unicstr;
- char loclstr[STRING_BUFFER_LENGTH*3+1]; // UTF-8 encoding is max 3 bytes per UCS2 char.
char *locp = loclstr;
size_t nconv;
size_t convlen = (ucs2_strlen(unicstr)+1) * sizeof(uint16_t); // UCS-2 is 16 bit wide, include terminator
size_t convmax = STRING_BUFFER_LENGTH*3;
-
- loclstr[0]='\0';
- #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
/* Do the conversion. */
nconv = iconv(params->cd_ucs2_to_locale, &stringp, &convlen, &locp, &convmax);
if (nconv == (size_t) -1) {
@@ -111,18 +111,18 @@ char *utf16_to_utf8(LIBMTP_mtpdevice_t *device, const uint16_t *unicstr)
*/
uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t *device, const char *localstr)
{
- PTPParams *params = (PTPParams *) device->params;
- char *stringp = (char *) localstr; // cast away "const"
char unicstr[(STRING_BUFFER_LENGTH+1)*2]; // UCS2 encoding is 2 bytes per UTF-8 char.
char *unip = unicstr;
size_t nconv = 0;
- size_t convlen = strlen(localstr)+1; // utf8 bytes, include terminator
- size_t convmax = STRING_BUFFER_LENGTH*2;
unicstr[0]='\0';
unicstr[1]='\0';
#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
+ PTPParams *params = (PTPParams *) device->params;
+ char *stringp = (char *) localstr; // cast away "const"
+ size_t convlen = strlen(localstr)+1; // utf8 bytes, include terminator
+ size_t convmax = STRING_BUFFER_LENGTH*2;
/* Do the conversion. */
nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, &unip, &convmax);
#endif