I need to use pthread_cond_timedwait, which is available in my old embedded Linux for PPC. But I don't have clock_gettime... So, I build this replacement for clock_gettime, and it seems to work:
#include <sys/time.h>
#include <time.h>
int clock_gettime_replacement(struct timespec *now) {
#ifdef HAVE_CLOCK_GETTIME
return clock_gettime(CLOCK_REALTIME, now);
#else
now->tv_sec = time(NULL);
struct timeval tv;
gettimeofday(&tv, NULL);
now->tv_nsec = tv.tv_usec * 1000;
return 0;
#endif
}
But I'm afraid of issues related with daylight saving and timezone. Do you know where I can get sources of clock_gettime, so I can build it on my own using other system calls?