Article View: comp.std.c
Article #2418Re: Questions about mktime() - and answer
From: Karl Heuer
Date: Thu, 14 Feb 1991 03:24
Date: Thu, 14 Feb 1991 03:24
16 lines
1349 bytes
1349 bytes
In article <1991Feb8.062954.13509@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes:
>time_t mktime(struct tm *tp) { ...
> *tp = *localtime(&t); /* set other fields in structure */
> return(t);
>}
Sorry, this violates the Standard. "The implementation shall behave as if
no other library function calls [localtime()]." [4.12.3]. In particular,
the user has the right to assume that the static structure maintained by
localtime() is not destroyed by a call to mktime().
Fix: move the guts of localtime() into void _do_time(time_t, struct tm *),
reimplement localtime(time_t *pt) as _do_time(*pt, &statictm), and change
"*tp = *localtime(&t);" in mktime() to "_do_time(t, tp)".
Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
Technical Details
Message-ID:
<1991Feb14.032409.27062@dirtydog.ima.isc.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!ima!dirtydog!karlReferences:
<1991Feb8.062954.13509@druid.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!ima!dirtydog!karl From: karl@ima.isc.com (Karl Heuer) Newsgroups: comp.std.c Subject: Re: Questions about mktime() - and answer Message-ID: <1991Feb14.032409.27062@dirtydog.ima.isc.com> Date: 14 Feb 91 03:24:09 GMT References: <1991Feb8.062954.13509@druid.uucp> Sender: news@dirtydog.ima.isc.com (NEWS ADMIN) Reply-To: karl@ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 16