public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Synchronize <sys/time.h> with FreeBSD
@ 2019-11-04 6:05 Sebastian Huber
0 siblings, 0 replies; only message in thread
From: Sebastian Huber @ 2019-11-04 6:05 UTC (permalink / raw)
To: newlib-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=aae831b083ab762726bfb2c07584a481e6925b81
commit aae831b083ab762726bfb2c07584a481e6925b81
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date: Mon Sep 23 12:02:11 2019 +0200
Synchronize <sys/time.h> with FreeBSD
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
Diff:
---
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 103f566..370c134 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 */
/*
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-11-04 6:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 6:05 [newlib-cygwin] Synchronize <sys/time.h> with FreeBSD Sebastian Huber
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).