9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* ape, gettimeofday.c
@ 1996-03-07 19:57 Scott
  0 siblings, 0 replies; only message in thread
From: Scott @ 1996-03-07 19:57 UTC (permalink / raw)


Pgp is much happier if gettimeofday returns something for
the usec field.  Here's a version that tries to do that.

#include <sys/types.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

static int
ms(void) 
{
	char b[20];
	static int f = -1;

	/* XXX - should use native plan9 syscalls herein */
	memset(b, 0, sizeof(b));
	if (f < 0) {
		f = open("/dev/msec", O_RDONLY);
		fcntl(f, FD_CLOEXEC, 1);
	}
	if (f >= 0) {
		lseek(f, 0, 0);
		read(f, b, sizeof(b));
	}
	return atol(b) % 1000;
}

int
gettimeofday(struct timeval *tp, struct timezone *tzp)
{
	tp->tv_sec = time(0);
	tp->tv_usec = ms() * 1000;

	if(tzp) {
		tzp->tz_minuteswest = 240;
		tzp->tz_dsttime = 1;
	}

	return 0;
}






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-03-07 19:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-07 19:57 ape, gettimeofday.c Scott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).