예제 #1
0
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
{
	const unsigned char *tzf;
	timelib_tzinfo *tmp;
	int version;

	if (seek_to_tz_position(&tzf, timezone, tzdb)) {
		tmp = timelib_tzinfo_ctor(timezone);

		version = read_preamble(&tzf, tmp);
		read_header(&tzf, tmp);
		read_transistions(&tzf, tmp);
		read_types(&tzf, tmp);
		if (version == 2) {
			skip_64bit_preamble(&tzf, tmp);
			read_64bit_header(&tzf, tmp);
			skip_64bit_transistions(&tzf, tmp);
			skip_64bit_types(&tzf, tmp);
			skip_posix_string(&tzf, tmp);
		}
		read_location(&tzf, tmp);
	} else {
		tmp = NULL;
	}

	return tmp;
}
예제 #2
0
파일: timelib.c 프로젝트: 19Berny90/php-src
timelib_tzinfo *timelib_tzinfo_clone(timelib_tzinfo *tz)
{
	timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name);
	tmp->ttisgmtcnt = tz->ttisgmtcnt;
	tmp->ttisstdcnt = tz->ttisstdcnt;
	tmp->leapcnt = tz->leapcnt;
	tmp->timecnt = tz->timecnt;
	tmp->typecnt = tz->typecnt;
	tmp->charcnt = tz->charcnt;
	
	tmp->trans = (int32_t *) malloc(tz->timecnt * sizeof(int32_t));
	tmp->trans_idx = (unsigned char*) malloc(tz->timecnt * sizeof(unsigned char));
	memcpy(tmp->trans, tz->trans, tz->timecnt * sizeof(int32_t));
	memcpy(tmp->trans_idx, tz->trans_idx, tz->timecnt * sizeof(unsigned char));

	tmp->type = (ttinfo*) malloc(tz->typecnt * sizeof(struct ttinfo));
	memcpy(tmp->type, tz->type, tz->typecnt * sizeof(struct ttinfo));

	tmp->timezone_abbr = (char*) malloc(tz->charcnt);
	memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->charcnt);

	tmp->leap_times = (tlinfo*) malloc(tz->leapcnt * sizeof(tlinfo));
	memcpy(tmp->leap_times, tz->leap_times, tz->leapcnt * sizeof(tlinfo));

	return tmp;
}
예제 #3
0
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
{
	const unsigned char *tzf;
	char *memmap = NULL;
	size_t maplen;
	timelib_tzinfo *tmp;

	if (seek_to_tz_position(&tzf, timezone, &memmap, &maplen, tzdb)) {
		tmp = timelib_tzinfo_ctor(timezone);

		read_preamble(&tzf, tmp);
		read_header(&tzf, tmp);
		read_transistions(&tzf, tmp);
		read_types(&tzf, tmp);

#ifdef HAVE_SYSTEM_TZDATA
		if (memmap) {
			const struct location_info *li;

			/* TZif-style - grok the location info from the system database,
			 * if possible. */

			if ((li = find_zone_info(system_location_table, timezone)) != NULL) {
				tmp->location.comments = strdup(li->comment);
                                strncpy(tmp->location.country_code, li->code, 2);
				tmp->location.longitude = li->longitude;
				tmp->location.latitude = li->latitude;
				tmp->bc = 1;
			}
			else {
				strcpy(tmp->location.country_code, "??");
				tmp->bc = 0;
				tmp->location.comments = strdup("");
			}

			/* Now done with the mmap segment - discard it. */
			munmap(memmap, maplen);
		} else
#endif
		{
			/* PHP-style - use the embedded info. */
			read_location(&tzf, tmp);
		}
	} else {
		tmp = NULL;
	}

	return tmp;
}
예제 #4
0
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
{
	const unsigned char *tzf;
	timelib_tzinfo *tmp;

	if (seek_to_tz_position(&tzf, timezone, tzdb)) {
		tmp = timelib_tzinfo_ctor(timezone);

		read_header((char**) &tzf, tmp);
		read_transistions((char**) &tzf, tmp);
		read_types((char**) &tzf, tmp);
	} else {
		tmp = NULL;
	}

	return tmp;
}