From 8170b5ab39f32d6c297e3582666bd29a331946f9 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 10 Mar 2007 10:29:18 +0100 Subject: [PATCH] csv plugin: Replace `localtime' with `localtime_r'. --- src/csv.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/csv.c b/src/csv.c index 268bdbf5..f4b56fe0 100644 --- a/src/csv.c +++ b/src/csv.c @@ -114,18 +114,19 @@ static int value_list_to_filename (char *buffer, int buffer_len, { time_t now; - struct tm *tm; + struct tm stm; - /* TODO: Find a way to minimize the calls to `localtime', since - * they are pretty expensive.. */ + /* TODO: Find a way to minimize the calls to `localtime_r', + * since they are pretty expensive.. */ now = time (NULL); - tm = localtime (&now); + if (localtime_r (&now, &stm) == NULL) + { + syslog (LOG_ERR, "csv plugin: localtime_r failed"); + return (1); + } strftime (buffer + offset, buffer_len - offset, - "-%Y-%m-%d", tm); - - /* `localtime(3)' returns a pointer to static data, - * therefore the pointer may not be free'd. */ + "-%Y-%m-%d", &stm); } return (0); -- 2.11.0