From: Florian Forster Date: Sat, 10 Mar 2007 09:29:18 +0000 (+0100) Subject: csv plugin: Replace `localtime' with `localtime_r'. X-Git-Tag: collectd-4.0.0~164 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8170b5ab39f32d6c297e3582666bd29a331946f9;p=collectd.git csv plugin: Replace `localtime' with `localtime_r'. --- 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);