[uClibc] clock_gettime

Justus Pendleton uc at ryoohki.net
Fri Oct 24 16:43:32 UTC 2003


This message from Feb 2002 --

http://www.uclibc.org/lists/uclibc/2002-February/002755.html

implied that uClibc was going to be getting clock_gettime in the
0.9.10 release.  I downloaded the most recent snapshot and still
couldn't find it.  I don't know the uClibc source enough to know where
this function should go (hence my not providing an actual patch) but:

#define __USE_GNU /* need this to get the TIMEVAL_TO_TIMESPEC macro */
#include <sys/time.h>
#include <errno.h>

int clock_gettime (clockid_t clock, struct timespec* ts)
{
	struct timeval tv;
	int retval = -1;
	switch (clock) {
		case CLOCK_REALTIME:
			retval = gettimeofday (&tv, NULL);
			if (retval == 0) {
				TIMEVAL_TO_TIMESPEC (&tv, ts);
			}
			break;
		default:
			errno = EINVAL;
			break;
	}
	return retval;
}

--
Justus



More information about the uClibc mailing list