diff --git a/libc/include/llvm-libc-types/time_t.h b/libc/include/llvm-libc-types/time_t.h --- a/libc/include/llvm-libc-types/time_t.h +++ b/libc/include/llvm-libc-types/time_t.h @@ -9,6 +9,10 @@ #ifndef __LLVM_LIBC_TYPES_TIME_T_H__ #define __LLVM_LIBC_TYPES_TIME_T_H__ +#if (defined(__arm__) || defined(_M_ARM)) typedef __INTPTR_TYPE__ time_t; +#else +typedef __INT64_TYPE__ time_t; +#endif #endif // __LLVM_LIBC_TYPES_TIME_T_H__ diff --git a/libc/src/time/linux/clockGetTimeImpl.h b/libc/src/time/linux/clockGetTimeImpl.h --- a/libc/src/time/linux/clockGetTimeImpl.h +++ b/libc/src/time/linux/clockGetTimeImpl.h @@ -14,6 +14,7 @@ #include "src/__support/error_or.h" #include "src/errno/libc_errno.h" +#include // For int64_t. #include // For syscall numbers. #include @@ -27,12 +28,12 @@ static_cast(clockid), reinterpret_cast(ts)); #elif defined(SYS_clock_gettime64) - struct timespec64 ts64; + static_assert( + sizeof(time_t) == sizeof(int64_t), + "SYS_clock_gettime64 requires struct timespec with 64-bit members."); int ret = __llvm_libc::syscall_impl(SYS_clock_gettime64, static_cast(clockid), - reinterpret_cast(&ts64)); - ts->tv_sec = static_cast(ts64.tv_sec); - ts->tv_nsec = static_cast(ts64.tv_nsec); + reinterpret_cast(ts)); #else #error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available." #endif diff --git a/libc/src/time/linux/nanosleep.cpp b/libc/src/time/linux/nanosleep.cpp --- a/libc/src/time/linux/nanosleep.cpp +++ b/libc/src/time/linux/nanosleep.cpp @@ -12,6 +12,7 @@ #include "src/__support/common.h" #include "src/errno/libc_errno.h" +#include // For int64_t. #include // For syscall numbers. namespace __llvm_libc { @@ -21,8 +22,11 @@ #if SYS_nanosleep int ret = __llvm_libc::syscall_impl(SYS_nanosleep, req, rem); #elif defined(SYS_clock_nanosleep_time64) - int ret = - __llvm_libc::syscall_impl(SYS_clock_nanosleep_time64, req, rem); + static_assert( + sizeof(time_t) == sizeof(int64_t), + "SYS_clock_gettime64 requires struct timespec with 64-bit members."); + int ret = __llvm_libc::syscall_impl(SYS_clock_nanosleep_time64, + CLOCK_REALTIME, 0, req, rem); #else #error "SYS_nanosleep and SYS_clock_nanosleep_time64 syscalls not available." #endif