os/ossrv/genericopenlibs/openenvcore/libc/src/gettimeofday.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // TIME.CPP
    15 // Mapping between EPOC32 time and libc time
    16 // The basic philosophy is to work in time_t units (TInt) which
    17 // will be essentially TTimeIntervalSeconds from the start of Unix time.
    18 // To stay compliant with the C-Standard (with reference to C99 draft), we  
    19 // set the meaning of time_t to be Universal time.
    20 // 
    21 //
    22 
    23 #include <e32std.h>
    24 #include <sys/time.h> // struct timeval, timezone
    25 
    26 #define UNIX_BASE   TTime(MAKE_TINT64(0x00dcddb3,0x0f2f8000))    // 00:00, Jan 1st 1970
    27 
    28 // external interface for the C library
    29 
    30 extern "C" {
    31 
    32 /*
    33 Intended Usage:	The gettimeofday function obtains the current UTC time, which is 
    34 				expressed as seconds and microseconds since 00:00:00 Coordinated Universal Time (UTC), 
    35 				January 1, 1970, and stores it in a timeval structure.
    36 				Please note that tz_minuteswest includes daytime saving. The struct member tz_dsttime is no 
    37 				longer supported by Symbian OS and therefore set to Zero.
    38 
    39 */
    40 EXPORT_C 
    41 int gettimeofday (struct timeval *tp, struct timezone *tzp)
    42     {
    43     if (tp)
    44 	{
    45 	TTime t;
    46 	t.UniversalTime();
    47 	
    48 	TTimeIntervalSeconds sec;
    49 	TInt err = t.SecondsFrom(UNIX_BASE, sec);
    50 	if (err)
    51 	    return -1;
    52 	else
    53 	    tp->tv_sec = sec.Int();
    54 	t -= sec;
    55 	TTimeIntervalMicroSeconds usec = t.MicroSecondsFrom(UNIX_BASE);
    56 	TInt64 hackyfix = usec.Int64();	// because GetTInt() isn't declared const
    57 	tp->tv_usec = I64INT(hackyfix);
    58 	}
    59     if (tzp)
    60 	{
    61 	    tzp->tz_minuteswest = (User::UTCOffset().Int())/60;
    62 	    tzp->tz_dsttime = 0;
    63 	}
    64     return 0;
    65     }
    66 
    67 } // extern "C"