Re: [PATCH v2] ctime.3: Document how to check errors from mktime(3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-08-23 07:37, Alejandro Colomar wrote:
     ++    if (tm.tm_wday == \-1)

'if (tm.tm_wday < 0)' is a bit faster on typical machines. (There are multiple instances of this issue.)

+To determine if

"if" -> "whether"

+    printf("%jd\[rs]n", (intmax_t) t);

This is not portable in general, as time_t might be unsigned. You could use strftime instead of printf. But see below for a better suggestion.

+    tm.tm_year  = atoi(*p++) \- 1900;

This doesn't work for the year 2147485547 (2**31 + 1899), which mktime can handle on typical machines with 32-bit int and 64-bit time_t. Also, all the atoi calls silently mess up if the argument overflows or is syntactically invalid.

To simplify the example, I suggest not doing I/O or parsing. Just have a function that accepts a struct tm *, and returns true or false and updates the struct tm when it returns true. That would avoid the issues with printf and atoi.




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux