Back to index

glibc  2.9
Defines | Functions
gettimeofday.c File Reference
#include <errno.h>
#include <time.h>
#include <sys/time.h>

Go to the source code of this file.

Defines

#define __daylight   daylight
#define __timezone   timezone
#define __tzname   tzname

Functions

int rtc_upper (void)
int rtc_lower (void)
 asm ("\n\ .rtc_upper: mfspr 3,4 # copy RTCU to return register\n\ blr\n\ \n\ .rtc_lower: mfspr 3,5 # copy RTCL to return register\n\ blr\n\ ")
int __gettimeofday (struct timeval *tv, struct timezone *tz)

Define Documentation

#define __daylight   daylight

Definition at line 24 of file gettimeofday.c.

#define __timezone   timezone

Definition at line 25 of file gettimeofday.c.

#define __tzname   tzname

Definition at line 26 of file gettimeofday.c.


Function Documentation

int __gettimeofday ( struct timeval tv,
struct timezone *  tz 
)

Definition at line 47 of file gettimeofday.c.

{
  int ts, tl, tu;

  if (tv == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  ts = rtc_upper ();        /* Seconds.  */
  tl = rtc_lower ();        /* Nanoseconds.  */
  tu = rtc_upper ();        /* Check for a carry from.  */
  if (ts != tu)                    /* The lower reg to the upper.  */
      tl  = rtc_lower ();   /* Recover from the race condition.  */

  tv->tv_sec  = (long int) (tu + (double) tl / 1000000000);
  tv->tv_usec = (long int) ((double) tl / 1000);

  if (tz != NULL)
    {
      const  time_t timer = tv->tv_sec;
      struct tm tm;
      const  struct tm *tmp;

      const long int save_timezone = __timezone;
      const long int save_daylight = __daylight;
      char *save_tzname[2];
      save_tzname[0] = __tzname[0];
      save_tzname[1] = __tzname[1];

      tmp = localtime_r (&timer, &tm);

      tz->tz_minuteswest = __timezone / 60;
      tz->tz_dsttime     = __daylight;

      __timezone  = save_timezone;
      __daylight  = save_daylight;
      __tzname[0] = save_tzname[0];
      __tzname[1] = save_tzname[1];

      if (tmp == NULL)
       return -1;
    }

  return 0;
}

Here is the call graph for this function:

asm ( "\n\.rtc_upper: mfspr  3,
4#copy RTCU to return register\n\blr\n\\n\.rtc_lower:mfspr  3,
5#copy RTCL to return register\n\blr\n\"   
)
int rtc_lower ( void  )

Here is the caller graph for this function:

int rtc_upper ( void  )

Here is the caller graph for this function: