Code

csv plugin: Replace `localtime' with `localtime_r'.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 10 Mar 2007 09:29:18 +0000 (10:29 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 10 Mar 2007 09:29:18 +0000 (10:29 +0100)
src/csv.c

index 268bdbf57447a49325b3fb448e76694a166ada30..f4b56fe0dc9254755f626bc5bf41b9acb2127510 100644 (file)
--- 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);