aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-12-22 08:25:41 +0000
committerLRN <lrn1986@gmail.com>2013-12-22 08:25:41 +0000
commit4fc3c362cc3f182c156bc5989cf92432d534c961 (patch)
tree8872fbd07509b955e92003b057e67d47635da615 /src
parent7df25e6e27fd04a7e958fb4edeee3ae1ae6e1c15 (diff)
downloadgnunet-4fc3c362cc3f182c156bc5989cf92432d534c961.tar.gz
gnunet-4fc3c362cc3f182c156bc5989cf92432d534c961.zip
Make GNUNET_STRINGS_absolute_time_to_string() return utf8-encoded string
Diffstat (limited to 'src')
-rw-r--r--src/util/strings.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index df0094cf4..cb3209215 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -745,7 +745,34 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
745 return _("end of time"); 745 return _("end of time");
746 tt = t.abs_value_us / 1000LL / 1000LL; 746 tt = t.abs_value_us / 1000LL / 1000LL;
747 tp = gmtime (&tt); 747 tp = gmtime (&tt);
748 /* This is hacky, but i don't know a way to detect libc character encoding.
749 * Just expect utf8 from glibc these days.
750 * As for msvcrt, use the wide variant, which always returns utf16
751 * (otherwise we'd have to detect current codepage or use W32API character
752 * set conversion routines to convert to UTF8).
753 */
754#ifndef WINDOWS
748 strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", tp); 755 strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", tp);
756#else
757 {
758 static wchar_t wbuf[255];
759 uint8_t *conved;
760 size_t ssize;
761
762 wcsftime (wbuf, sizeof (wbuf) / sizeof (wchar_t),
763 L"%a %b %d %H:%M:%S %Y", tp);
764
765 ssize = sizeof (buf);
766 conved = u16_to_u8 (wbuf, sizeof (wbuf) / sizeof (wchar_t),
767 (uint8_t *) buf, &ssize);
768 if (conved != (uint8_t *) buf)
769 {
770 strncpy (buf, (char *) conved, sizeof (buf));
771 buf[255 - 1] = '\0';
772 free (conved);
773 }
774 }
775#endif
749 return buf; 776 return buf;
750} 777}
751 778