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.

666 lines
18 KiB

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