Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions uspace/lib/posix/include/posix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <libc/time.h>

#define CLOCK_REALTIME ((clockid_t) 0)
#define CLOCK_MONOTONIC ((clockid_t) 1)

#define ASCTIME_BUF_LEN 26

Expand Down
9 changes: 7 additions & 2 deletions uspace/lib/posix/src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ char *ctime(const time_t *timep)
}

/**
* Get clock resolution. Only CLOCK_REALTIME is supported.
* Get clock resolution.
*
* @param clock_id Clock ID.
* @param res Pointer to the variable where the resolution is to be written.
Expand All @@ -217,6 +217,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res)

switch (clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
res->tv_sec = 0;
res->tv_nsec = USEC2NSEC(1); /* Microsecond resolution. */
return 0;
Expand All @@ -227,7 +228,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
}

/**
* Get time. Only CLOCK_REALTIME is supported.
* Get time.
*
* @param clock_id ID of the clock to query.
* @param tp Pointer to the variable where the time is to be written.
Expand All @@ -245,6 +246,9 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = USEC2NSEC(tv.tv_usec);
return 0;
case CLOCK_MONOTONIC:
getuptime(tp);
return 0;
default:
errno = EINVAL;
return -1;
Expand All @@ -266,6 +270,7 @@ int clock_settime(clockid_t clock_id,

switch (clock_id) {
case CLOCK_REALTIME:
case CLOCK_MONOTONIC:
// TODO: setting clock
// FIXME: HelenOS doesn't actually support hardware
// clock yet
Expand Down