[review v3] Use ctime_r and localtime_r if available

Kevin Buettner (Code Review)
2019-11-10T07:45:34Z

Kevin Buettner has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/475
......................................................................

Patch Set 3:

(1 comment)

> Patch Set 3: Code-Review+2

Only one small nit in gdb/nat/linux-osdata.c - I suggest adding a comment. Aside from that, it looks good to me.

| --- gdb/nat/linux-osdata.c
| +++ gdb/nat/linux-osdata.c
| @@ -908,12 +908,18 @@ time_from_time_t (char *time, int maxlen, TIME_T seconds)
| {
| if (!seconds)
| time[0] = '\0';
| else
| {
| time_t t = (time_t) seconds;
|
| - strncpy (time, ctime (&t), maxlen);
| +#ifdef HAVE_CTIME_R
| + char buf[30];

PS3, Line 916:

Perhaps add a comment here stating that the ctime_r man page states
that the user supplied buffer needs to be 26 bytes or larger?

| + const char *time_str = ctime_r (&t, buf);
| +#else
| + const char *time_str = ctime (&t);
| +#endif
| + strncpy (time, time_str, maxlen);
| time[maxlen - 1] = '\0';
| }
| }
|

--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd
Gerrit-Change-Number: 475
Gerrit-PatchSet: 3
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Kevin Buettner <kevinb@redhat.com>
Gerrit-Comment-Date: Sun, 10 Nov 2019 07:45:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment