* @brief Sets the time of a specified clock. * * This function sets the time of the specified clock (identified by `clk`) to the given value. The time is provided * as a `struct timespec` containing seconds and nanoseconds. This function can be used to set the system clock or * other specific clocks, such as monotonic or real-time clocks. * * @param[in] clk The clock ID for which to set the
| 8031 | * @see sys_clock_gettime(), sys_clock_getres() |
| 8032 | */ |
| 8033 | sysret_t sys_clock_settime(clockid_t clk, const struct timespec *ts) |
| 8034 | { |
| 8035 | int ret = 0; |
| 8036 | #ifdef ARCH_MM_MMU |
| 8037 | size_t size = sizeof(struct timespec); |
| 8038 | struct timespec *kts = NULL; |
| 8039 | |
| 8040 | if (!lwp_user_accessable((void *)ts, size)) |
| 8041 | { |
| 8042 | return -EFAULT; |
| 8043 | } |
| 8044 | |
| 8045 | kts = kmem_get(size); |
| 8046 | if (!kts) |
| 8047 | { |
| 8048 | return -ENOMEM; |
| 8049 | } |
| 8050 | |
| 8051 | lwp_get_from_user(kts, (void *)ts, size); |
| 8052 | ret = clock_settime(clk, kts); |
| 8053 | if (ret < 0) |
| 8054 | { |
| 8055 | ret = GET_ERRNO(); |
| 8056 | } |
| 8057 | |
| 8058 | kmem_put(kts); |
| 8059 | |
| 8060 | return ret; |
| 8061 | #else |
| 8062 | if (!lwp_user_accessable((void *)ts, sizeof(struct timespec))) |
| 8063 | { |
| 8064 | return -EFAULT; |
| 8065 | } |
| 8066 | ret = clock_settime(clk, ts); |
| 8067 | return (ret < 0 ? GET_ERRNO() : ret); |
| 8068 | #endif |
| 8069 | } |
| 8070 | |
| 8071 | /** |
| 8072 | * @brief Retrieves the current time of a specified clock. |
nothing calls this directly
no test coverage detected