aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am2
-rw-r--r--src/util/strings.c35
2 files changed, 20 insertions, 17 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 6da3b8d27..217229688 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -119,7 +119,7 @@ libgnunetutil_la_LIBADD = \
119 119
120libgnunetutil_la_LDFLAGS = \ 120libgnunetutil_la_LDFLAGS = \
121 $(GN_LIB_LDFLAGS) \ 121 $(GN_LIB_LDFLAGS) \
122 -version-info 8:0:0 122 -version-info 9:0:0
123 123
124 124
125libexec_PROGRAMS = \ 125libexec_PROGRAMS = \
diff --git a/src/util/strings.c b/src/util/strings.c
index 6fae8e713..70986a978 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -371,24 +371,22 @@ char *
371GNUNET_STRINGS_conv (const char *input, size_t len, const char *input_charset, const char *output_charset) 371GNUNET_STRINGS_conv (const char *input, size_t len, const char *input_charset, const char *output_charset)
372{ 372{
373 char *ret; 373 char *ret;
374
375 uint8_t *u8_string; 374 uint8_t *u8_string;
376 char *encoded_string; 375 char *encoded_string;
377 size_t u8_string_length; 376 size_t u8_string_length;
378 size_t encoded_string_length; 377 size_t encoded_string_length;
379 378
380 u8_string = u8_conv_from_encoding (input_charset, iconveh_error, input, len, NULL, NULL, &u8_string_length); 379 u8_string = u8_conv_from_encoding (input_charset,
380 iconveh_error,
381 input, len,
382 NULL, NULL,
383 &u8_string_length);
381 if (NULL == u8_string) 384 if (NULL == u8_string)
382 { 385 {
383 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding"); 386 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding");
384 LOG (GNUNET_ERROR_TYPE_WARNING, _("Character sets requested were `%s'->`%s'\n"), 387 goto fail;
385 input_charset, "UTF-8");
386 ret = GNUNET_malloc (len + 1);
387 memcpy (ret, input, len);
388 ret[len] = '\0';
389 return ret;
390 } 388 }
391 if (strcmp (output_charset, "UTF-8") == 0) 389 if (0 == strcmp (output_charset, "UTF-8"))
392 { 390 {
393 ret = GNUNET_malloc (u8_string_length + 1); 391 ret = GNUNET_malloc (u8_string_length + 1);
394 memcpy (ret, u8_string, u8_string_length); 392 memcpy (ret, u8_string, u8_string_length);
@@ -396,23 +394,28 @@ GNUNET_STRINGS_conv (const char *input, size_t len, const char *input_charset, c
396 free (u8_string); 394 free (u8_string);
397 return ret; 395 return ret;
398 } 396 }
399 encoded_string = u8_conv_to_encoding (output_charset, iconveh_error, u8_string, u8_string_length, NULL, NULL, &encoded_string_length); 397 encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
398 u8_string, u8_string_length,
399 NULL, NULL,
400 &encoded_string_length);
400 free (u8_string); 401 free (u8_string);
401 if (NULL == encoded_string) 402 if (NULL == encoded_string)
402 { 403 {
403 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_to_encoding"); 404 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_to_encoding");
404 LOG (GNUNET_ERROR_TYPE_WARNING, _("Character sets requested were `%s'->`%s'\n"), 405 goto fail;
405 "UTF-8", output_charset);
406 ret = GNUNET_malloc (len + 1);
407 memcpy (ret, input, len);
408 ret[len] = '\0';
409 return ret;
410 } 406 }
411 ret = GNUNET_malloc (encoded_string_length + 1); 407 ret = GNUNET_malloc (encoded_string_length + 1);
412 memcpy (ret, encoded_string, encoded_string_length); 408 memcpy (ret, encoded_string, encoded_string_length);
413 ret[encoded_string_length] = '\0'; 409 ret[encoded_string_length] = '\0';
414 free (encoded_string); 410 free (encoded_string);
415 return ret; 411 return ret;
412 fail:
413 LOG (GNUNET_ERROR_TYPE_WARNING, _("Character sets requested were `%s'->`%s'\n"),
414 "UTF-8", output_charset);
415 ret = GNUNET_malloc (len + 1);
416 memcpy (ret, input, len);
417 ret[len] = '\0';
418 return ret;
416} 419}
417 420
418 421