1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*LINTLIBRARY*/
31 
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <errno.h>
37 #include <sys/syscall.h>
38 #include "libc.h"
39 
40 /*
41  * Get the time of day information.
42  * BSD compatibility on top of SVr4 facilities:
43  * u_sec always zero, and don't do anything with timezone pointer.
44  */
45 
46 /*
47  * This is defined in sys/gettimeofday.s
48  * This extern cannot be in libc.h due to name conflict with port/gen/synonyms.h
49  */
50 extern int _gettimeofday(struct timeval *);
51 
52 /*ARGSUSED*/
53 int
gettimeofday(struct timeval * tp,void * tzp)54 gettimeofday(struct timeval *tp, void *tzp)
55 {
56 	if (tp == NULL)
57 		return (0);
58 
59 	return (_gettimeofday(tp));
60 }
61 
62 /*
63  * Set the time.
64  * Don't do anything with the timezone information.
65  */
66 
67 /*ARGSUSED*/
68 int
settimeofday(struct timeval * tp,void * tzp)69 settimeofday(struct timeval *tp, void *tzp)
70 {
71 	time_t t;		/* time in seconds */
72 
73 	if (tp == NULL)
74 		return (0);
75 
76 	t = (time_t) tp->tv_sec;
77 	if (tp->tv_usec >= 500000)
78 		/* round up */
79 		t++;
80 
81 	return (stime(&t));
82 }
83