public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH/committed 2/5] sim: m32r: migrate ftime() to clock_gettime()
Date: Wed, 10 Jan 2024 22:37:44 -0500	[thread overview]
Message-ID: <20240111033747.17795-2-vapier@gentoo.org> (raw)
In-Reply-To: <20240111033747.17795-1-vapier@gentoo.org>

The ftime() function has been deprecated since POSIX-1-2004, and
removed in POSIX.1-2008.  It's also been deprecated/removed in glibc
since 2.33.  POSIX has always said the function is not portable, and
its return value, timezone, and dstflag fields are unspecified.  Even
if Linux/glibc & m32r had defined behavior, those aren't the host for
the sim runtime.

So let's stop using the function and switch to clock_gettime.  gnulib
already has detection support for it, and it's been around since at
least POSIX-1-2004.
---
 sim/m32r/traps.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index b779e0c3b9f5..c5191989d7fd 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -386,17 +386,20 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 	  case TARGET_LINUX_SYS_ftime:
 	    {
 	      struct timeb t;
+	      struct timespec ts;
 
-	      result = ftime (&t);
+	      result = clock_gettime (CLOCK_REALTIME, &ts);
 	      errcode = errno;
 
 	      if (result != 0)
 		break;
 
-	      t.time = H2T_4 (t.time);
-	      t.millitm = H2T_2 (t.millitm);
-	      t.timezone = H2T_2 (t.timezone);
-	      t.dstflag = H2T_2 (t.dstflag);
+	      t.time = H2T_4 (ts.tv_sec);
+	      t.millitm = H2T_2 (ts.tv_nsec / 1000000);
+	      /* POSIX.1-2001 says the contents of the timezone and dstflag
+		 members of tp after a call to ftime() are unspecified.  */
+	      t.timezone = H2T_2 (0);
+	      t.dstflag = H2T_2 (0);
 	      if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t))
 		  != sizeof(t))
 		{
-- 
2.43.0


  reply	other threads:[~2024-01-11  3:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11  3:37 [PATCH/committed 1/5] sim: m32r: cleanup unused variables Mike Frysinger
2024-01-11  3:37 ` Mike Frysinger [this message]
2024-01-11  3:37 ` [PATCH/committed 3/5] sim: m32r: fix missing break statement Mike Frysinger
2024-01-11  3:37 ` [PATCH/committed 4/5] sim: m32r: fixup some of the int<->pointer casts Mike Frysinger
2024-01-11  3:37 ` [PATCH/committed 5/5] sim: m32r: enable warnings in traps.c Mike Frysinger

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=20240111033747.17795-2-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).