You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

665 lines
18 KiB

  1. From: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
  2. Date: Thu, 7 Mar 2019 19:42:35 +0000
  3. Subject: Add-support-for-use-of-the-system-timezone-database
  4. # License: MIT
  5. # http://opensource.org/licenses/MIT
  6. # License: MIT
  7. # http://opensource.org/licenses/MIT
  8. Add support for use of the system timezone database, rather
  9. than embedding a copy. Discussed upstream but was not desired.
  10. History:
  11. r18: adapt for autotool change in 7.3.3RC1
  12. r17: adapt for timelib 2018.01 (in 7.3.2RC1)
  13. r16: adapt for timelib 2017.06 (in 7.2.3RC1)
  14. r15: adapt for timelib 2017.05beta7 (in 7.2.0RC1)
  15. r14: improve check for valid tz file
  16. r13: adapt for upstream changes to use PHP allocator
  17. r12: adapt for upstream changes for new zic
  18. r11: use canonical names to avoid more case sensitivity issues
  19. round lat/long from zone.tab towards zero per builtin db
  20. r10: make timezone case insensitive
  21. r9: fix another compile error without --with-system-tzdata configured (Michael Heimpold)
  22. r8: fix compile error without --with-system-tzdata configured
  23. r7: improve check for valid timezone id to exclude directories
  24. r6: fix fd leak in r5, fix country code/BC flag use in
  25. timezone_identifiers_list() using system db,
  26. fix use of PECL timezonedb to override system db,
  27. r5: reverts addition of "System/Localtime" fake tzname.
  28. updated for 5.3.0, parses zone.tab to pick up mapping between
  29. timezone name, country code and long/lat coords
  30. r4: added "System/Localtime" tzname which uses /etc/localtime
  31. r3: fix a crash if /usr/share/zoneinfo doesn't exist (Raphael Geissert)
  32. r2: add filesystem trawl to set up name alias index
  33. r1: initial revision
  34. ---
  35. ext/date/config0.m4 | 13 ++
  36. ext/date/lib/parse_tz.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++-
  37. 2 files changed, 545 insertions(+), 3 deletions(-)
  38. --- a/ext/date/config0.m4
  39. +++ b/ext/date/config0.m4
  40. @@ -4,6 +4,19 @@ AC_CHECK_HEADERS([io.h])
  41. dnl Check for strtoll, atoll
  42. AC_CHECK_FUNCS(strtoll atoll)
  43. +PHP_ARG_WITH(system-tzdata, for use of system timezone data,
  44. +[ --with-system-tzdata[=DIR] to specify use of system timezone data],
  45. +no, no)
  46. +
  47. +if test "$PHP_SYSTEM_TZDATA" != "no"; then
  48. + AC_DEFINE(HAVE_SYSTEM_TZDATA, 1, [Define if system timezone data is used])
  49. +
  50. + if test "$PHP_SYSTEM_TZDATA" != "yes"; then
  51. + AC_DEFINE_UNQUOTED(HAVE_SYSTEM_TZDATA_PREFIX, "$PHP_SYSTEM_TZDATA",
  52. + [Define for location of system timezone data])
  53. + fi
  54. +fi
  55. +
  56. PHP_DATE_CFLAGS="-I@ext_builddir@/lib -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DHAVE_TIMELIB_CONFIG_H=1"
  57. timelib_sources="lib/astro.c lib/dow.c lib/parse_date.c lib/parse_tz.c
  58. lib/timelib.c lib/tm2unixtime.c lib/unixtime2tm.c lib/parse_iso_intervals.c lib/interval.c"
  59. --- a/ext/date/lib/parse_tz.c
  60. +++ b/ext/date/lib/parse_tz.c
  61. @@ -26,8 +26,21 @@
  62. #include "timelib.h"
  63. #include "timelib_private.h"
  64. +#ifdef HAVE_SYSTEM_TZDATA
  65. +#include <sys/mman.h>
  66. +#include <sys/stat.h>
  67. +#include <limits.h>
  68. +#include <fcntl.h>
  69. +#include <unistd.h>
  70. +
  71. +#include "php_scandir.h"
  72. +
  73. +#else
  74. #define TIMELIB_SUPPORTS_V2DATA
  75. #include "timezonedb.h"
  76. +#endif
  77. +
  78. +#include <ctype.h>
  79. #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
  80. # if defined(__LITTLE_ENDIAN__)
  81. @@ -88,6 +101,11 @@ static int read_php_preamble(const unsig
  82. {
  83. uint32_t version;
  84. + if (memcmp(*tzf, "TZif", 4) == 0) {
  85. + *tzf += 20;
  86. + return 0;
  87. + }
  88. +
  89. /* read ID */
  90. version = (*tzf)[3] - '0';
  91. *tzf += 4;
  92. @@ -412,7 +430,429 @@ void timelib_dump_tzinfo(timelib_tzinfo
  93. }
  94. }
  95. -static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const timelib_tzdb *tzdb)
  96. +#ifdef HAVE_SYSTEM_TZDATA
  97. +
  98. +#ifdef HAVE_SYSTEM_TZDATA_PREFIX
  99. +#define ZONEINFO_PREFIX HAVE_SYSTEM_TZDATA_PREFIX
  100. +#else
  101. +#define ZONEINFO_PREFIX "/usr/share/zoneinfo"
  102. +#endif
  103. +
  104. +/* System timezone database pointer. */
  105. +static const timelib_tzdb *timezonedb_system;
  106. +
  107. +/* Hash table entry for the cache of the zone.tab mapping table. */
  108. +struct location_info {
  109. + char code[2];
  110. + double latitude, longitude;
  111. + char name[64];
  112. + char *comment;
  113. + struct location_info *next;
  114. +};
  115. +
  116. +/* Cache of zone.tab. */
  117. +static struct location_info **system_location_table;
  118. +
  119. +/* Size of the zone.tab hash table; a random-ish prime big enough to
  120. + * prevent too many collisions. */
  121. +#define LOCINFO_HASH_SIZE (1021)
  122. +
  123. +/* Compute a case insensitive hash of str */
  124. +static uint32_t tz_hash(const char *str)
  125. +{
  126. + const unsigned char *p = (const unsigned char *)str;
  127. + uint32_t hash = 5381;
  128. + int c;
  129. +
  130. + while ((c = tolower(*p++)) != '\0') {
  131. + hash = (hash << 5) ^ hash ^ c;
  132. + }
  133. +
  134. + return hash % LOCINFO_HASH_SIZE;
  135. +}
  136. +
  137. +/* Parse an ISO-6709 date as used in zone.tab. Returns end of the
  138. + * parsed string on success, or NULL on parse error. On success,
  139. + * writes the parsed number to *result. */
  140. +static char *parse_iso6709(char *p, double *result)
  141. +{
  142. + double v, sign;
  143. + char *pend;
  144. + size_t len;
  145. +
  146. + if (*p == '+')
  147. + sign = 1.0;
  148. + else if (*p == '-')
  149. + sign = -1.0;
  150. + else
  151. + return NULL;
  152. +
  153. + p++;
  154. + for (pend = p; *pend >= '0' && *pend <= '9'; pend++)
  155. + ;;
  156. +
  157. + /* Annoying encoding used by zone.tab has no decimal point, so use
  158. + * the length to determine the format:
  159. + *
  160. + * 4 = DDMM
  161. + * 5 = DDDMM
  162. + * 6 = DDMMSS
  163. + * 7 = DDDMMSS
  164. + */
  165. + len = pend - p;
  166. + if (len < 4 || len > 7) {
  167. + return NULL;
  168. + }
  169. +
  170. + /* p => [D]DD */
  171. + v = (p[0] - '0') * 10.0 + (p[1] - '0');
  172. + p += 2;
  173. + if (len == 5 || len == 7)
  174. + v = v * 10.0 + (*p++ - '0');
  175. + /* p => MM[SS] */
  176. + v += (10.0 * (p[0] - '0')
  177. + + p[1] - '0') / 60.0;
  178. + p += 2;
  179. + /* p => [SS] */
  180. + if (len > 5) {
  181. + v += (10.0 * (p[0] - '0')
  182. + + p[1] - '0') / 3600.0;
  183. + p += 2;
  184. + }
  185. +
  186. + /* Round to five decimal place, not because it's a good idea,
  187. + * but, because the builtin data uses rounded data, so, match
  188. + * that. */
  189. + *result = trunc(v * sign * 100000.0) / 100000.0;
  190. +
  191. + return p;
  192. +}
  193. +
  194. +/* This function parses the zone.tab file to build up the mapping of
  195. + * timezone to country code and geographic location, and returns a
  196. + * hash table. The hash table is indexed by the function:
  197. + *
  198. + * tz_hash(timezone-name)
  199. + */
  200. +static struct location_info **create_location_table(void)
  201. +{
  202. + struct location_info **li, *i;
  203. + char zone_tab[PATH_MAX];
  204. + char line[512];
  205. + FILE *fp;
  206. +
  207. + strncpy(zone_tab, ZONEINFO_PREFIX "/zone.tab", sizeof zone_tab);
  208. +
  209. + fp = fopen(zone_tab, "r");
  210. + if (!fp) {
  211. + return NULL;
  212. + }
  213. +
  214. + li = calloc(LOCINFO_HASH_SIZE, sizeof *li);
  215. +
  216. + while (fgets(line, sizeof line, fp)) {
  217. + char *p = line, *code, *name, *comment;
  218. + uint32_t hash;
  219. + double latitude, longitude;
  220. +
  221. + while (isspace(*p))
  222. + p++;
  223. +
  224. + if (*p == '#' || *p == '\0' || *p == '\n')
  225. + continue;
  226. +
  227. + if (!isalpha(p[0]) || !isalpha(p[1]) || p[2] != '\t')
  228. + continue;
  229. +
  230. + /* code => AA */
  231. + code = p;
  232. + p[2] = 0;
  233. + p += 3;
  234. +
  235. + /* coords => [+-][D]DDMM[SS][+-][D]DDMM[SS] */
  236. + p = parse_iso6709(p, &latitude);
  237. + if (!p) {
  238. + continue;
  239. + }
  240. + p = parse_iso6709(p, &longitude);
  241. + if (!p) {
  242. + continue;
  243. + }
  244. +
  245. + if (!p || *p != '\t') {
  246. + continue;
  247. + }
  248. +
  249. + /* name = string */
  250. + name = ++p;
  251. + while (*p != '\t' && *p && *p != '\n')
  252. + p++;
  253. +
  254. + *p++ = '\0';
  255. +
  256. + /* comment = string */
  257. + comment = p;
  258. + while (*p != '\t' && *p && *p != '\n')
  259. + p++;
  260. +
  261. + if (*p == '\n' || *p == '\t')
  262. + *p = '\0';
  263. +
  264. + hash = tz_hash(name);
  265. + i = malloc(sizeof *i);
  266. + memcpy(i->code, code, 2);
  267. + strncpy(i->name, name, sizeof i->name);
  268. + i->comment = strdup(comment);
  269. + i->longitude = longitude;
  270. + i->latitude = latitude;
  271. + i->next = li[hash];
  272. + li[hash] = i;
  273. + /* printf("%s [%u, %f, %f]\n", name, hash, latitude, longitude); */
  274. + }
  275. +
  276. + fclose(fp);
  277. +
  278. + return li;
  279. +}
  280. +
  281. +/* Return location info from hash table, using given timezone name.
  282. + * Returns NULL if the name could not be found. */
  283. +const struct location_info *find_zone_info(struct location_info **li,
  284. + const char *name)
  285. +{
  286. + uint32_t hash = tz_hash(name);
  287. + const struct location_info *l;
  288. +
  289. + if (!li) {
  290. + return NULL;
  291. + }
  292. +
  293. + for (l = li[hash]; l; l = l->next) {
  294. + if (timelib_strcasecmp(l->name, name) == 0)
  295. + return l;
  296. + }
  297. +
  298. + return NULL;
  299. +}
  300. +
  301. +/* Filter out some non-tzdata files and the posix/right databases, if
  302. + * present. */
  303. +static int index_filter(const struct dirent *ent)
  304. +{
  305. + return strcmp(ent->d_name, ".") != 0
  306. + && strcmp(ent->d_name, "..") != 0
  307. + && strcmp(ent->d_name, "posix") != 0
  308. + && strcmp(ent->d_name, "posixrules") != 0
  309. + && strcmp(ent->d_name, "right") != 0
  310. + && strstr(ent->d_name, ".list") == NULL
  311. + && strstr(ent->d_name, ".tab") == NULL;
  312. +}
  313. +
  314. +static int sysdbcmp(const void *first, const void *second)
  315. +{
  316. + const timelib_tzdb_index_entry *alpha = first, *beta = second;
  317. +
  318. + return timelib_strcasecmp(alpha->id, beta->id);
  319. +}
  320. +
  321. +
  322. +/* Create the zone identifier index by trawling the filesystem. */
  323. +static void create_zone_index(timelib_tzdb *db)
  324. +{
  325. + size_t dirstack_size, dirstack_top;
  326. + size_t index_size, index_next;
  327. + timelib_tzdb_index_entry *db_index;
  328. + char **dirstack;
  329. +
  330. + /* LIFO stack to hold directory entries to scan; each slot is a
  331. + * directory name relative to the zoneinfo prefix. */
  332. + dirstack_size = 32;
  333. + dirstack = malloc(dirstack_size * sizeof *dirstack);
  334. + dirstack_top = 1;
  335. + dirstack[0] = strdup("");
  336. +
  337. + /* Index array. */
  338. + index_size = 64;
  339. + db_index = malloc(index_size * sizeof *db_index);
  340. + index_next = 0;
  341. +
  342. + do {
  343. + struct dirent **ents;
  344. + char name[PATH_MAX], *top;
  345. + int count;
  346. +
  347. + /* Pop the top stack entry, and iterate through its contents. */
  348. + top = dirstack[--dirstack_top];
  349. + snprintf(name, sizeof name, ZONEINFO_PREFIX "/%s", top);
  350. +
  351. + count = php_scandir(name, &ents, index_filter, php_alphasort);
  352. +
  353. + while (count > 0) {
  354. + struct stat st;
  355. + const char *leaf = ents[count - 1]->d_name;
  356. +
  357. + snprintf(name, sizeof name, ZONEINFO_PREFIX "/%s/%s",
  358. + top, leaf);
  359. +
  360. + if (strlen(name) && stat(name, &st) == 0) {
  361. + /* Name, relative to the zoneinfo prefix. */
  362. + const char *root = top;
  363. +
  364. + if (root[0] == '/') root++;
  365. +
  366. + snprintf(name, sizeof name, "%s%s%s", root,
  367. + *root ? "/": "", leaf);
  368. +
  369. + if (S_ISDIR(st.st_mode)) {
  370. + if (dirstack_top == dirstack_size) {
  371. + dirstack_size *= 2;
  372. + dirstack = realloc(dirstack,
  373. + dirstack_size * sizeof *dirstack);
  374. + }
  375. + dirstack[dirstack_top++] = strdup(name);
  376. + }
  377. + else {
  378. + if (index_next == index_size) {
  379. + index_size *= 2;
  380. + db_index = realloc(db_index,
  381. + index_size * sizeof *db_index);
  382. + }
  383. +
  384. + db_index[index_next++].id = strdup(name);
  385. + }
  386. + }
  387. +
  388. + free(ents[--count]);
  389. + }
  390. +
  391. + if (count != -1) free(ents);
  392. + free(top);
  393. + } while (dirstack_top);
  394. +
  395. + qsort(db_index, index_next, sizeof *db_index, sysdbcmp);
  396. +
  397. + db->index = db_index;
  398. + db->index_size = index_next;
  399. +
  400. + free(dirstack);
  401. +}
  402. +
  403. +#define FAKE_HEADER "1234\0??\1??"
  404. +#define FAKE_UTC_POS (7 - 4)
  405. +
  406. +/* Create a fake data segment for database 'sysdb'. */
  407. +static void fake_data_segment(timelib_tzdb *sysdb,
  408. + struct location_info **info)
  409. +{
  410. + size_t n;
  411. + char *data, *p;
  412. +
  413. + data = malloc(3 * sysdb->index_size + 7);
  414. +
  415. + p = mempcpy(data, FAKE_HEADER, sizeof(FAKE_HEADER) - 1);
  416. +
  417. + for (n = 0; n < sysdb->index_size; n++) {
  418. + const struct location_info *li;
  419. + timelib_tzdb_index_entry *ent;
  420. +
  421. + ent = (timelib_tzdb_index_entry *)&sysdb->index[n];
  422. +
  423. + /* Lookup the timezone name in the hash table. */
  424. + if (strcmp(ent->id, "UTC") == 0) {
  425. + ent->pos = FAKE_UTC_POS;
  426. + continue;
  427. + }
  428. +
  429. + li = find_zone_info(info, ent->id);
  430. + if (li) {
  431. + /* If found, append the BC byte and the
  432. + * country code; set the position for this
  433. + * section of timezone data. */
  434. + ent->pos = (p - data) - 4;
  435. + *p++ = '\1';
  436. + *p++ = li->code[0];
  437. + *p++ = li->code[1];
  438. + }
  439. + else {
  440. + /* If not found, the timezone data can
  441. + * point at the header. */
  442. + ent->pos = 0;
  443. + }
  444. + }
  445. +
  446. + sysdb->data = (unsigned char *)data;
  447. +}
  448. +
  449. +/* Returns true if the passed-in stat structure describes a
  450. + * probably-valid timezone file. */
  451. +static int is_valid_tzfile(const struct stat *st, int fd)
  452. +{
  453. + if (fd) {
  454. + char buf[20];
  455. + if (read(fd, buf, 20)!=20) {
  456. + return 0;
  457. + }
  458. + lseek(fd, SEEK_SET, 0);
  459. + if (memcmp(buf, "TZif", 4)) {
  460. + return 0;
  461. + }
  462. + }
  463. + return S_ISREG(st->st_mode) && st->st_size > 20;
  464. +}
  465. +
  466. +/* To allow timezone names to be used case-insensitively, find the
  467. + * canonical name for this timezone, if possible. */
  468. +static const char *canonical_tzname(const char *timezone)
  469. +{
  470. + if (timezonedb_system) {
  471. + timelib_tzdb_index_entry *ent, lookup;
  472. +
  473. + lookup.id = (char *)timezone;
  474. +
  475. + ent = bsearch(&lookup, timezonedb_system->index,
  476. + timezonedb_system->index_size, sizeof lookup,
  477. + sysdbcmp);
  478. + if (ent) {
  479. + return ent->id;
  480. + }
  481. + }
  482. +
  483. + return timezone;
  484. +}
  485. +
  486. +/* Return the mmap()ed tzfile if found, else NULL. On success, the
  487. + * length of the mapped data is placed in *length. */
  488. +static char *map_tzfile(const char *timezone, size_t *length)
  489. +{
  490. + char fname[PATH_MAX];
  491. + struct stat st;
  492. + char *p;
  493. + int fd;
  494. +
  495. + if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) {
  496. + return NULL;
  497. + }
  498. +
  499. + snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
  500. +
  501. + fd = open(fname, O_RDONLY);
  502. + if (fd == -1) {
  503. + return NULL;
  504. + } else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st, fd)) {
  505. + close(fd);
  506. + return NULL;
  507. + }
  508. +
  509. + *length = st.st_size;
  510. + p = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
  511. + close(fd);
  512. +
  513. + return p != MAP_FAILED ? p : NULL;
  514. +}
  515. +
  516. +#endif
  517. +
  518. +static int inmem_seek_to_tz_position(const unsigned char **tzf, char *timezone, const timelib_tzdb *tzdb)
  519. {
  520. int left = 0, right = tzdb->index_size - 1;
  521. @@ -438,9 +878,48 @@ static int seek_to_tz_position(const uns
  522. return 0;
  523. }
  524. +static int seek_to_tz_position(const unsigned char **tzf, char *timezone,
  525. + char **map, size_t *maplen,
  526. + const timelib_tzdb *tzdb)
  527. +{
  528. +#ifdef HAVE_SYSTEM_TZDATA
  529. + if (tzdb == timezonedb_system) {
  530. + char *orig;
  531. +
  532. + orig = map_tzfile(timezone, maplen);
  533. + if (orig == NULL) {
  534. + return 0;
  535. + }
  536. +
  537. + (*tzf) = (unsigned char *)orig;
  538. + *map = orig;
  539. + return 1;
  540. + }
  541. + else
  542. +#endif
  543. + {
  544. + return inmem_seek_to_tz_position(tzf, timezone, tzdb);
  545. + }
  546. +}
  547. +
  548. const timelib_tzdb *timelib_builtin_db(void)
  549. {
  550. +#ifdef HAVE_SYSTEM_TZDATA
  551. + if (timezonedb_system == NULL) {
  552. + timelib_tzdb *tmp = malloc(sizeof *tmp);
  553. +
  554. + tmp->version = "0.system";
  555. + tmp->data = NULL;
  556. + create_zone_index(tmp);
  557. + system_location_table = create_location_table();
  558. + fake_data_segment(tmp, system_location_table);
  559. + timezonedb_system = tmp;
  560. + }
  561. +
  562. + return timezonedb_system;
  563. +#else
  564. return &timezonedb_builtin;
  565. +#endif
  566. }
  567. const timelib_tzdb_index_entry *timelib_timezone_identifiers_list(const timelib_tzdb *tzdb, int *count)
  568. @@ -452,7 +931,30 @@ const timelib_tzdb_index_entry *timelib_
  569. int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
  570. {
  571. const unsigned char *tzf;
  572. - return (seek_to_tz_position(&tzf, timezone, tzdb));
  573. +
  574. +#ifdef HAVE_SYSTEM_TZDATA
  575. + if (tzdb == timezonedb_system) {
  576. + char fname[PATH_MAX];
  577. + struct stat st;
  578. +
  579. + if (timezone[0] == '\0' || strstr(timezone, "..") != NULL) {
  580. + return 0;
  581. + }
  582. +
  583. + if (system_location_table) {
  584. + if (find_zone_info(system_location_table, timezone) != NULL) {
  585. + /* found in cache */
  586. + return 1;
  587. + }
  588. + }
  589. +
  590. + snprintf(fname, sizeof fname, ZONEINFO_PREFIX "/%s", canonical_tzname(timezone));
  591. +
  592. + return stat(fname, &st) == 0 && is_valid_tzfile(&st, 0);
  593. + }
  594. +#endif
  595. +
  596. + return (inmem_seek_to_tz_position(&tzf, timezone, tzdb));
  597. }
  598. static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
  599. @@ -494,12 +996,14 @@ static timelib_tzinfo* timelib_tzinfo_ct
  600. timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb, int *error_code)
  601. {
  602. const unsigned char *tzf;
  603. + char *memmap = NULL;
  604. + size_t maplen;
  605. timelib_tzinfo *tmp;
  606. int version;
  607. int transitions_result, types_result;
  608. unsigned int type; /* TIMELIB_TZINFO_PHP or TIMELIB_TZINFO_ZONEINFO */
  609. - if (seek_to_tz_position(&tzf, timezone, tzdb)) {
  610. + if (seek_to_tz_position(&tzf, timezone, &memmap, &maplen, tzdb)) {
  611. tmp = timelib_tzinfo_ctor(timezone);
  612. version = read_preamble(&tzf, tmp, &type);
  613. @@ -534,11 +1038,36 @@ timelib_tzinfo *timelib_parse_tzfile(cha
  614. }
  615. skip_posix_string(&tzf, tmp);
  616. +#ifdef HAVE_SYSTEM_TZDATA
  617. + if (memmap) {
  618. + const struct location_info *li;
  619. +
  620. + /* TZif-style - grok the location info from the system database,
  621. + * if possible. */
  622. +
  623. + if ((li = find_zone_info(system_location_table, timezone)) != NULL) {
  624. + tmp->location.comments = timelib_strdup(li->comment);
  625. + strncpy(tmp->location.country_code, li->code, 2);
  626. + tmp->location.longitude = li->longitude;
  627. + tmp->location.latitude = li->latitude;
  628. + tmp->bc = 1;
  629. + }
  630. + else {
  631. + set_default_location_and_comments(&tzf, tmp);
  632. + }
  633. +
  634. + /* Now done with the mmap segment - discard it. */
  635. + munmap(memmap, maplen);
  636. + } else {
  637. +#endif
  638. if (type == TIMELIB_TZINFO_PHP) {
  639. read_location(&tzf, tmp);
  640. } else {
  641. set_default_location_and_comments(&tzf, tmp);
  642. }
  643. +#ifdef HAVE_SYSTEM_TZDATA
  644. + }
  645. +#endif
  646. } else {
  647. *error_code = TIMELIB_ERROR_NO_SUCH_TIMEZONE;
  648. tmp = NULL;