timegm.3: Remove sample implementation of timegm()

Stephen and Mats both question the wisdom of showing a portable
*non-thread-safe* implementation of timegm(), and I find it
hard to disagree. So, remove this code.

See https://bugzilla.kernel.org/show_bug.cgi?id=103701

Reported-by: Stephen Hurd <shurd@sasktel.net>
Reported-by: Mats Wichmann <mats@linuxfoundation.org>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2016-03-10 19:26:55 +01:00
parent 813596e5f2
commit 25a0440e45
1 changed files with 1 additions and 39 deletions

View File

@ -70,51 +70,13 @@ T} Thread safety MT-Safe env locale
.SH CONFORMING TO
These functions are nonstandard GNU extensions
that are also present on the BSDs.
Avoid their use; see NOTES.
Avoid their use.
.SH NOTES
The
.BR timelocal ()
function is equivalent to the POSIX standard function
.BR mktime (3).
There is no reason to ever use it.
.LP
For a portable version of
.BR timegm (),
set the
.B TZ
environment variable to UTC, call
.BR mktime (3)
and restore the value of
.BR TZ .
Something like
.in +4n
.nf
#include <time.h>
#include <stdlib.h>
time_t
my_timegm(struct tm *tm)
{
time_t ret;
char *tz;
tz = getenv("TZ");
if (tz)
tz = strdup(tz);
setenv("TZ", "", 1);
tzset();
ret = mktime(tm);
if (tz) {
setenv("TZ", tz, 1);
free(tz);
} else
unsetenv("TZ");
tzset();
return ret;
}
.fi
.in
.SH SEE ALSO
.BR gmtime (3),
.BR localtime (3),