
The following patch adds a "magic number" to compiled zoneinfo files. The affected files are zic.c and tzfile.h. In essence, the first four bytes of zoneinfo files are set to "\0x14\0x1a\0x54\0x5a", which in ASCII is "^T^ZTZ". This patch is trivial, but will assist in the automatic recognition of zoneinfo files by the Unix "file" command. *** tzfile.h Sat Jul 19 13:14:50 1997 --- tzfile.new.h Tue Oct 7 16:36:24 1997 *************** *** 46,52 **** */ struct tzhead { ! char tzh_reserved[20]; /* reserved for future use */ char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ char tzh_leapcnt[4]; /* coded number of leap seconds */ --- 46,53 ---- */ struct tzhead { ! char tzh_magic[4]; /* magic string: "^T^ZTZ" */ ! char tzh_reserved[16]; /* reserved for future use */ char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ char tzh_leapcnt[4]; /* coded number of leap seconds */ *** zic.c Tue Sep 23 16:37:14 1997 --- zic.new.c Tue Oct 7 16:34:30 1997 *************** *** 1468,1473 **** --- 1468,1475 ---- 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) + strncpy(tzh.tzh_magic, "\0x14\0x1a\0x54\0x5a", 4); + DO(tzh_magic); DO(tzh_reserved); DO(tzh_ttisgmtcnt); DO(tzh_ttisstdcnt); -- John Cowan http://www.ccil.org/~cowan cowan@ccil.org e'osai ko sarji la lojban

On Tue, 7 Oct 1997, John Cowan wrote:
The following patch adds a "magic number" to compiled zoneinfo files. The affected files are zic.c and tzfile.h. In essence, the first four bytes of zoneinfo files are set to "\0x14\0x1a\0x54\0x5a", which in ASCII is "^T^ZTZ". This patch is trivial, but will assist in the automatic recognition of zoneinfo files by the Unix "file" command.
Excellent idea, but I'd suggest choosing a magic number based on the principles outlined in RFC 2083 section 12.11. I propose: \211 T Z \r \n ^Z \n as a magic number. - Chris

Chris Newman wrote:
Excellent idea, but I'd suggest choosing a magic number based on the principles outlined in RFC 2083 section 12.11. I propose:
\211 T Z \r \n ^Z \n
as a magic number.
Thanks for the reference to RFC 2083. I have two problems: 1) 7 bytes is a "peculiar" length. I suggest adding a NUL (\0) byte just after the Z, if we go with this scheme. In which case "strncpy" will have to be replaced with "memcpy". 2) There are only 20 available bytes. I am a little reluctant to consume 8 of them, leaving at most 3 new 32-bit length quantities. Consuming only 4 is less risky. Comments? -- John Cowan http://www.ccil.org/~cowan cowan@ccil.org e'osai ko sarji la lojban
participants (2)
-
Chris Newman
-
John Cowan