MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_clock_settime

Function sys_clock_settime

components/lwp/lwp_syscall.c:8033–8069  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

8031 * @see sys_clock_gettime(), sys_clock_getres()
8032 */
8033sysret_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.

Callers

nothing calls this directly

Calls 5

lwp_user_accessableFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
clock_settimeFunction · 0.85
kmem_putFunction · 0.85

Tested by

no test coverage detected