|
|
@ -1,11 +1,12 @@ |
|
|
|
From: Joe Orton <jorton@redhat.com> |
|
|
|
Date: Sun, 18 Oct 2015 02:15:17 +0200 |
|
|
|
Date: Thu, 20 Oct 2016 11:44:14 +0200 |
|
|
|
Subject: Add support for use of the system timezone database |
|
|
|
|
|
|
|
Add support for use of the system timezone database, rather |
|
|
|
than embedding a copy. Discussed upstream but was not desired. |
|
|
|
|
|
|
|
History: |
|
|
|
r14: improve check for valid tz file |
|
|
|
r13: adapt for upstream changes to use PHP allocator |
|
|
|
r12: adapt for upstream changes for new zic |
|
|
|
r11: use canonical names to avoid more case sensitivity issues |
|
|
@ -25,12 +26,12 @@ r3: fix a crash if /usr/share/zoneinfo doesn't exist (Raphael Geissert) |
|
|
|
r2: add filesystem trawl to set up name alias index |
|
|
|
r1: initial revision |
|
|
|
---
|
|
|
|
ext/date/lib/parse_tz.c | 549 +++++++++++++++++++++++++++++++++++++++++++++++- |
|
|
|
ext/date/lib/timelib.m4 | 14 ++ |
|
|
|
2 files changed, 552 insertions(+), 11 deletions(-) |
|
|
|
ext/date/lib/parse_tz.c | 560 +++++++++++++++++++++++++++++++++++++++++++++++- |
|
|
|
ext/date/lib/timelib.m4 | 13 ++ |
|
|
|
2 files changed, 562 insertions(+), 11 deletions(-) |
|
|
|
|
|
|
|
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c
|
|
|
|
index 20d7eea..6301dc5 100644
|
|
|
|
index 20d7eea..ed7717e 100644
|
|
|
|
--- a/ext/date/lib/parse_tz.c
|
|
|
|
+++ b/ext/date/lib/parse_tz.c
|
|
|
|
@@ -24,6 +24,16 @@
|
|
|
@ -75,7 +76,7 @@ index 20d7eea..6301dc5 100644 |
|
|
|
/* read ID */ |
|
|
|
version = (*tzf)[3] - '0'; |
|
|
|
*tzf += 4; |
|
|
|
@@ -302,7 +321,418 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
|
|
|
|
@@ -302,7 +321,429 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -294,6 +295,7 @@ index 20d7eea..6301dc5 100644 |
|
|
|
+ && strcmp(ent->d_name, "posix") != 0
|
|
|
|
+ && strcmp(ent->d_name, "posixrules") != 0
|
|
|
|
+ && strcmp(ent->d_name, "right") != 0
|
|
|
|
+ && strstr(ent->d_name, ".list") == NULL
|
|
|
|
+ && strstr(ent->d_name, ".tab") == NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
@ -434,8 +436,18 @@ index 20d7eea..6301dc5 100644 |
|
|
|
+
|
|
|
|
+/* Returns true if the passed-in stat structure describes a
|
|
|
|
+ * probably-valid timezone file. */
|
|
|
|
+static int is_valid_tzfile(const struct stat *st)
|
|
|
|
+static int is_valid_tzfile(const struct stat *st, int fd)
|
|
|
|
+{
|
|
|
|
+ if (fd) {
|
|
|
|
+ char buf[20];
|
|
|
|
+ if (read(fd, buf, 20)!=20) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ lseek(fd, SEEK_SET, 0);
|
|
|
|
+ if (memcmp(buf, "TZif", 4)) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return S_ISREG(st->st_mode) && st->st_size > 20;
|
|
|
|
+}
|
|
|
|
+
|
|
|
@ -473,11 +485,11 @@ index 20d7eea..6301dc5 100644 |
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ fd = open(fname, O_RDONLY);
|
|
|
|
+ if (fd == -1) {
|
|
|
|
+ return NULL;
|
|
|
|
+ } else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st)) {
|
|
|
|
+ } else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st, fd)) {
|
|
|
|
+ close(fd);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
@ -495,7 +507,7 @@ index 20d7eea..6301dc5 100644 |
|
|
|
{ |
|
|
|
int left = 0, right = tzdb->index_size - 1; |
|
|
|
#ifdef HAVE_SETLOCALE |
|
|
|
@@ -341,21 +771,88 @@ static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const
|
|
|
|
@@ -341,21 +782,88 @@ static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
@ -577,7 +589,7 @@ index 20d7eea..6301dc5 100644 |
|
|
|
+
|
|
|
|
+ snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
|
|
|
|
+
|
|
|
|
+ return stat(fname, &st) == 0 && is_valid_tzfile(&st);
|
|
|
|
+ return stat(fname, &st) == 0 && is_valid_tzfile(&st, 0);
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
@ -585,7 +597,7 @@ index 20d7eea..6301dc5 100644 |
|
|
|
} |
|
|
|
|
|
|
|
static void skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) |
|
|
|
@@ -380,24 +877,54 @@ static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz)
|
|
|
|
@@ -380,24 +888,54 @@ static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz)
|
|
|
|
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb) |
|
|
|
{ |
|
|
|
const unsigned char *tzf; |
|
|
@ -650,13 +662,13 @@ index 20d7eea..6301dc5 100644 |
|
|
|
tmp = NULL; |
|
|
|
} |
|
|
|
diff --git a/ext/date/lib/timelib.m4 b/ext/date/lib/timelib.m4
|
|
|
|
index c725572..4c837c7 100644
|
|
|
|
index 99bf9fa..4bf7e46 100644
|
|
|
|
--- a/ext/date/lib/timelib.m4
|
|
|
|
+++ b/ext/date/lib/timelib.m4
|
|
|
|
@@ -78,3 +78,17 @@ stdlib.h
|
|
|
|
@@ -78,3 +78,16 @@ stdlib.h
|
|
|
|
|
|
|
|
dnl Check for strtoll, atoll |
|
|
|
AC_CHECK_FUNCS(strtoll atoll strftime) |
|
|
|
AC_CHECK_FUNCS(strtoll atoll strftime gettimeofday) |
|
|
|
+
|
|
|
|
+PHP_ARG_WITH(system-tzdata, for use of system timezone data,
|
|
|
|
+[ --with-system-tzdata[=DIR] to specify use of system timezone data],
|
|
|
@ -670,4 +682,3 @@ index c725572..4c837c7 100644 |
|
|
|
+ [Define for location of system timezone data])
|
|
|
|
+ fi
|
|
|
|
+fi
|
|
|
|
+
|