]>
git.saurik.com Git - apple/libc.git/blob - sys/gettimeofday.c
9b939897428d30bc1c08edeb244713dff45508d7
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
28 * File: libc/sys/gettimeofday.c
35 #include <sys/syscall.h>
38 #define __APPLE_API_PRIVATE
39 #include <machine/cpu_capabilities.h>
40 #undef __APPLE_API_PRIVATE
43 int gettimeofday (struct timeval
*tp
, struct timezone
*tzp
)
45 static int validtz
= 0;
46 static struct timezone cached_tz
= {0};
47 struct timeval localtv
;
55 #if defined(__ppc__) || defined(__ppc64__)
57 extern int __ppc_gettimeofday(struct timeval
*, struct timezone
*);
58 extern int __commpage_gettimeofday(struct timeval
*);
60 if (__commpage_gettimeofday(tp
)) { /* first try commpage */
61 if (__ppc_gettimeofday(tp
,tzp
)) { /* if it fails, use syscall */
67 if (syscall (SYS_gettimeofday
, tp
, tzp
) < 0) {
73 struct tm
*localtm
= localtime ((time_t *)&tp
->tv_sec
);
74 cached_tz
.tz_dsttime
= localtm
->tm_isdst
;
75 cached_tz
.tz_minuteswest
=
76 (-localtm
->tm_gmtoff
/ SECSPERMIN
) +
77 (localtm
->tm_isdst
* MINSPERHOUR
);
80 tzp
->tz_dsttime
= cached_tz
.tz_dsttime
;
81 tzp
->tz_minuteswest
= cached_tz
.tz_minuteswest
;