Closed GoogleCodeExporter closed 9 years ago
Original comment by chris.m.dunlap
on 3 Jan 2013 at 8:58
I thought every time zone could be abbreviated with 4 characters or less:
http://www.timeanddate.com/library/abbreviations/timezones/
What does strftime() return for your %Z value?
Original comment by chris.m.dunlap
on 3 Jan 2013 at 9:35
"GMT-1"
We instructed out customer to use Europe/Vienna which works and is the correct
zone as the workaround.
Also tried with Europe/Volgograd and it reported "VOLT-4",
America/Argentina/San_Luis "WARST" & Chile/EasterIsland "EASST". I searched the
zoneinfo database and found some as long as 8 characters.
Original comment by mark_sal...@xyratex.com
on 3 Jan 2013 at 9:53
This issue was closed by revision 858ecb47c558.
Original comment by chris.m.dunlap
on 3 Jan 2013 at 10:41
You are trying to minimize buffer size because you don't want to waste bytes,
right?
There is a better way to do it:
char * create_long_time_string(time_t t)
{
char buf[160];
struct tm tm;
get_localtime(&t, &tm);
if (strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", &tm) == 0) {
log_err(0, "strftime() failed");
buf[0] = '\0';
}
return(create_string(buf));
}
This way, you always allocate as many bytes as necessary, and not a byte more.
Original comment by vda.li...@googlemail.com
on 20 Feb 2013 at 12:25
True, but that costs an additional strcpy (ie, a strdup vs a malloc).
If there was a greater range in the lengths of timezone strings (eg, if there
was at least one tz string that was really long), I'd be inclined to go with
this approach. But we're only dealing with a few extra bytes for a short-lived
string. Thanks, though.
Original comment by chris.m.dunlap
on 21 Feb 2013 at 12:03
> that costs an additional strcpy (ie, a strdup vs a malloc).
The cost is small, while wasted trailing bytes will persist as long as result
is in use.
Original comment by vda.li...@googlemail.com
on 7 May 2013 at 2:00
Original issue reported on code.google.com by
mark_sal...@xyratex.com
on 3 Jan 2013 at 8:54