[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Mon, 25 Jan 2010 08:16:31 +0100
On Sun, Jan 24, 2010 at 08:51:58PM +0100, Bruno Haible wrote:
> Hmm, if this is proposed for gnulib, I have 4 remarks:
> - Error handling: strftime can fail. Since you call xmalloc for the
> memory allocation, I think it would be reasonable to call error()
> in case strftime fails.
> - Flexibility: The three most often used formats are probably %c, %x, %X.
> Any function for date formatting should not have the format built-in.
> It should have a format indication as argument. But then you can also
> allow the user to pass an entire format string. And define shorthands
> as reminders like this:
> #define TIMEFORMAT_LOCALE_DATETIME "%c"
> #define TIMEFORMAT_LOCALE_DATE "%x"
> #define TIMEFORMAT_LOCALE_TIME "%X"
> - In the average case, you can get away with 1 strftime call instead of 2,
> if you preallocate a buffer on the stack:
> char buf;
> len = strftime (buf, sizeof (buf), "%c", loctime) + 1;
> In the case where 256 bytes are not enough, the function will need
> 3 strftime calls instead of 1, but this case should be pretty rare
> (even in Chinese and GB18030 encoding, 64 characters should be enough
> for a date + time display).
What about http://www.gnu.org/prep/standards/standards.html#Semantics ?
Avoiding arbitrary limits is a good thing IMO.
> - sizeof ("") is confusing. You can write 1 instead.
"Be the change you want to see in the world" -- Gandhi
- xctime(), Robert Millan, 2010/01/24
- Re: xctime(), Bruno Haible, 2010/01/24
- Re: xctime(),
Robert Millan <=