path: root/src/time/clock.c
AgeCommit message (Collapse)AuthorLines
2013-05-23fix overflow behavior of clock() functionRich Felker-7/+10
per Austin Group interpretation for issue #686, which cites the requirements of ISO C, clock() cannot wrap. if the result is not representable, it must return (clock_t)-1. in addition, the old code was performing wrapping via signed overflow and thus invoking undefined behavior. since it seems impossible to accurately check for overflow with the old times()-based fallback code, I have simply dropped the fallback code for now, thus always returning -1 on ancient systems. if there's a demand for making it work and somebody comes up with a way, it could be reinstated, but the clock() function is essentially useless on 32-bit system anyway (it overflows in less than an hour). it should be noted that I used LONG_MAX rather than ULONG_MAX, despite 32-bit archs using an unsigned type for clock_t. this discrepency with the glibc/LSB type definitions will be fixed now; since wrapping of clock_t is no longer supported, there's no use in it being unsigned.
2013-05-05fix incorrect clock tick scaling in fallback case of clock()Rich Felker-1/+1
since CLOCKS_PER_SEC is 1000000 (required by XSI) and the times syscall reports values in 1/100 second units (Linux), the correct scaling factor is 10000, not 100. note that only ancient kernels which lack clock_gettime are affected.
2011-08-13fix missing include in last commitRich Felker-0/+1
2011-08-13fix clock() functionRich Felker-2/+7
it previously was returning the pseudo-monotonic-realtime clock returned by times() rather than process cputime. it also violated C namespace by pulling in times(). we now use clock_gettime() if available because times() has ridiculously bad resolution. still provide a fallback for ancient kernels without clock_gettime.
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+9