Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153848413
D41524.id126305.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D41524.id126305.diff
View Options
diff --git a/include/time.h b/include/time.h
--- a/include/time.h
+++ b/include/time.h
@@ -182,9 +182,13 @@
#if defined(__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2011 || \
(defined(__cplusplus) && __cplusplus >= 201703)
#include <sys/_timespec.h>
-/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */
+/* ISO/IEC 9899:2011 7.27.2.5 The timespec_get function */
#define TIME_UTC 1 /* time elapsed since epoch */
int timespec_get(struct timespec *ts, int base);
+#if defined (__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2023
+/* ISO/IEC 9899:2024 7.29.2.7 The timespec_getres function */
+int timespec_getres(struct timespec *, int);
+#endif
#endif
__END_DECLS
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -156,6 +156,7 @@
time.c \
times.c \
timespec_get.c \
+ timespec_getres.c \
timezone.c \
tls.c \
ttyname.c \
@@ -319,6 +320,7 @@
time.3 \
times.3 \
timespec_get.3 \
+ timespec_getres.3 \
timezone.3 \
ttyname.3 \
tzset.3 \
diff --git a/lib/libc/gen/timespec_get.3 b/lib/libc/gen/timespec_get.3
--- a/lib/libc/gen/timespec_get.3
+++ b/lib/libc/gen/timespec_get.3
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd August 10, 2018
+.Dd August 21, 2023
.Dt TIMESPEC_GET 3
.Os
.Sh NAME
@@ -66,7 +66,8 @@
.Sh SEE ALSO
.Xr clock_gettime 2 ,
.Xr gettimeofday 2 ,
-.Xr time 3
+.Xr time 3 ,
+.Xr timespec_getres 3
.Sh STANDARDS
The
.Nm
diff --git a/lib/libc/gen/timespec_getres.3 b/lib/libc/gen/timespec_getres.3
new file mode 100644
--- /dev/null
+++ b/lib/libc/gen/timespec_getres.3
@@ -0,0 +1,51 @@
+.\"-
+.\" Copyright (c) 2023 Dag-Erling Smørgrav
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd August 21, 2023
+.Dt TIMESPEC_GETRES 3
+.Os
+.Sh NAME
+.Nm timespec_getres
+.Nd get clock resolution
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In time.h
+.Ft int
+.Fn timespec_getres "struct timespec *ts" "int base"
+.Sh DESCRIPTION
+If
+.Fa ts
+is non-null and
+.Fa base
+refers to a supported time base as described in
+.Xr timespec_get 3 ,
+the
+.Nm
+function fills in the structure pointed to by
+.Fa ts
+to reflect the resolution of that time base.
+.Sh RETURN VALUES
+The
+.Nm
+function returns the value of
+.Fa base
+if successful and zero otherwise.
+.Sh SEE ALSO
+.Xr clock_getres 2 ,
+.Xr timespec_get 3
+.\" .Sh STANDARDS
+.\" The
+.\" .Nm
+.\" function conforms to
+.\" .St -isoC-2023 .
+.Sh HISTORY
+This interface first appeared in
+.Fx 14 .
+.Sh AUTHORS
+The
+.Nm
+function and this manual page were written by
+.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
diff --git a/lib/libc/gen/timespec_getres.c b/lib/libc/gen/timespec_getres.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/gen/timespec_getres.c
@@ -0,0 +1,16 @@
+/*-
+ * Copyright (c) 2023 Dag-Erling Smørgrav
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <time.h>
+
+int
+timespec_getres(struct timespec *ts, int base)
+{
+
+ if (base == TIME_UTC && clock_getres(CLOCK_REALTIME, ts) == 0)
+ return (base);
+ return (0);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 25, 5:57 AM (9 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32112275
Default Alt Text
D41524.id126305.diff (3 KB)
Attached To
Mode
D41524: libc: Add timespec_getres(3) as per C23.
Attached
Detach File
Event Timeline
Log In to Comment