*BSD News Article 8137


Return to BSD News archive

Path: sserve!manuel.anu.edu.au!munnari.oz.au!news.hawaii.edu!ames!agate!doc.ic.ac.uk!uknet!cf-cm!news
From: spedpr@thor.cf.ac.uk (Paul Richards)
Newsgroups: comp.unix.bsd
Subject: Re: ftime(), Elm (& libcompat.a)
Message-ID: <2163.9211261245@thor.cf.ac.uk>
Date: 26 Nov 92 12:45:07 GMT
References: <1992Nov24.093116.226@otago.ac.nz> <1992Nov24.223305.5227@mnemosyne.cs.du.edu> <ByA03o.BoL@unx.sas.com>
Sender: news@cm.cf.ac.uk (Network News System)
Organization: University of Wales College at Cardiff
Lines: 60
X-Mailer: Cardiff Computing Maths PP Mail Open News Gateway

In article <ByA03o.BoL@unx.sas.com> sastdr@torpid.unx.sas.com (Thomas David Rivers) writes:
|
| 
| There is a nice ftime() replacement in the Cnews source.  It is in
|the "faked-up" library for SysV boxes, but works well on 386BSD.
|

I found a ftime using archie that was coded up for BSDI. I've contacted
the author and he's happy to let us use it for 386bsd. I've included the
source below.

The author's mail address is:
>From erik@com.retix.eab Thu Nov 12 18:16:45 1992

/*
 *  A reimplementation of the 'deprecated' ftime
 *  system call using modern BSD 4.3 and later calls.
 *  Note that under BSDI/386, the kernel runs on UTC
 *  time so we cannot really use the time zone info
 *  from the gettimeofday system call. Therefore we
 *  use the localtime library function which does
 *  all appropriate conversions.
 *  Erik Forsberg.
 */

#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/timeb.h>

int ftime(tbp)
	struct timeb *tbp;
	{
	struct timeval tv;
	struct tm *tmp;

	if (tbp == NULL)
		return(-1);

	if (gettimeofday(&tv, (struct timezone *) NULL) < 0)
		return(-1);

	if ((tmp = localtime(&tv.tv_sec)) == NULL)
		return(-1);

	tbp->time = tv.tv_sec;
	tbp->millitm = tv.tv_usec / 1000;

	tbp->timezone = - tmp->tm_gmtoff / 60;
	tbp->dstflag = tmp->tm_isdst;

	return(0);
	}

-- 
  Paul Richards at Cardiff university, UK.

  spedpr@uk.ac.cf.thor	Internet: spedpr@thor.cf.ac.uk
  UUCP:     spedpr@cf-thor.UUCP or ...!uunet!mcsun!uknet!cf!thor!spedpr
+++