]>
git.saurik.com Git - apple/libc.git/blob - stdtime/time32-fbsd.c
2 * Copyright (c) 2001 FreeBSD Inc.
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.
14 #include <sys/cdefs.h>
15 __FBSDID("$FreeBSD: src/lib/libc/stdtime/time32.c,v 1.5 2002/06/17 01:42:29 wollman Exp $");
17 #include <sys/types.h>
21 * Convert a 32 bit representation of time_t into time_t. XXX needs to
22 * implement the 50-year rule to handle post-2038 conversions.
25 _time32_to_time(__int32_t t32
)
31 * Convert time_t to a 32 bit representation. If time_t is 64 bits we can
32 * simply chop it down. The resulting 32 bit representation can be
33 * converted back to a temporally local 64 bit time_t using time32_to_time.
36 _time_to_time32(time_t t
)
42 * Convert a 64 bit representation of time_t into time_t. If time_t is
43 * represented as 32 bits we can simply chop it and not support times
47 _time64_to_time(__int64_t t64
)
53 * Convert time_t to a 64 bit representation. If time_t is represented
54 * as 32 bits we simply sign-extend and do not support times past 2038.
57 _time_to_time64(time_t t
)
63 * Convert to/from 'long'. Depending on the sizeof(long) this may or
64 * may not require using the 50-year rule.
67 _time_to_long(time_t t
)
69 if (sizeof(long) == sizeof(__int64_t
))
70 return(_time_to_time64(t
));
75 _long_to_time(long tlong
)
77 if (sizeof(long) == sizeof(__int32_t
))
78 return(_time32_to_time(tlong
));
79 return((time_t)tlong
);
83 * Convert to/from 'int'. Depending on the sizeof(int) this may or
84 * may not require using the 50-year rule.
87 _time_to_int(time_t t
)
89 if (sizeof(int) == sizeof(__int64_t
))
90 return(_time_to_time64(t
));
95 _int_to_time(int tint
)
97 if (sizeof(int) == sizeof(__int32_t
))
98 return(_time32_to_time(tint
));