From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60429 invoked by alias); 3 Nov 2019 20:09:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 60421 invoked by uid 89); 3 Nov 2019 20:09:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-28.7 required=5.0 tests=AWL,BAYES_00,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_JMF_BL,SPF_PASS,USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy=manpage, xml, XML, googlecom X-HELO: mail-oi1-f193.google.com Received: from mail-oi1-f193.google.com (HELO mail-oi1-f193.google.com) (209.85.167.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 03 Nov 2019 20:09:34 +0000 Received: by mail-oi1-f193.google.com with SMTP id m193so12396911oig.0 for ; Sun, 03 Nov 2019 12:09:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CIjxDoBM0mIj7m/+Aw9cHBpsI3WH5xjjQMXwm/unjBA=; b=lWvHiM2erEhQpizcAd2YMMV4sTPhkw49fjYQl9BwlLfuGcrfIYXg0i+zuGXna7bWC9 9/D47HHOchfJdpDG4b7WpCiNQsg01dAXR5ROljSEQEDq+rJS/QhTQffOADYw7EUINWQK xuLtkRSmc2reUOe/Jjh0eWnEvis4F14CFWOsaaBpgG4pgX/Qs6G5qKeLn9bIuPBMTEuI rwML8QC4O0EUno57HeKAuaZh9aCZ5bxrpSg5LuNo5HGqpiQPnVFSLbJ0DZQ/mJVSQxdW oXbz1o4tIJZkslIcgs6LJ//bFp1n/33+g1XcPRtzimYm1Lo3jsDs7m54S+nvWMeG/6ml kumw== MIME-Version: 1.0 References: <20191103025430.BD90720AF6@gnutoolchain-gerrit.osci.io> <87pni9h1e3.fsf@hase.home> In-Reply-To: <87pni9h1e3.fsf@hase.home> From: "Christian Biesinger via gdb-patches" Reply-To: Christian Biesinger Date: Sun, 03 Nov 2019 20:09:00 -0000 Message-ID: Subject: Re: [review v2] Use ctime_r and localtime_r if available To: Andreas Schwab Cc: "Christian Biesinger (Code Review)" , gdb-patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-11/txt/msg00058.txt.bz2 On Sun, Nov 3, 2019 at 2:20 AM Andreas Schwab wrote: > > On Nov 02 2019, Christian Biesinger (Code Review) wrote: > > > diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c > > index 67f9f3a..e0bad81 100644 > > --- a/gdb/nat/linux-osdata.c > > +++ b/gdb/nat/linux-osdata.c > > @@ -912,7 +912,13 @@ > > { > > time_t t = (time_t) seconds; > > > > - strncpy (time, ctime (&t), maxlen); > > + char buf[30]; > > +#ifdef HAVE_CTIME_R > > + const char *time_str = ctime_r (&t, buf); > > +#else > > + const char *time_str = ctime (&t); > > +#endif > > buf is unused if !HAVE_CTIME_R. Thanks, fixed. > Note that both ctime and ctime_r are obsolescent and should be replaced > by strftime. gdb currently doesn't setlocale LC_TIME, but if it does it > would make the use of these functions undefined. I read through the manpage for ctime/ctime_r and I don't see any note that the behavior is undefined when setlocale is called, or that it is obsolete. For completeness, I also looked at the Solaris manpage and it does not say that either. Instead, it will use a locale-independent format, which seems desirable here since it is serialized into XML. Christian