Fix possible memory leak and add time_t argument in utils_get_date_time() to pass a time pointer to use.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2049 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
31c1cae631
commit
1672c377fe
@ -1,3 +1,10 @@
|
||||
2007-11-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
||||
* src/templates.c, src/utils.c, src/utils.h:
|
||||
Fix possible memory leak and add time_t argument in
|
||||
utils_get_date_time() to pass a time pointer to use.
|
||||
|
||||
|
||||
2007-11-14 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
||||
* plugins/vcdiff.c, plugins/Makefile.am:
|
||||
|
@ -350,8 +350,8 @@ static void create_new_menu_items()
|
||||
|
||||
void templates_init(void)
|
||||
{
|
||||
gchar *year = utils_get_date_time("%Y");
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT);
|
||||
gchar *year = utils_get_date_time("%Y", NULL);
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT, NULL);
|
||||
|
||||
init_general_templates(year, date);
|
||||
init_ft_templates(year, date);
|
||||
@ -523,7 +523,7 @@ gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
|
||||
gchar *template = g_strdup(templates[GEANY_TEMPLATE_FILEHEADER]);
|
||||
gchar *shortname;
|
||||
gchar *result;
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT);
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL);
|
||||
filetype_id ft_id = filetype_idx;
|
||||
filetype *ft = filetypes[ft_id];
|
||||
|
||||
@ -586,8 +586,8 @@ gchar *templates_get_template_generic(gint template)
|
||||
gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name)
|
||||
{
|
||||
gchar *template = g_strdup(templates[GEANY_TEMPLATE_FUNCTION]);
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT);
|
||||
gchar *datetime = utils_get_date_time(TEMPLATE_DATETIME_FORMAT);
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT, NULL);
|
||||
gchar *datetime = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL);
|
||||
gchar *result;
|
||||
|
||||
template = utils_str_replace(template, "{date}", date);
|
||||
@ -605,7 +605,7 @@ gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name
|
||||
|
||||
gchar *templates_get_template_changelog(void)
|
||||
{
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT);
|
||||
gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL);
|
||||
gchar *result = g_strdup(templates[GEANY_TEMPLATE_CHANGELOG]);
|
||||
result = utils_str_replace(result, "{date}", date);
|
||||
|
||||
|
15
src/utils.c
15
src/utils.c
@ -881,15 +881,22 @@ gint utils_strpos(const gchar *haystack, const gchar *needle)
|
||||
}
|
||||
|
||||
|
||||
gchar *utils_get_date_time(const gchar *format)
|
||||
gchar *utils_get_date_time(const gchar *format, time_t *time_to_use)
|
||||
{
|
||||
time_t tp = time(NULL);
|
||||
const struct tm *tm = localtime(&tp);
|
||||
gchar *date = g_malloc0(256);
|
||||
time_t tp;
|
||||
const struct tm *tm;
|
||||
gchar *date;
|
||||
|
||||
if (format == NULL)
|
||||
return NULL;
|
||||
|
||||
if (time_to_use != NULL)
|
||||
tp = *time_to_use;
|
||||
else
|
||||
tp = time(NULL);
|
||||
|
||||
tm = localtime(&tp);
|
||||
date = g_malloc0(256);
|
||||
strftime(date, 256, format, tm);
|
||||
return date;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ gchar *utils_str_replace(gchar *haystack, const gchar *needle, const gchar *repl
|
||||
gint utils_strpos(const gchar* haystack, const gchar * needle);
|
||||
|
||||
|
||||
gchar *utils_get_date_time(const gchar *format);
|
||||
gchar *utils_get_date_time(const gchar *format, time_t *time_to_use);
|
||||
|
||||
gchar *utils_get_initials(gchar *name);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user