I saw a cookie with an expiration date of 2039, which is beyond the end of the universe for me, so it turned into 1903. So I made this, and it's working for me, but maybe you will know a nicer calculation, or a portability subtlety that I should handle.
On Wed, Dec 30, 2009 at 07:32:19PM +0000, corvid wrote:
... but maybe you will know a nicer calculation, or a portability subtlety that I should handle.
[...] +#define DILLO_TIME_MAX ((time_t) ((1UL << (sizeof(time_t) * 8 - 1)) - 1))
Quoting "man -S 0p types.h" * time_t and clock_t shall be integer or real-floating types. So at least in theory you should not assume that time_t is an integer type. I've no idea how likely that is to be wrong in practice. (On my system time_t is long.) Unfortunatly "man sysconf" does not describe any maximum time value constant. Some Googling suggests that time_t is almost always a signed integer type. This is interesting: http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=lib/mktime.c /* The maximum and minimum values for the integer type T. These macros have undefined behavior if T is signed and has padding bits. If this is a problem for you, please let us know how to fix it for your host. */ #define TYPE_MINIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ ? (t) 0 \ : TYPE_SIGNED_MAGNITUDE (t) \ ? ~ (t) 0 \ : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) #define TYPE_MAXIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ ? (t) -1 \ : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) Regards, Jeremy Henty
Jeremy wrote:
On Wed, Dec 30, 2009 at 07:32:19PM +0000, corvid wrote:
... but maybe you will know a nicer calculation, or a portability subtlety that I should handle.
[...] +#define DILLO_TIME_MAX ((time_t) ((1UL << (sizeof(time_t) * 8 - 1)) - 1))
Quoting "man -S 0p types.h"
* time_t and clock_t shall be integer or real-floating types.
So at least in theory you should not assume that time_t is an integer type. I've no idea how likely that is to be wrong in practice. (On my system time_t is long.) Unfortunatly "man sysconf" does not describe any maximum time value constant.
Hmm... well, at least it wouldn't be any worse than it already is! There's a bunch of time_t <-> long in dpi/cookies.c.
participants (2)
-
corvid@lavabit.com
-
onepoint@starurchin.org