tech-userlevel archive

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

mktime(3) return value

(Previously posted to netbsd-users@ but probably more appropriate here)

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 ?

| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at |
| Kernel Developer |                          | pgoyette at  |

Home | Main Index | Thread Index | Old Index