os/ossrv/genericopenlibs/openenvcore/libc/src/gettimeofday.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/gettimeofday.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,67 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// TIME.CPP
    1.18 +// Mapping between EPOC32 time and libc time
    1.19 +// The basic philosophy is to work in time_t units (TInt) which
    1.20 +// will be essentially TTimeIntervalSeconds from the start of Unix time.
    1.21 +// To stay compliant with the C-Standard (with reference to C99 draft), we  
    1.22 +// set the meaning of time_t to be Universal time.
    1.23 +// 
    1.24 +//
    1.25 +
    1.26 +#include <e32std.h>
    1.27 +#include <sys/time.h> // struct timeval, timezone
    1.28 +
    1.29 +#define UNIX_BASE   TTime(MAKE_TINT64(0x00dcddb3,0x0f2f8000))    // 00:00, Jan 1st 1970
    1.30 +
    1.31 +// external interface for the C library
    1.32 +
    1.33 +extern "C" {
    1.34 +
    1.35 +/*
    1.36 +Intended Usage:	The gettimeofday function obtains the current UTC time, which is 
    1.37 +				expressed as seconds and microseconds since 00:00:00 Coordinated Universal Time (UTC), 
    1.38 +				January 1, 1970, and stores it in a timeval structure.
    1.39 +				Please note that tz_minuteswest includes daytime saving. The struct member tz_dsttime is no 
    1.40 +				longer supported by Symbian OS and therefore set to Zero.
    1.41 +
    1.42 +*/
    1.43 +EXPORT_C 
    1.44 +int gettimeofday (struct timeval *tp, struct timezone *tzp)
    1.45 +    {
    1.46 +    if (tp)
    1.47 +	{
    1.48 +	TTime t;
    1.49 +	t.UniversalTime();
    1.50 +	
    1.51 +	TTimeIntervalSeconds sec;
    1.52 +	TInt err = t.SecondsFrom(UNIX_BASE, sec);
    1.53 +	if (err)
    1.54 +	    return -1;
    1.55 +	else
    1.56 +	    tp->tv_sec = sec.Int();
    1.57 +	t -= sec;
    1.58 +	TTimeIntervalMicroSeconds usec = t.MicroSecondsFrom(UNIX_BASE);
    1.59 +	TInt64 hackyfix = usec.Int64();	// because GetTInt() isn't declared const
    1.60 +	tp->tv_usec = I64INT(hackyfix);
    1.61 +	}
    1.62 +    if (tzp)
    1.63 +	{
    1.64 +	    tzp->tz_minuteswest = (User::UTCOffset().Int())/60;
    1.65 +	    tzp->tz_dsttime = 0;
    1.66 +	}
    1.67 +    return 0;
    1.68 +    }
    1.69 +
    1.70 +} // extern "C"