@@ -0,0 +1,608 @@
+
+Add support for use of the system timezone database, rather
+than embedding a copy. Discussed upstream but was not desired.
+
+History:
+r6: fix fd leak in r5, fix country code/BC flag use in
+ timezone_identifiers_list() using system db,
+ fix use of PECL timezonedb to override system db,
+r5: reverts addition of "System/Localtime" fake tzname.
+ updated for 5.3.0, parses zone.tab to pick up mapping between
+ timezone name, country code and long/lat coords
+r4: added "System/Localtime" tzname which uses /etc/localtime
+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
+
+Index: ext/date/lib/timelib.m4
+===================================================================
+--- php-5.3.0/ext/date/lib/parse_tz.c.systzdata
++++ php-5.3.0/ext/date/lib/parse_tz.c
+@@ -20,6 +20,16 @@
+
+ #include "timelib.h"
+
++#ifdef HAVE_SYSTEM_TZDATA
++#include <sys/mman.h>
++#include <sys/stat.h>
++#include <limits.h>
++#include <fcntl.h>
++#include <unistd.h>
++
++#include "php_scandir.h"
++#endif
++
+ #include <stdio.h>
+
+ #ifdef HAVE_LOCALE_H
+@@ -31,7 +41,12 @@
+ #else
+ #include <strings.h>
+ #endif
++
++#ifndef HAVE_SYSTEM_TZDATA
+ #include "timezonedb.h"
++#endif
++
++#include <ctype.h>
+
+ #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
+ # if defined(__LITTLE_ENDIAN__)
+@@ -51,9 +66,14 @@
+
+ static void read_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
+ {
+- /* skip ID */
+- *tzf += 4;
+-
++ if (memcmp(tzf, "TZif", 4) == 0) {
++ *tzf += 20;
++ return;
++ }
++
++ /* skip ID */
++ *tzf += 4;
++
+ /* read BC flag */
+ tz->bc = (**tzf == '\1');
+ *tzf += 1;
+@@ -253,7 +273,390 @@ void timelib_dump_tzinfo(timelib_tzinfo
+ }
+ }
+
+-static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const timelib_tzdb *tzdb)
++#ifdef HAVE_SYSTEM_TZDATA
++
++#ifdef HAVE_SYSTEM_TZDATA_PREFIX
++#define ZONEINFO_PREFIX HAVE_SYSTEM_TZDATA_PREFIX
++#else
++#define ZONEINFO_PREFIX "/usr/share/zoneinfo"
++#endif
++
++/* System timezone database pointer. */
++static const timelib_tzdb *timezonedb_system = NULL;
++
++/* Hash table entry for the cache of the zone.tab mapping table. */
++struct location_info {
++ char code[2];
++ double latitude, longitude;
++ char name[64];
++ char *comment;
++ struct location_info *next;
++};
++
++/* Cache of zone.tab. */
++static struct location_info **system_location_table;
++
++/* Size of the zone.tab hash table; a random-ish prime big enough to
++ * prevent too many collisions. */
++#define LOCINFO_HASH_SIZE (1021)
++
++static uint32_t tz_hash(const char *str)
++{
++ const unsigned char *p = (const unsigned char *)str;
++ uint32_t hash = 5381;
++ int c;
++
++ while ((c = *p++) != '\0') {
++ hash = (hash << 5) ^ hash ^ c;
++ }
++
++ return hash % LOCINFO_HASH_SIZE;
++}
++
++/* Parse an ISO-6709 date as used in zone.tab. Returns end of the
++ * parsed string on success, or NULL on parse error. On success,
++ * writes the parsed number to *result. */
++static char *parse_iso6709(char *p, double *result)
++{
++ double v, sign;
++ char *pend;
++ size_t len;
++
++ if (*p == '+')
++ sign = 1.0;
++ else if (*p == '-')
++ sign = -1.0;
++ else
++ return NULL;
++
++ p++;
++ for (pend = p; *pend >= '0' && *pend <= '9'; pend++)
++ ;;
++
++ /* Annoying encoding used by zone.tab has no decimal point, so use
++ * the length to determine the format:
++ *
++ * 4 = DDMM
++ * 5 = DDDMM
++ * 6 = DDMMSS
++ * 7 = DDDMMSS
++ */
++ len = pend - p;
++ if (len < 4 || len > 7) {
++ return NULL;
++ }
++
++ /* p => [D]DD */
++ v = (p[0] - '0') * 10.0 + (p[1] - '0');
++ p += 2;
++ if (len == 5 || len == 7)
++ v = v * 10.0 + (*p++ - '0');
++ /* p => MM[SS] */
++ v += (10.0 * (p[0] - '0')
++ + p[1] - '0') / 60.0;
++ p += 2;
++ /* p => [SS] */
++ if (len > 5) {
++ v += (10.0 * (p[0] - '0')
++ + p[1] - '0') / 3600.0;
++ p += 2;
++ }
++
++ /* Round to five decimal place, not because it's a good idea,
++ * but, because the builtin data uses rounded data, so, match
++ * that. */
++ *result = round(v * sign * 100000.0) / 100000.0;
++
++ return p;
++}
++
++/* This function parses the zone.tab file to build up the mapping of
++ * timezone to country code and geographic location, and returns a
++ * hash table. The hash table is indexed by the function:
++ *
++ * tz_hash(timezone-name)
++ */
++static struct location_info **create_location_table(void)
++{
++ struct location_info **li, *i;
++ char zone_tab[PATH_MAX];
++ char line[512];
++ FILE *fp;
++
++ strncpy(zone_tab, ZONEINFO_PREFIX "/zone.tab", sizeof zone_tab);
++
++ fp = fopen(zone_tab, "r");
++ if (!fp) {
++ return NULL;
++ }
++
++ li = calloc(LOCINFO_HASH_SIZE, sizeof *li);
++
++ while (fgets(line, sizeof line, fp)) {
++ char *p = line, *code, *name, *comment;
++ uint32_t hash;
++ double latitude, longitude;
++
++ while (isspace(*p))
++ p++;
|