Re: [PATCH v3] ctime.3: EXAMPLES: Add example program

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

 



On 2024-08-23 14:28:13 +0200, Alejandro Colomar wrote:
[about mktime]
> tm_wday is guaranteed to be left unmodified on a failed call.

Where did you see that?

I cannot see any guarantee in case of a failed call, so that I would
say that tm_wday could have been modified, e.g. if the values are
set before checking whether the calendar time can be represented.

> This provides a way to determine if the call failed.

The example in C17 does not use the above claim that "tm_wday is
guaranteed to be left unmodified on a failed call" to determine
whether the call failed. Instead, it uses

  if (mktime(&time_str) == (time_t)(-1))

which is not 100% correct, since -1 can be a valid value (as already
noticed).

> Indeed, this is the only way to determine if the call failed:
> 
> 	tm.tm_wday = INT_MAX;
> 	mktime(&tm);
> 	if (tm.tm_wday == INT_MAX)
> 		err(1, "mktime");

Because of my above remark, I think that a mktime(&tm) == (time_t)(-1)
test is needed *in addition to* the tm.tm_wday == INT_MAX test.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




[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