1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)ftime.c 5.4 (Berkeley) 05/13/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 #include <sys/time.h> 14 15 /* 16 * Backwards compatible ftime. 17 */ 18 19 /* from old timeb.h */ 20 struct timeb { 21 time_t time; 22 u_short millitm; 23 short timezone; 24 short dstflag; 25 }; 26 27 ftime(tp) 28 register struct timeb *tp; 29 { 30 struct timeval t; 31 struct timezone tz; 32 struct tm *tm; 33 time_t zero; 34 35 if (gettimeofday(&t, &tz) < 0) 36 return (-1); 37 tp->time = t.tv_sec; 38 tp->millitm = t.tv_usec / 1000; 39 if ((tm = localtime(&tp->time)) == NULL) { 40 /* in the absence of anything better, use kernel's timezone */ 41 tp->timezone = tz.tz_minuteswest; 42 tp->dstflag = tz.tz_dsttime; 43 } else { 44 tp->dstflag = tm->tm_isdst; 45 if (tm->tm_isdst) { /* tm_gmtoff has an offset applied */ 46 zero = 0; /* try 0 and hope for the best */ 47 tp->timezone = -localtime(&zero)->tm_gmtoff / 60; 48 } else 49 tp->timezone = -tm->tm_gmtoff / 60; 50 } 51 } 52