| #include <stdio.h>
|
| #include <time.h>
|
|
|
| struct timespec *set_timer(struct timespec *ts, int ms) {
|
| clock_gettime(CLOCK_REALTIME, ts);
|
| ts->tv_sec += ms / 1000;
|
| ts->tv_nsec += (ms % 1000) * 1000000;
|
|
|
| return ts;
|
| }
|
|
|
| int main() {
|
| struct timespec now;
|
|
|
| clock_gettime(CLOCK_REALTIME, &now);
|
| set_timer(&now, 1000);
|
| printf("sec: %lld\n", now.tv_sec);
|
| printf("nsec: %ld\n", now.tv_nsec);
|
|
|
| return 0;
|
| }
|