From: Michael Kerrisk <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: "Jérémie Galarneau"
<jeremie.galarneau-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [patch] timegm.3: copy the string returned by getenv()
Date: Thu, 27 Jun 2013 00:30:43 +0200 [thread overview]
Message-ID: <51CB6B93.2060400@gmail.com> (raw)
In-Reply-To: <1372259329-26397-1-git-send-email-jeremie.galarneau-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
On 06/26/13 17:08, Jérémie Galarneau wrote:
> The example of a portable version of timegm() uses the string returned by
> getenv() after calling setenv() on the same environment variale. The tz
> string may be invalid as per getenv.3:
>
> "The string pointed to by the return value of getenv() may be statically
> allocated, and can be modified by a subsequent call to getenv(), putenv(3),
> setenv(3), or unsetenv(3)."
>
> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Thanks, Jérémie. I've applied your patch.
Cheers,
Michael
> ---
> man3/timegm.3 | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/man3/timegm.3 b/man3/timegm.3
> index 3ab194b..0e71be5 100644
> --- a/man3/timegm.3
> +++ b/man3/timegm.3
> @@ -84,12 +84,15 @@ my_timegm(struct tm *tm)
> char *tz;
>
> tz = getenv("TZ");
> + if (tz)
> + tz = strdup(tz);
> setenv("TZ", "", 1);
> tzset();
> ret = mktime(tm);
> - if (tz)
> + if (tz) {
> setenv("TZ", tz, 1);
> - else
> + free(tz);
> + } else
> unsetenv("TZ");
> tzset();
> return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2013-06-26 22:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-26 15:08 [patch] timegm.3: copy the string returned by getenv() Jérémie Galarneau
[not found] ` <1372259329-26397-1-git-send-email-jeremie.galarneau-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2013-06-26 22:30 ` Michael Kerrisk [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51CB6B93.2060400@gmail.com \
--to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=jeremie.galarneau-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).