(file) Return to time.c CVS log (file) (dir) Up to [OMI] / omi / base

 1 mike  1.1 /*
 2           **==============================================================================
 3           **
 4           ** Open Management Infrastructure (OMI)
 5           **
 6           ** Copyright (c) Microsoft Corporation
 7           ** 
 8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 9           ** use this file except in compliance with the License. You may obtain a copy 
10           ** of the License at 
11           **
12           **     http://www.apache.org/licenses/LICENSE-2.0 
13           **
14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
18           **
19           ** See the Apache 2 License for the specific language governing permissions 
20           ** and limitations under the License.
21           **
22 mike  1.1 **==============================================================================
23           */
24           
25           #include "time.h"
26           
27           #if defined(CONFIG_OS_WINDOWS)
28           # include <windows.h>
29           # include <time.h>
30           #elif defined(CONFIG_POSIX)
31           # include <unistd.h>
32           # include <time.h>
33           # include <sys/time.h>
34           # include <sys/types.h>
35           #endif
36           
37           void Time_Sleep(MI_Uint64 msec)
38           {
39           #if defined(CONFIG_OS_WINDOWS)
40               Sleep((DWORD)msec);
41           #else
42               struct timespec ts;
43 mike  1.1     ts.tv_sec = (long)(msec/1000);
44               ts.tv_nsec = (long)((msec%1000)*1000*1000);
45               nanosleep(&ts, NULL);
46           #endif
47           }
48           
49           MI_Result Time_Now(
50               MI_Uint64* self)
51           {
52           #if defined(CONFIG_OS_WINDOWS)
53               FILETIME ft;
54               ULARGE_INTEGER tmp;
55           
56               GetSystemTimeAsFileTime(&ft);
57               tmp.u.LowPart = ft.dwLowDateTime;
58               tmp.u.HighPart = ft.dwHighDateTime;
59               tmp.QuadPart -= 0X19DB1DED53E8000;
60               *self = tmp.QuadPart / (UINT64)10;
61               return MI_RESULT_OK;
62           #else
63               struct timeval tv;
64 mike  1.1     struct timezone tz;
65               memset(&tv, 0, sizeof(tv));
66               memset(&tz, 0, sizeof(tz));
67           
68               if (gettimeofday(&tv, &tz) != 0)
69                   return MI_RESULT_FAILED;
70           
71               *self = (MI_Uint64)tv.tv_sec * (MI_Uint64)1000000 + (MI_Uint64)tv.tv_usec;
72               return MI_RESULT_OK;
73           #endif
74           }

ViewCVS 0.9.2