NetBSD-Users archive

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

Re: mktime(3) return value



In article <Pine.NEB.4.64.1101051128120.3005%quicky.whooppee.com@localhost>,
Paul Goyette  <paul%whooppee.com@localhost> wrote:
>While looking at more of our old src/regress/lib/libc regression tests, 
>I noticed that mktime(3) doesn't seem to work correectly.
>
>The following code snippet demonstrates the problem
>
>       {
>               time_t rc;
>               struct tm tms;
>
>               (void)memset(&tms, 0, sizeof(tms));
>               tms.tm_year = ~0;
>
>               errno = 0;
>               rc = mktime(&tms);
>       }
>
>Given the rather absurd value of tms.tm_year, you would certainly expect 
>an error.  mktime(3) does indeed set errno to EOVERFLOW, however it does 
>set the return value to (time_t)-1 as is documented in the man page:
>
>       The mktime() function returns the specified time since the Epoch
>       as a time_t type value.  If the time cannot be represented, then
>       mktime() returns (time_t)-1 setting the global variable errno to
>       indicate the error.
>
>(If it matters, the actual return value from mktime is 2,054,384,896 
>which is 0x7a736d00)
>
>So, my question is simple:
>
>Is the man page wrong about returning (time_t)-1?  Or is the return 
>value actually a correct representation of tm_year = ~0 ?

1. No.
2. Could be.

christos



Home | Main Index | Thread Index | Old Index