Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In POSIX systems, many time fetching functions return -1 as an error code, and I can easily see some programmer doing […]

Particular in this case which traditionally is a function which does not indicate failure by setting `errno`. On many systems it's impossible to distinguish a second before epoch with a legitimate failure.



I think of this another way: why should a "get current time" function ever return an error? And what is someone to do about that case anyway? The time it returns may be wrong, but I think such a function shouldn't be capable of returning "error", as adding that path just increases complexity needlessly without much additional benefit; with the current time being used often in things like error logging, introducing an "error on top of an error" is not a good idea. Defaulting to January 1, 1970 or December 31, 1969 would be sufficient.


If you look into the glibc sources you will find time() implemented as always returning -1. Not all systems have a clock. So specifically for linux for instance it will ask the os for the time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: