usched: Implement LWP lazy migration support.
[dragonfly.git] / lib / libc / stdtime / time32.c
blobd6ee06fdb11e00ebde8f24a1643c895e7c93d5e8
1 /*-
2 * Copyright (c) 2001 FreeBSD Inc.
3 * All rights reserved.
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
10 * Redistribution and use under the terms of the COPYRIGHT file at the
11 * base of the source tree.
13 * $FreeBSD: head/lib/libc/stdtime/time32.c 98313 2002-06-17 01:42:33Z wollman $
16 #include <sys/types.h>
17 #include <timeconv.h>
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.
23 time_t
24 _time32_to_time(__int32_t t32)
26 return((time_t)t32);
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.
34 __int32_t
35 _time_to_time32(time_t t)
37 return((__int32_t)t);
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.
45 time_t
46 _time64_to_time(__int64_t t64)
48 return((time_t)t64);
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.
55 __int64_t
56 _time_to_time64(time_t t)
58 return((__int64_t)t);
62 * Convert to/from 'long'. Depending on the sizeof(long) this may or
63 * may not require using the 50-year rule.
65 long
66 _time_to_long(time_t t)
68 if (sizeof(long) == sizeof(__int64_t))
69 return(_time_to_time64(t));
70 return((long)t);
73 time_t
74 _long_to_time(long tlong)
76 if (sizeof(long) == sizeof(__int32_t))
77 return(_time32_to_time(tlong));
78 return((time_t)tlong);
82 * Convert to/from 'int'. Depending on the sizeof(int) this may or
83 * may not require using the 50-year rule.
85 int
86 _time_to_int(time_t t)
88 if (sizeof(int) == sizeof(__int64_t))
89 return(_time_to_time64(t));
90 return((int)t);
93 time_t
94 _int_to_time(int tint)
96 if (sizeof(int) == sizeof(__int32_t))
97 return(_time32_to_time(tint));
98 return((time_t)tint);