public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] sim: m32r: migrate ftime() to clock_gettime()
@ 2024-01-11  3:37 Michael Frysinger
  0 siblings, 0 replies; only message in thread
From: Michael Frysinger @ 2024-01-11  3:37 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b1f974faeb5f1423639f387714699a2bde0c5610

commit b1f974faeb5f1423639f387714699a2bde0c5610
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Wed Jan 10 21:57:47 2024 -0500

    sim: m32r: migrate ftime() to clock_gettime()
    
    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.

Diff:
---
 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 b779e0c3b9f..c5191989d7f 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))
 		{

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-11  3:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11  3:37 [binutils-gdb] sim: m32r: migrate ftime() to clock_gettime() Michael Frysinger

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).