]>
git.saurik.com Git - apple/libc.git/blob - sys/gettimeofday.c
07ad5f0cea60c3874583938d00dbc1ca40da30c3
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
25 * File: libc/sys/gettimeofday.c
32 #include <sys/syscall.h>
35 int gettimeofday (struct timeval
*tp
, struct timezone
*tzp
)
37 static int validtz
= 0;
38 static struct timezone cached_tz
= {0};
39 struct timeval localtv
;
41 extern __ppc_gettimeofday(struct timeval
*, struct timezone
*);
44 if (tzp
&& (tp
== NULL
) && (validtz
== 0)) {
49 if(__ppc_gettimeofday(tp
, tzp
))
52 if (syscall (SYS_gettimeofday
, tp
, tzp
) < 0) {
58 struct tm
*localtm
= localtime ((time_t *)&tp
->tv_sec
);
59 cached_tz
.tz_dsttime
= localtm
->tm_isdst
;
60 cached_tz
.tz_minuteswest
=
61 (-localtm
->tm_gmtoff
/ SECSPERMIN
) +
62 (localtm
->tm_isdst
* MINSPERHOUR
);
65 tzp
->tz_dsttime
= cached_tz
.tz_dsttime
;
66 tzp
->tz_minuteswest
= cached_tz
.tz_minuteswest
;