14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 78462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin 244887Schin #include <tv.h> 254887Schin #include <tm.h> 264887Schin 274887Schin #include "FEATURE/tvlib" 284887Schin 294887Schin int tvgettime(Tv_t * tv)304887Schintvgettime(Tv_t* tv) 314887Schin { 324887Schin 334887Schin #if _lib_clock_gettime && defined(CLOCK_REALTIME) 344887Schin 354887Schin struct timespec s; 364887Schin 374887Schin clock_gettime(CLOCK_REALTIME, &s); 384887Schin tv->tv_sec = s.tv_sec; 394887Schin tv->tv_nsec = s.tv_nsec; 404887Schin 414887Schin #else 424887Schin 434887Schin #if defined(tmgettimeofday) 444887Schin 454887Schin struct timeval v; 464887Schin 474887Schin tmgettimeofday(&v); 484887Schin tv->tv_sec = v.tv_sec; 494887Schin tv->tv_nsec = v.tv_usec * 1000; 504887Schin 514887Schin #else 524887Schin 534887Schin static time_t s; 544887Schin static uint32_t n; 554887Schin 564887Schin if ((tv->tv_sec = time(NiL)) != s) 574887Schin { 584887Schin s = tv->tv_sec; 594887Schin n = 0; 604887Schin } 614887Schin else 624887Schin n += 1000; 634887Schin tv->tv_nsec = n; 644887Schin 654887Schin #endif 664887Schin 674887Schin #endif 684887Schin 694887Schin return 0; 704887Schin } 71