diff options
author | Arnavion <arnavion@gmail.com> | 2014-04-21 01:39:28 -0700 |
---|---|---|
committer | Arnavion <arnavion@gmail.com> | 2014-04-21 01:39:28 -0700 |
commit | dc27640265dcbe480ad137831f3a22f35bd07b51 (patch) | |
tree | d80b5b4cbe641d094a6ee71f4fd1f25b8154fd1d /src/common/util.c | |
parent | 41c209bf45ce1a926c526959cae2dc94fec7c0b9 (diff) |
Use utf-8 variant of strftime to format log file paths.
strftime assumes the format string is in locale encoding, which mangles log file paths that are in utf-8. Fixes #767 Fixes #945
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/common/util.c b/src/common/util.c index dec9d4df..0549bd6e 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2203,15 +2203,17 @@ challengeauth_response (char *username, char *password, char *challenge) #endif /** -* \brief Wrapper around strftime for Windows -* -* Prevents crashing when using an invalid format by escaping them. -* -* Behaves the same as strftime with the addition that -* it returns 0 if the escaped format string is too large. -* -* Based upon work from znc-msvc project. -*/ + * \brief Wrapper around strftime for Windows + * + * Prevents crashing when using an invalid format by escaping them. + * + * Behaves the same as strftime with the addition that + * it returns 0 if the escaped format string is too large. + * + * Based upon work from znc-msvc project. + * + * This assumes format is a locale-encoded string. For utf-8 strings, use strftime_utf8 + */ size_t strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time) { @@ -2278,3 +2280,17 @@ strftime_validated (char *dest, size_t destsize, const char *format, const struc return strftime (dest, destsize, safe_format, time); #endif } + +/** + * \brief Similar to strftime except it works with utf-8 formats, since strftime treats the format as locale-encoded. + */ +gsize +strftime_utf8 (char *dest, gsize destsize, const char *format, time_t time) +{ + gsize result; + GDate* date = g_date_new (); + g_date_set_time_t (date, time); + result = g_date_strftime (dest, destsize, format, date); + g_date_free (date); + return result; +} |