[Scummvm-devel] ATTN: Porters. Notes about time() implementation and thumbnails
Marcus Comstedt
marcus at mc.pp.se
Wed Oct 12 05:08:29 CEST 2005
Johannes Schickel <lordhoto at gmail.com> writes:
> Hi,
>
> since patch #1259034 ( Scumm Savegame Informations ) is applied it
> would be nice to have a correct time() impelemtation, I've looked at
> WinCE and Palm port and both seems to return the seconds since 1 Jan
> 1970 localtime and not GMT, it would be better that this is fixed
> before 0.8.0 Release, I think.
I disagree with this.
*) I don't know about WinCE and Palm, but for Dreamcast I have no way
of figuring out what timezone I'm in, and so now way of producing a
timestamp relative to GMT.
*) ISO says that "The time function determines the current calendar
time. The encoding of the value is unspecified." Thus you are
wrong in implying that an implementation which returns an encoding
based on localtime is not correct. Any encoding is considered
valid by the standard.
*) Why would the savegame system want GMT anyway? The answer is of
course that it doesn't. It just wants something to pass to
localtime(). Which is ok. The combination time() + localtime()
will give you the time in the local timezone in a standard format;
this is guaranteed by the C standard.
So, there are two things which might need fixing, none of which is the
representation returned by time() (since this is explicitly left as
unspecified by the standard):
A) _If_ the combination time() + localtime() (when run on the same
system) does not produce the correct values on one of the systems
you mention, then their _localtime_ needs fixing.
B) Looking at the patch, it seems like the code incorrectly assumes
that time_t (1) is <=32 bits, (2) has a common representation
across systems (given the ambition that savegames should be
portable between systems, which is suggested by the use of
serialization functions). Both these assumptions lack support in
the C standard. Instead of writing the time_t to the savefile, you
should write either the fields of the struct tm, which are well
specified and with known ranges, or simply the "date" and "time"
values computed from this struct:
stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
as these are also portable.
// Marcus
More information about the Scummvm-devel
mailing list