148368Sbostic /*- 2*61240Sbostic * Copyright (c) 1980, 1993 3*61240Sbostic * The Regents of the University of California. All rights reserved. 448368Sbostic * 548368Sbostic * %sccs.include.proprietary.c% 621326Sdist */ 712846Ssam 826516Sdonn #if defined(LIBC_SCCS) && !defined(lint) 9*61240Sbostic static char sccsid[] = "@(#)ftime.c 8.1 (Berkeley) 06/04/93"; 1048368Sbostic #endif /* LIBC_SCCS and not lint */ 1121326Sdist 1212846Ssam #include <sys/types.h> 1312846Ssam #include <sys/time.h> 1412846Ssam 1512846Ssam /* 1612846Ssam * Backwards compatible ftime. 1712846Ssam */ 1812846Ssam 1912846Ssam /* from old timeb.h */ 2012846Ssam struct timeb { 2112846Ssam time_t time; 2212846Ssam u_short millitm; 2312846Ssam short timezone; 2412846Ssam short dstflag; 2512846Ssam }; 2612846Ssam ftime(tp)2712846Ssamftime(tp) 2812846Ssam register struct timeb *tp; 2912846Ssam { 3012846Ssam struct timeval t; 3112846Ssam struct timezone tz; 3259996Storek struct tm *tm; 3359996Storek time_t zero; 3412846Ssam 3512846Ssam if (gettimeofday(&t, &tz) < 0) 3612846Ssam return (-1); 3712846Ssam tp->time = t.tv_sec; 3812846Ssam tp->millitm = t.tv_usec / 1000; 3959996Storek if ((tm = localtime(&tp->time)) == NULL) { 4059996Storek /* in the absence of anything better, use kernel's timezone */ 4159996Storek tp->timezone = tz.tz_minuteswest; 4259996Storek tp->dstflag = tz.tz_dsttime; 4359996Storek } else { 4459996Storek tp->dstflag = tm->tm_isdst; 4559996Storek if (tm->tm_isdst) { /* tm_gmtoff has an offset applied */ 4659996Storek zero = 0; /* try 0 and hope for the best */ 4759996Storek tp->timezone = -localtime(&zero)->tm_gmtoff / 60; 4859996Storek } else 4959996Storek tp->timezone = -tm->tm_gmtoff / 60; 5059996Storek } 5112846Ssam } 52