diff --git a/include/time.h b/include/time.h index 6cff71399139..9143cbc3ef98 100644 --- a/include/time.h +++ b/include/time.h @@ -140,6 +140,10 @@ time_t time32_to_time __P((__int32_t t32)); __int32_t time_to_time32 __P((time_t t)); time_t time64_to_time __P((__int64_t t64)); __int64_t time_to_time64 __P((time_t t)); +long time_to_long __P((time_t t)); +time_t long_to_time __P((long tlong)); +int time_to_int __P((time_t t)); +time_t int_to_time __P((int tint)); #endif /* not ANSI */ #ifndef _ANSI_SOURCE diff --git a/lib/libc/stdtime/time32.c b/lib/libc/stdtime/time32.c index 4886f7c036a5..ed3d3e0ced56 100644 --- a/lib/libc/stdtime/time32.c +++ b/lib/libc/stdtime/time32.c @@ -58,3 +58,43 @@ time_to_time64(time_t t) return((__int64_t)t); } +/* + * Convert to/from 'long'. Depending on the sizeof(long) this may or + * may not require using the 50-year rule. + */ +long +time_to_long(time_t t) +{ + if (sizeof(long) == sizeof(__int64_t)) + return(time_to_time64(t)); + return((long)t); +} + +time_t +long_to_time(long tlong) +{ + if (sizeof(long) == sizeof(__int32_t)) + return(time32_to_time(tlong)); + return((time_t)tlong); +} + +/* + * Convert to/from 'int'. Depending on the sizeof(int) this may or + * may not require using the 50-year rule. + */ +int +time_to_int(time_t t) +{ + if (sizeof(int) == sizeof(__int64_t)) + return(time_to_time64(t)); + return((int)t); +} + +time_t +int_to_time(int tint) +{ + if (sizeof(int) == sizeof(__int32_t)) + return(time32_to_time(tint)); + return((time_t)tint); +} +