/*************************************************************** CPU-TIME-LINUX.H Linux/i386/ILP32 conversion helpers for the MCPU time ABI. PART OF : CPU - library . USAGE : Internal only . Copyright (C) 2026 by Andrew V.Kosteltsev. All Rights Reserved. ***************************************************************/ #ifndef __CPU_TIME_LINUX_H #define __CPU_TIME_LINUX_H #include #include static int __cpu_clockid_to_host( __mpu_uint64_t clockid, clockid_t *host_clockid ) { if( !host_clockid ) return( __MCPU_EFAULT ); switch( clockid ) { case __CPU_CLOCK_REALTIME: *host_clockid = CLOCK_REALTIME; return( 0 ); case __CPU_CLOCK_MONOTONIC: *host_clockid = CLOCK_MONOTONIC; return( 0 ); default: return( __MCPU_EINVAL ); } } /* End of __cpu_clockid_to_host() */ static int __cpu_timespec_from_host( struct __cpu_timespec *dst, const struct timespec *src ) { __mpu_int64_t sec; __mpu_int64_t nsec; if( !dst || !src ) return( __MCPU_EFAULT ); sec = (__mpu_int64_t)src->tv_sec; if( (time_t)sec != src->tv_sec ) return( __MCPU_EOVERFLOW ); nsec = (__mpu_int64_t)src->tv_nsec; if( (long)nsec != src->tv_nsec ) return( __MCPU_EOVERFLOW ); if( nsec < 0 || nsec > 999999999 ) return( __MCPU_EOVERFLOW ); dst->tv_sec = sec; dst->tv_nsec = nsec; return( 0 ); } /* End of __cpu_timespec_from_host() */ #endif /* __CPU_TIME_LINUX_H */