/*-1* Copyright (c) 2001 FreeBSD Inc.2* All rights reserved.3*4* These routines are for converting time_t to fixed-bit representations5* for use in protocols or storage. When converting time to a larger6* representation of time_t these routines are expected to assume temporal7* locality and use the 50-year rule to properly set the msb bits. XXX8*9* Redistribution and use under the terms of the COPYRIGHT file at the10* base of the source tree.11*/1213#include <sys/types.h>14#include <timeconv.h>1516/*17* Convert a 32 bit representation of time_t into time_t. XXX needs to18* implement the 50-year rule to handle post-2038 conversions.19*/20time_t21_time32_to_time(__int32_t t32)22{23return((time_t)t32);24}2526/*27* Convert time_t to a 32 bit representation. If time_t is 64 bits we can28* simply chop it down. The resulting 32 bit representation can be29* converted back to a temporally local 64 bit time_t using time32_to_time.30*/31__int32_t32_time_to_time32(time_t t)33{34return((__int32_t)t);35}3637/*38* Convert a 64 bit representation of time_t into time_t. If time_t is39* represented as 32 bits we can simply chop it and not support times40* past 2038.41*/42time_t43_time64_to_time(__int64_t t64)44{45return((time_t)t64);46}4748/*49* Convert time_t to a 64 bit representation. If time_t is represented50* as 32 bits we simply sign-extend and do not support times past 2038.51*/52__int64_t53_time_to_time64(time_t t)54{55return((__int64_t)t);56}5758/*59* Convert to/from 'long'. Depending on the sizeof(long) this may or60* may not require using the 50-year rule.61*/62long63_time_to_long(time_t t)64{65if (sizeof(long) == sizeof(__int64_t))66return(_time_to_time64(t));67return((long)t);68}6970time_t71_long_to_time(long tlong)72{73if (sizeof(long) == sizeof(__int32_t))74return(_time32_to_time(tlong));75return((time_t)tlong);76}7778/*79* Convert to/from 'int'. Depending on the sizeof(int) this may or80* may not require using the 50-year rule.81*/82int83_time_to_int(time_t t)84{85if (sizeof(int) == sizeof(__int64_t))86return(_time_to_time64(t));87return((int)t);88}8990time_t91_int_to_time(int tint)92{93if (sizeof(int) == sizeof(__int32_t))94return(_time32_to_time(tint));95return((time_t)tint);96}979899