DO(tzh_magic);
writezone(name)const char * const	name;{	register FILE *		fp;	register int		i, j;	static char *		fullname;	static struct tzhead	tzh;	time_t			ats[TZ_MAX_TIMES];	unsigned char		types[TZ_MAX_TIMES];	/*	** Sort.	*/	if (timecnt > 1)		(void) qsort((void *) attypes, (size_t) timecnt,			(size_t) sizeof *attypes, atcomp);	/*	** Optimize.	*/	{		int	fromi;		int	toi;		toi = 0;		fromi = 0;		while (fromi < timecnt && attypes[fromi].at < min_time)			++fromi;		if (isdsts[0] == 0)			while (fromi < timecnt && attypes[fromi].type == 0)				++fromi;	/* handled by default rule */		for ( ; fromi < timecnt; ++fromi) {			if (toi != 0			    && ((attypes[fromi].at				 + gmtoffs[attypes[toi - 1].type])				<= (attypes[toi - 1].at				    + gmtoffs[toi == 1 ? 0					      : attypes[toi - 2].type]))) {				attypes[toi - 1].type = attypes[fromi].type;				continue;			}			if (toi == 0 ||				attypes[toi - 1].type != attypes[fromi].type)					attypes[toi++] = attypes[fromi];		}		timecnt = toi;	}	/*	** Transfer.	*/	for (i = 0; i < timecnt; ++i) {		ats[i] = attypes[i].at;		types[i] = attypes[i].type;	}	fullname = erealloc(fullname,		(int) (strlen(directory) + 1 + strlen(name) + 1));	(void) sprintf(fullname, "%s/%s", directory, name);	/*	** Remove old file, if any, to snap links.	*/	if (!itsdir(fullname) && remove(fullname) != 0 && errno != ENOENT) {		const char *e = strerror(errno);		(void) fprintf(stderr, _("%s: Can't remove %s: %s\n"),			progname, fullname, e);		(void) exit(EXIT_FAILURE);	}	if ((fp = fopen(fullname, "wb")) == NULL) {		if (mkdirs(fullname) != 0)			(void) exit(EXIT_FAILURE);		if ((fp = fopen(fullname, "wb")) == NULL) {			const char *e = strerror(errno);			(void) fprintf(stderr, _("%s: Can't create %s: %s\n"),				progname, fullname, e);			(void) exit(EXIT_FAILURE);		}	}	convert(eitol(typecnt), tzh.tzh_ttisgmtcnt);	convert(eitol(typecnt), tzh.tzh_ttisstdcnt);	convert(eitol(leapcnt), tzh.tzh_leapcnt);	convert(eitol(timecnt), tzh.tzh_timecnt);	convert(eitol(typecnt), tzh.tzh_typecnt);	convert(eitol(charcnt), tzh.tzh_charcnt);#define DO(field)	(void) fwrite((void *) tzh.field, (size_t) sizeof tzh.field, (size_t) 1, fp)	DO(tzh_reserved);	DO(tzh_ttisgmtcnt);	DO(tzh_ttisstdcnt);	DO(tzh_leapcnt);	DO(tzh_timecnt);	DO(tzh_typecnt);	DO(tzh_charcnt);#undef DO	for (i = 0; i < timecnt; ++i) {		j = leapcnt;		while (--j >= 0)			if (ats[i] >= trans[j]) {				ats[i] = tadd(ats[i], corr[j]);				break;			}		puttzcode((long) ats[i], fp);	}	if (timecnt > 0)		(void) fwrite((void *) types, (size_t) sizeof types[0],			(size_t) timecnt, fp);	for (i = 0; i < typecnt; ++i) {		puttzcode((long) gmtoffs[i], fp);		(void) putc(isdsts[i], fp);		(void) putc(abbrinds[i], fp);	}	if (charcnt != 0)		(void) fwrite((void *) chars, (size_t) sizeof chars[0],			(size_t) charcnt, fp);	for (i = 0; i < leapcnt; ++i) {		if (roll[i]) {			if (timecnt == 0 || trans[i] < ats[0]) {				j = 0;				while (isdsts[j])					if (++j >= typecnt) {						j = 0;						break;					}			} else {				j = 1;				while (j < timecnt && trans[i] >= ats[j])					++j;				j = types[j - 1];			}			puttzcode((long) tadd(trans[i], -gmtoffs[j]), fp);		} else	puttzcode((long) trans[i], fp);		puttzcode((long) corr[i], fp);	}	for (i = 0; i < typecnt; ++i)		(void) putc(ttisstds[i], fp);	for (i = 0; i < typecnt; ++i)		(void) putc(ttisgmts[i], fp);	if (ferror(fp) || fclose(fp)) {		(void) fprintf(stderr, _("%s: Error writing %s\n"),			progname, fullname);		(void) exit(EXIT_FAILURE);	}}