1 /* Copyright (C) 1991,92,94,95,96,97,2001,2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 # define __daylight daylight
25 # define __timezone timezone
26 # define __tzname tzname
31 extern int rtc_upper (void);
32 extern int rtc_lower (void);
34 /* Assembler Routines to access the timer registers */
36 .rtc_upper: mfspr 3,4 # copy RTCU to return register\n\
39 .rtc_lower: mfspr 3,5 # copy RTCL to return register\n\
43 /* Get the current time of day and timezone information,
44 putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
45 Returns 0 on success, -1 on errors. */
47 __gettimeofday (tv, tz)
59 ts = rtc_upper (); /* Seconds. */
60 tl = rtc_lower (); /* Nanoseconds. */
61 tu = rtc_upper (); /* Check for a carry from. */
62 if (ts != tu) /* The lower reg to the upper. */
63 tl = rtc_lower (); /* Recover from the race condition. */
65 tv->tv_sec = (long int) (tu + (double) tl / 1000000000);
66 tv->tv_usec = (long int) ((double) tl / 1000);
70 const time_t timer = tv->tv_sec;
74 const long int save_timezone = __timezone;
75 const long int save_daylight = __daylight;
77 save_tzname[0] = __tzname[0];
78 save_tzname[1] = __tzname[1];
80 tmp = localtime_r (&timer, &tm);
82 tz->tz_minuteswest = __timezone / 60;
83 tz->tz_dsttime = __daylight;
85 __timezone = save_timezone;
86 __daylight = save_daylight;
87 __tzname[0] = save_tzname[0];
88 __tzname[1] = save_tzname[1];
97 INTDEF(__gettimeofday)
98 weak_alias (__gettimeofday, gettimeofday)