Created
December 11, 2014 03:11
-
-
Save snyh/10bafe0a053c515d9185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/datetime/timezone/timestamp.c b/datetime/timezone/timestamp.c | |
index 6ddb230..53a8857 100644 | |
--- a/datetime/timezone/timestamp.c | |
+++ b/datetime/timezone/timestamp.c | |
@@ -31,7 +31,7 @@ | |
static int isdst_timestamp(time_t t); | |
-DSTTime* | |
+DSTTime | |
get_dst_time(const char *zone, int year) | |
{ | |
register time_t cutlotime; | |
@@ -47,11 +47,12 @@ get_dst_time(const char *zone, int year) | |
register struct tm * tmp; | |
register struct tm * newtmp; | |
static char buf[MAX_STRING_LENGTH]; | |
+ DSTTime ret = {0,0}; | |
char *tz = getenv("TZ"); | |
if (setenv("TZ", zone, 1) != 0 ) { | |
fprintf(stderr, "Set TZ=%s failed\n", zone); | |
- return NULL; | |
+ return ret; | |
} | |
t = absolute_min_time; | |
@@ -63,11 +64,6 @@ get_dst_time(const char *zone, int year) | |
strncpy(buf, abbr(&tm), (sizeof buf) - 1); | |
} | |
- DSTTime *ret = calloc(1, sizeof(DSTTime)); | |
- if (!ret) { | |
- setenv("TZ", tz, 1); | |
- return NULL; | |
- } | |
int enter_flag = 0; | |
for ( ; ; ) { | |
@@ -88,17 +84,17 @@ get_dst_time(const char *zone, int year) | |
if (newtmp != NULL) { | |
if (newtmp->tm_isdst) { | |
if (!enter_flag) { | |
- ret->enter = newt; | |
+ ret.enter = newt; | |
enter_flag = 1; | |
} else { | |
- ret->leave = newt; | |
+ ret.leave = newt; | |
} | |
} else { | |
if (!enter_flag) { | |
- ret->enter = newt-1; | |
+ ret.enter = newt-1; | |
enter_flag = 1; | |
} else { | |
- ret->leave = newt-1; | |
+ ret.leave = newt-1; | |
} | |
} | |
diff --git a/datetime/timezone/timestamp.h b/datetime/timezone/timestamp.h | |
index 3623b54..af3b7ee 100644 | |
--- a/datetime/timezone/timestamp.h | |
+++ b/datetime/timezone/timestamp.h | |
@@ -30,6 +30,6 @@ typedef struct _DSTTime { | |
long long get_rawoffset_time (const char *zone, long long t); | |
long long get_year_begin_time(const char *zone, int year); | |
long getoffset (const char *zone, long long t); | |
-DSTTime* get_dst_time(const char *zone, int year); | |
+DSTTime get_dst_time(const char *zone, int year); | |
#endif | |
diff --git a/datetime/timezone/wrapper.go b/datetime/timezone/wrapper.go | |
index c56b303..d5fd45c 100644 | |
--- a/datetime/timezone/wrapper.go | |
+++ b/datetime/timezone/wrapper.go | |
@@ -35,13 +35,8 @@ func sumDSTTime(zone string, year int32) (int64, int64, bool) { | |
czone := C.CString(zone) | |
ret := C.get_dst_time(czone, C.int(year)) | |
- if ret == nil { | |
- return 0, 0, false | |
- } | |
- | |
t1 := int64(ret.enter) | |
t2 := int64(ret.leave) | |
- C.free(unsafe.Pointer(ret)) | |
if t1 == 0 || t2 == 0 { | |
return 0, 0, false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment