Make library buildable on Darwin

The library is currently not buildable on Darwin. The main reason is the use of `clock_gettime`, which is not implemented by Darwin. Fix this by providing an implementation based on `gettimeofday` on Darwin.