int get_stamp_str (char *fmt, time_t tim, char **ret) { char *loc = NULL; char dest[128]; gsize len; /* strftime wants the format string in LOCALE! */ if (!prefs.utf8_locale) { const gchar *charset; g_get_charset (&charset); loc = g_convert_with_fallback (fmt, -1, charset, "UTF-8", "?", 0, 0, 0); if (loc) fmt = loc; } len = strftime_validated (dest, sizeof (dest), fmt, localtime (&tim)); if (len) { if (prefs.utf8_locale) *ret = g_strdup (dest); else *ret = g_locale_to_utf8 (dest, len, 0, &len, 0); } if (loc) g_free (loc); return len; }
int get_stamp_str (char *fmt, time_t tim, char **ret) { char dest[128]; gsize len_locale; gsize len_utf8; /* strftime requires the format string to be in locale encoding. */ fmt = g_locale_from_utf8 (fmt, -1, NULL, NULL, NULL); len_locale = strftime_validated (dest, sizeof (dest), fmt, localtime (&tim)); g_free (fmt); if (len_locale == 0) { return 0; } *ret = g_locale_to_utf8 (dest, len_locale, NULL, &len_utf8, NULL); if (*ret == NULL) { return 0; } return len_utf8; }
static char * log_create_pathname (char *servname, char *channame, char *netname) { char fname[384]; char fnametime[384]; struct tm *tm; time_t now; if (!netname) { netname = strdup ("NETWORK"); } else { netname = log_create_filename (netname); } /* first, everything is in UTF-8 */ if (!rfc_casecmp (channame, servname)) { channame = strdup ("server"); } else { channame = log_create_filename (channame); } log_insert_vars (fname, sizeof (fname), prefs.pchat_irc_logmask, channame, netname, servname); free (channame); free (netname); /* insert time/date */ now = time (NULL); tm = localtime (&now); strftime_validated (fnametime, sizeof (fnametime), fname, tm); /* If one uses log mask variables, such as "%c/...", %c will be empty upon * connecting since there's no channel name yet, so we have to make sure * we won't try to write to the FS root. */ if (g_path_is_absolute (prefs.pchat_irc_logmask)) { g_snprintf (fname, sizeof (fname), "%s", fnametime); } else /* relative path */ { g_snprintf (fname, sizeof (fname), "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s", get_xdir (), fnametime); } /* create all the subdirectories */ mkdir_p (fname); return g_strdup(fname); }
static char * log_create_pathname (char *servname, char *channame, char *netname) { char fname[384]; char fnametime[384]; struct tm *tm; time_t now; if (!netname) { netname = strdup ("NETWORK"); } else { netname = log_create_filename (netname); } /* first, everything is in UTF-8 */ if (!rfc_casecmp (channame, servname)) { channame = strdup ("server"); } else { channame = log_create_filename (channame); } log_insert_vars (fname, sizeof (fname), prefs.hex_irc_logmask, channame, netname, servname); free (channame); free (netname); /* insert time/date */ now = time (NULL); tm = localtime (&now); strftime_validated (fnametime, sizeof (fnametime), fname, tm); /* create final path/filename */ if (logmask_is_fullpath ()) { snprintf (fname, sizeof (fname), "%s", fnametime); } else /* relative path */ { snprintf (fname, sizeof (fname), "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s", get_xdir (), fnametime); } /* create all the subdirectories */ mkdir_p (fname); return g_strdup(fname); }
static int get_stamp_str (time_t tim, char *dest, int size) { return strftime_validated (dest, size, prefs.pchat_stamp_text_format, localtime (&tim)); }