time32.c revision 85634
185634Sdillon/*-
285634Sdillon * Copyright (c) 2001 FreeBSD Inc.
385634Sdillon * All rights reserved.
485634Sdillon *
585634Sdillon * These routines are for converting time_t to fixed-bit representations
685634Sdillon * for use in protocols or storage.  When converting time to a larger
785634Sdillon * representation of time_t these routines are expected to assume temporal
885634Sdillon * locality and use the 50-year rule to properly set the msb bits.  XXX
985634Sdillon *
1085634Sdillon * Redistribution and use under the terms of the COPYRIGHT file at the
1185634Sdillon * base of the source tree.
1285634Sdillon *
1385634Sdillon * $FreeBSD: head/lib/libc/stdtime/time32.c 85634 2001-10-28 19:54:49Z dillon $
1485634Sdillon */
1585634Sdillon
1685634Sdillon#include <sys/types.h>
1785634Sdillon#include <sys/time.h>
1885634Sdillon
1985634Sdillon/*
2085634Sdillon * Convert a 32 bit representation of time_t into time_t.  XXX needs to
2185634Sdillon * implement the 50-year rule to handle post-2038 conversions.
2285634Sdillon */
2385634Sdillontime_t
2485634Sdillontime32_to_time(__int32_t t32)
2585634Sdillon{
2685634Sdillon    return((time_t)t32);
2785634Sdillon}
2885634Sdillon
2985634Sdillon/*
3085634Sdillon * Convert time_t to a 32 bit representation.  If time_t is 64 bits we can
3185634Sdillon * simply chop it down.   The resulting 32 bit representation can be
3285634Sdillon * converted back to a temporally local 64 bit time_t using time32_to_time.
3385634Sdillon */
3485634Sdillon__int32_t
3585634Sdillontime_to_time32(time_t t)
3685634Sdillon{
3785634Sdillon    return((__int32_t)t);
3885634Sdillon}
3985634Sdillon
4085634Sdillon/*
4185634Sdillon * Convert a 64 bit representation of time_t into time_t.  If time_t is
4285634Sdillon * represented as 32 bits we can simply chop it and not support times
4385634Sdillon * past 2038.
4485634Sdillon */
4585634Sdillontime_t
4685634Sdillontime64_to_time(__int64_t t64)
4785634Sdillon{
4885634Sdillon    return((time_t)t64);
4985634Sdillon}
5085634Sdillon
5185634Sdillon/*
5285634Sdillon * Convert time_t to a 64 bit representation.  If time_t is represented
5385634Sdillon * as 32 bits we simply sign-extend and do not support times past 2038.
5485634Sdillon */
5585634Sdillon__int64_t
5685634Sdillontime_to_time64(time_t t)
5785634Sdillon{
5885634Sdillon    return((__int64_t)t);
5985634Sdillon}
6085634Sdillon
61