public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: newlib@sourceware.org
Subject: [PATCH 3/4] Synchronize <sys/time.h> with FreeBSD
Date: Tue, 24 Sep 2019 07:01:00 -0000	[thread overview]
Message-ID: <20190924070054.24447-4-sebastian.huber@embedded-brains.de> (raw)
In-Reply-To: <20190924070054.24447-1-sebastian.huber@embedded-brains.de>

This change is based on the FreeBSD commit:

Author: asomers <asomers@FreeBSD.org>
Date:   Mon Jul 30 15:46:40 2018 +0000

    Make timespecadd(3) and friends public

    The timespecadd(3) family of macros were imported from NetBSD back in
    r35029. However, they were initially guarded by #ifdef _KERNEL. In the
    meantime, we have grown at least 28 syscalls that use timespecs in some
    way, leading many programs both inside and outside of the base system to
    redefine those macros. It's better just to make the definitions public.

    Our kernel currently defines two-argument versions of timespecadd and
    timespecsub.  NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
    three-argument versions.  Solaris also defines a three-argument version, but
    only in its kernel.  This revision changes our definition to match the
    common three-argument version.

    Bump _FreeBSD_version due to the breaking KPI change.

    Discussed with: cem, jilles, ian, bde
    Differential Revision:  https://reviews.freebsd.org/D14725
---
 newlib/libc/include/sys/time.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/newlib/libc/include/sys/time.h b/newlib/libc/include/sys/time.h
index 103f56660..370c13406 100644
--- a/newlib/libc/include/sys/time.h
+++ b/newlib/libc/include/sys/time.h
@@ -340,6 +340,33 @@ tvtosbt(struct timeval _tv)
 
 	return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec));
 }
+
+/* Operations on timespecs */
+#define	timespecclear(tvp)	((tvp)->tv_sec = (tvp)->tv_nsec = 0)
+#define	timespecisset(tvp)	((tvp)->tv_sec || (tvp)->tv_nsec)
+#define	timespeccmp(tvp, uvp, cmp)					\
+	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
+	    ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :			\
+	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
+
+#define	timespecadd(tsp, usp, vsp)					\
+	do {								\
+		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;		\
+		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;	\
+		if ((vsp)->tv_nsec >= 1000000000L) {			\
+			(vsp)->tv_sec++;				\
+			(vsp)->tv_nsec -= 1000000000L;			\
+		}							\
+	} while (0)
+#define	timespecsub(tsp, usp, vsp)					\
+	do {								\
+		(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;		\
+		(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;	\
+		if ((vsp)->tv_nsec < 0) {				\
+			(vsp)->tv_sec--;				\
+			(vsp)->tv_nsec += 1000000000L;			\
+		}							\
+	} while (0)
 #endif /* __BSD_VISIBLE */
 
 /*
-- 
2.16.4

  parent reply	other threads:[~2019-09-24  7:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24  7:01 [PATCH 0/4] Synchronize <sys/time.h>, etc. " Sebastian Huber
2019-09-24  7:01 ` [PATCH 2/4] Synchronize <sys/_timespec.h> " Sebastian Huber
2019-09-24  7:01 ` Sebastian Huber [this message]
2019-09-24  7:01 ` [PATCH 1/4] Fix sbttons for values > 2s Sebastian Huber
2019-09-24  7:01 ` [PATCH 4/4] Move timeval macros to <sys/time.h> Sebastian Huber
2019-10-14  6:57 ` [PATCH 0/4] Synchronize <sys/time.h>, etc. with FreeBSD Sebastian Huber
2019-10-31  7:05   ` Sebastian Huber
2019-11-02 15:26 ` Corinna Vinschen

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=20190924070054.24447-4-sebastian.huber@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --cc=newlib@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).