time32.c revision 85634
1/*-
2 * Copyright (c) 2001 FreeBSD Inc.
3 * All rights reserved.
4 *
5 * These routines are for converting time_t to fixed-bit representations
6 * for use in protocols or storage.  When converting time to a larger
7 * representation of time_t these routines are expected to assume temporal
8 * locality and use the 50-year rule to properly set the msb bits.  XXX
9 *
10 * Redistribution and use under the terms of the COPYRIGHT file at the
11 * base of the source tree.
12 *
13 * $FreeBSD: head/lib/libc/stdtime/time32.c 85634 2001-10-28 19:54:49Z dillon $
14 */
15
16#include <sys/types.h>
17#include <sys/time.h>
18
19/*
20 * Convert a 32 bit representation of time_t into time_t.  XXX needs to
21 * implement the 50-year rule to handle post-2038 conversions.
22 */
23time_t
24time32_to_time(__int32_t t32)
25{
26    return((time_t)t32);
27}
28
29/*
30 * Convert time_t to a 32 bit representation.  If time_t is 64 bits we can
31 * simply chop it down.   The resulting 32 bit representation can be
32 * converted back to a temporally local 64 bit time_t using time32_to_time.
33 */
34__int32_t
35time_to_time32(time_t t)
36{
37    return((__int32_t)t);
38}
39
40/*
41 * Convert a 64 bit representation of time_t into time_t.  If time_t is
42 * represented as 32 bits we can simply chop it and not support times
43 * past 2038.
44 */
45time_t
46time64_to_time(__int64_t t64)
47{
48    return((time_t)t64);
49}
50
51/*
52 * Convert time_t to a 64 bit representation.  If time_t is represented
53 * as 32 bits we simply sign-extend and do not support times past 2038.
54 */
55__int64_t
56time_to_time64(time_t t)
57{
58    return((__int64_t)t);
59}
60
61