mirror of
https://github.com/moparisthebest/hexchat
synced 2024-11-26 03:02:17 -05:00
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
This commit is contained in:
parent
41c209bf45
commit
dc27640265
@ -540,7 +540,6 @@ log_create_pathname (char *servname, char *channame, char *netname)
|
|||||||
{
|
{
|
||||||
char fname[384];
|
char fname[384];
|
||||||
char fnametime[384];
|
char fnametime[384];
|
||||||
struct tm *tm;
|
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
if (!netname)
|
if (!netname)
|
||||||
@ -568,8 +567,7 @@ log_create_pathname (char *servname, char *channame, char *netname)
|
|||||||
|
|
||||||
/* insert time/date */
|
/* insert time/date */
|
||||||
now = time (NULL);
|
now = time (NULL);
|
||||||
tm = localtime (&now);
|
strftime_utf8 (fnametime, sizeof (fnametime), fname, now);
|
||||||
strftime_validated (fnametime, sizeof (fnametime), fname, tm);
|
|
||||||
|
|
||||||
/* create final path/filename */
|
/* create final path/filename */
|
||||||
if (logmask_is_fullpath ())
|
if (logmask_is_fullpath ())
|
||||||
|
@ -2203,15 +2203,17 @@ challengeauth_response (char *username, char *password, char *challenge)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Wrapper around strftime for Windows
|
* \brief Wrapper around strftime for Windows
|
||||||
*
|
*
|
||||||
* Prevents crashing when using an invalid format by escaping them.
|
* Prevents crashing when using an invalid format by escaping them.
|
||||||
*
|
*
|
||||||
* Behaves the same as strftime with the addition that
|
* Behaves the same as strftime with the addition that
|
||||||
* it returns 0 if the escaped format string is too large.
|
* it returns 0 if the escaped format string is too large.
|
||||||
*
|
*
|
||||||
* Based upon work from znc-msvc project.
|
* Based upon work from znc-msvc project.
|
||||||
*/
|
*
|
||||||
|
* This assumes format is a locale-encoded string. For utf-8 strings, use strftime_utf8
|
||||||
|
*/
|
||||||
size_t
|
size_t
|
||||||
strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time)
|
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);
|
return strftime (dest, destsize, safe_format, time);
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
@ -82,4 +82,5 @@ char *encode_sasl_pass_blowfish (char *user, char *pass, char *data);
|
|||||||
char *encode_sasl_pass_aes (char *user, char *pass, char *data);
|
char *encode_sasl_pass_aes (char *user, char *pass, char *data);
|
||||||
char *challengeauth_response (char *username, char *password, char *challenge);
|
char *challengeauth_response (char *username, char *password, char *challenge);
|
||||||
size_t strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time);
|
size_t strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time);
|
||||||
|
size_t strftime_utf8 (char *dest, size_t destsize, const char *format, time_t time);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user