summaryrefslogtreecommitdiff
path: root/time/ical/patches/patch-time_Time.C
blob: c0fdfc2500c2df2c596e1e6b6c144fa590788be9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$NetBSD: patch-time_Time.C,v 1.1 2013/01/09 17:22:14 is Exp $

--- time/Time.C.orig	2009-01-18 13:18:20.000000000 +0000
+++ time/Time.C
@@ -4,7 +4,6 @@
 #include <sys/types.h>
 #include <math.h>
 #include <string.h>
-#include <alloca.h>
 #include <stdlib.h>
 
 #include "config.h"
@@ -54,13 +53,13 @@ void Time::BreakDown(int& mday, WeekDay&
                      int& hour, int& min, int& sec, int& milli,
                      const char *tz) const
 {
-    const char *old;
+    char *old;
     if (! initialized) Initialize();
 
     time_t clock = (time_t) round(rep + offset);
 
     if (tz) {
-        if ((old=getenv("TZ"))) old=strdupa(old);
+        if ((old=getenv("TZ"))) old=strdup(old);
         setenv("TZ", tz, 1);
         tzset();
     }
@@ -80,6 +79,8 @@ void Time::BreakDown(int& mday, WeekDay&
     min   = t->tm_min;
     sec   = t->tm_sec;
     milli = (int)round((rep - floor(rep)) * 1000);
+
+    if(tz) free(old);
 }
 
 Time::Time(const struct timeval& tv) {
@@ -96,8 +97,8 @@ void Time::Convert(struct timeval& tv) c
 
 #if 0
 time_t timezone_to_local(time_t clock, const char *tz) {
-    const char *old=getenv("TZ");
-    if (old) old=strdupa(old);
+    char *old=getenv("TZ");
+    if (old) old=strdup(old);
     
     struct tm* t = localtime(&clock);
     setenv("TZ", tz, 1);
@@ -107,12 +108,13 @@ time_t timezone_to_local(time_t clock, c
     if (old) setenv("TZ", old, 1); else unsetenv("TZ");
     tzset();
 
+    if(old) free(old);
     return clock;
 }
 
 time_t local_to_timezone(time_t clock, const char *tz) {
-    const char *old=getenv("TZ");
-    if (old) old=strdupa(old);
+    char *old=getenv("TZ");
+    if (old) old=strdup(old);
     
     setenv("TZ", tz, 1);
     tzset();
@@ -122,6 +124,7 @@ time_t local_to_timezone(time_t clock, c
     tzset();
     clock = mktime(t);
 
+    if (old) free(old);
     return clock;
 }
 #endif