| /* A part of the Windows CE C Extra Library (celibc) |
| Copyright 2007-2015 PC GO Ld. |
| |
| This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| */ |
| |
| #include <time.h> |
| #include <errno.h> |
| #include <windows.h> |
| #include <shared.h> |
| |
| #if _WCE >= 3 |
| void GetCurrentFT(FILETIME *); |
| #endif |
| |
| int clock_gettime(clockid_t clock_id, struct timespec *tp) { |
| if(!tp) { |
| errno = EFAULT; |
| return -1; |
| } |
| switch(clock_id) { |
| case CLOCK_REALTIME: { |
| FILETIME ft; |
| #if _WCE >= 3 |
| GetCurrentFT(&ft); |
| #else |
| SYSTEMTIME st; |
| GetSystemTime(&st); |
| if(!SystemTimeToFileTime(&st, &ft)) return -1; |
| #endif |
| __filetime_to_timespec(&ft, tp); |
| return 0; |
| } |
| case CLOCK_MONOTONIC: { |
| //t = timeGetTime(); // _WCE 4.2 |
| unsigned long int t = GetTickCount(); |
| tp->tv_sec = t / 1000; |
| //tp->tv_nsec = (t - tp->tv_sec * 1000) * 1000000; |
| tp->tv_nsec = (t % 1000) * 1000000; |
| return 0; |
| } |
| default: |
| errno = EINVAL; |
| return -1; |
| } |
| } |