| /* A part of the Native C Library for Windows NT |
| 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 <windows.h> |
| #include <nt.h> |
| #include <errno.h> |
| #include <sys/time.h> |
| |
| int clock_gettime(clockid_t clock_id, struct timespec *tp) { |
| if(!tp) { |
| errno = EFAULT; |
| return -1; |
| } |
| switch(clock_id) { |
| case CLOCK_REALTIME: { |
| LARGE_INTEGER li; |
| long int status = NtQuerySystemTime(&li); |
| if(status < 0) { |
| __set_errno_from_ntstatus(status); |
| return -1; |
| } |
| __hurdred_nanoseconds_since_1601_to_timespec(&li, tp); |
| return 0; |
| } |
| case CLOCK_MONOTONIC: { |
| #if 0 /* NtGetTickCount is not exists in Windows NT 5.1 */ |
| unsigned long int t = NtGetTickCount(); |
| tp->tv_sec = t / 1000; |
| //tp->tv_nsec = (t - tp->tv_sec * 1000) * 1000000; |
| tp->tv_nsec = (t % 1000) * 1000000; |
| #else |
| unsigned long int t = USER_SHARED_DATA->TickCountLow; |
| tp->tv_sec = t / 100; |
| tp->tv_nsec = (t % 100) * 10000000; |
| #endif |
| return 0; |
| } |
| default: |
| errno = EINVAL; |
| return -1; |
| } |
| } |