File: [OMI] / omi / base / Attic / time.c
(download)
Revision: 1.1,
Wed May 30 21:47:49 2012 UTC (12 years, 1 month ago) by mike
Branch: MAIN
Initial revision
|
/*
**==============================================================================
**
** Open Management Infrastructure (OMI)
**
** Copyright (c) Microsoft Corporation
**
** Licensed under the Apache License, Version 2.0 (the "License"); you may not
** use this file except in compliance with the License. You may obtain a copy
** of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
** MERCHANTABLITY OR NON-INFRINGEMENT.
**
** See the Apache 2 License for the specific language governing permissions
** and limitations under the License.
**
**==============================================================================
*/
#include "time.h"
#if defined(CONFIG_OS_WINDOWS)
# include <windows.h>
# include <time.h>
#elif defined(CONFIG_POSIX)
# include <unistd.h>
# include <time.h>
# include <sys/time.h>
# include <sys/types.h>
#endif
void Time_Sleep(MI_Uint64 msec)
{
#if defined(CONFIG_OS_WINDOWS)
Sleep((DWORD)msec);
#else
struct timespec ts;
ts.tv_sec = (long)(msec/1000);
ts.tv_nsec = (long)((msec%1000)*1000*1000);
nanosleep(&ts, NULL);
#endif
}
MI_Result Time_Now(
MI_Uint64* self)
{
#if defined(CONFIG_OS_WINDOWS)
FILETIME ft;
ULARGE_INTEGER tmp;
GetSystemTimeAsFileTime(&ft);
tmp.u.LowPart = ft.dwLowDateTime;
tmp.u.HighPart = ft.dwHighDateTime;
tmp.QuadPart -= 0X19DB1DED53E8000;
*self = tmp.QuadPart / (UINT64)10;
return MI_RESULT_OK;
#else
struct timeval tv;
struct timezone tz;
memset(&tv, 0, sizeof(tv));
memset(&tz, 0, sizeof(tz));
if (gettimeofday(&tv, &tz) != 0)
return MI_RESULT_FAILED;
*self = (MI_Uint64)tv.tv_sec * (MI_Uint64)1000000 + (MI_Uint64)tv.tv_usec;
return MI_RESULT_OK;
#endif
}