xref: /onnv-gate/usr/src/lib/libast/common/tm/tvsettime.c (revision 12068:08a39a083754)
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 #include <errno.h>
274887Schin 
284887Schin #include "FEATURE/tvlib"
294887Schin 
304887Schin int
tvsettime(const Tv_t * tv)314887Schin tvsettime(const Tv_t* tv)
324887Schin {
334887Schin 
344887Schin #if _lib_clock_settime && defined(CLOCK_REALTIME)
354887Schin 
364887Schin 	struct timespec			s;
374887Schin 
384887Schin 	s.tv_sec = tv->tv_sec;
394887Schin 	s.tv_nsec = tv->tv_nsec;
404887Schin 	return clock_settime(CLOCK_REALTIME, &s);
414887Schin 
424887Schin #else
434887Schin 
444887Schin #if defined(tmsettimeofday)
454887Schin 
464887Schin 	struct timeval			v;
474887Schin 
484887Schin 	v.tv_sec = tv->tv_sec;
494887Schin 	v.tv_usec = tv->tv_nsec / 1000;
504887Schin 	return tmsettimeofday(&v);
514887Schin 
524887Schin #else
534887Schin 
544887Schin #if _lib_stime
554887Schin 
564887Schin 	static time_t			s;
574887Schin 
584887Schin 	s = tv->tv_sec + (tv->tv_nsec != 0);
594887Schin 	return stime(s);
604887Schin 
614887Schin #else
624887Schin 
634887Schin 	errno = EPERM;
644887Schin 	return -1;
654887Schin 
664887Schin #endif
674887Schin 
684887Schin #endif
694887Schin 
704887Schin #endif
714887Schin 
724887Schin }
73