Import <sys/time.h> for some of its macros Fixes: https://bugs.freedesktop.org/94320
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
diff --git a/COPYING b/COPYING
index 5b1e8c3..9ffc6b4 100644
--- a/COPYING
+++ b/COPYING
@@ -90,6 +90,7 @@ Files:
include/bsd/netinet/ip_icmp.h
include/bsd/sys/bitstring.h
include/bsd/sys/queue.h
+ include/bsd/sys/time.h
include/bsd/timeconv.h
include/bsd/vis.h
man/bitstring.3bsd
@@ -209,6 +210,37 @@ License: BSD-3-clause-Peter-Wemm
SUCH DAMAGE.
Files:
+ man/timeradd.3bsd
+Copyright:
+ Copyright © 2009 Jukka Ruohonen <jruohonen@iki.fi>
+ Copyright © 1999 Kelly Yancey <kbyanc@posi.net>
+ All rights reserved.
+License: BSD-3-clause-John-Birrell
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the author nor the names of any co-contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+Files:
man/setproctitle.3bsd
Copyright:
Copyright © 1995 Peter Wemm <peter@FreeBSD.org>
@@ -235,11 +267,12 @@ Files:
man/fmtcheck.3bsd
man/humanize_number.3bsd
man/stringlist.3bsd
+ man/timeval.3bsd
src/fmtcheck.c
src/humanize_number.c
src/stringlist.c
Copyright:
- Copyright © 1994, 1997-2000, 2002, 2008 The NetBSD Foundation, Inc.
+ Copyright © 1994, 1997-2000, 2002, 2008, 2010 The NetBSD Foundation, Inc.
All rights reserved.
.
Some code was contributed to The NetBSD Foundation by Allen Briggs.
@@ -256,6 +289,9 @@ Copyright:
.
Some code is derived from software contributed to The NetBSD Foundation
by Christos Zoulas.
+ .
+ Some code is derived from software contributed to The NetBSD Foundation
+ by Jukka Ruohonen.
License: BSD-2-clause-NetBSD
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
diff --git a/include/Makefile.am b/include/Makefile.am
index b8140d9..6c74b44 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,6 +6,7 @@ nobase_include_HEADERS = \
bsd/sys/endian.h \
bsd/sys/poll.h \
bsd/sys/queue.h \
+ bsd/sys/time.h \
bsd/sys/tree.h \
bsd/netinet/ip_icmp.h \
bsd/bitstring.h \
diff --git a/include/bsd/sys/time.h b/include/bsd/sys/time.h
new file mode 100644
index 0000000..0aaf0e2
--- /dev/null
+++ b/include/bsd/sys/time.h
@@ -0,0 +1,138 @@
+/* $OpenBSD: time.h,v 1.36 2016/09/12 19:41:20 guenther Exp $ */
+/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)time.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifdef LIBBSD_OVERLAY
+#include_next <sys/time.h>
+#else
+#include <sys/time.h>
+#endif
+
+#ifndef LIBBSD_SYS_TIME_H
+#define LIBBSD_SYS_TIME_H
+
+#ifndef TIMEVAL_TO_TIMESPEC
+#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
+ (ts)->tv_sec = (tv)->tv_sec; \
+ (ts)->tv_nsec = (tv)->tv_usec * 1000; \
+}
+#endif
+
+#ifndef TIMESPEC_TO_TIMEVAL
+#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
+ (tv)->tv_sec = (ts)->tv_sec; \
+ (tv)->tv_usec = (ts)->tv_nsec / 1000; \
+}
+#endif
+
+/* Operations on timevals. */
+#ifndef timerclear
+#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
+#endif
+
+#ifndef timerisset
+#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
+#endif
+
+#ifndef timercmp
+#define timercmp(tvp, uvp, cmp) \
+ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
+ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
+ ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#endif
+
+#ifndef timeradd
+#define timeradd(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
+ if ((vvp)->tv_usec >= 1000000) { \
+ (vvp)->tv_sec++; \
+ (vvp)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+#endif
+
+#ifndef timersub
+#define timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (0)
+#endif
+
+/* Operations on timespecs. */
+#ifndef timespecclear
+#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
+#endif
+
+#ifndef timespecisset
+#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
+#endif
+
+#ifndef timespeccmp
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#endif
+
+#ifndef timespecadd
+#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)
+#endif
+
+#ifndef timespecsub
+#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
+
+#endif
diff --git a/man/Makefile.am b/man/Makefile.am
index 92da18d..fe0c335 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -132,6 +132,8 @@ dist_man_MANS = \
TAILQ_PREV.3bsd \
TAILQ_REMOVE.3bsd \
TAILQ_SWAP.3bsd \
+ TIMESPEC_TO_TIMEVAL.3bsd \
+ TIMEVAL_TO_TIMESPEC.3bsd \
arc4random.3bsd \
arc4random_addrandom.3bsd \
arc4random_buf.3bsd \
@@ -213,6 +215,17 @@ dist_man_MANS = \
strunvis.3bsd \
strvis.3bsd \
strvisx.3bsd \
+ timeradd.3bsd \
+ timerclear.3bsd \
+ timercmp.3bsd \
+ timerisset.3bsd \
+ timersub.3bsd \
+ timespecadd.3bsd \
+ timespecclear.3bsd \
+ timespeccmp.3bsd \
+ timespecisset.3bsd \
+ timespecsub.3bsd \
+ timeval.3bsd \
tree.3bsd \
unvis.3bsd \
vis.3bsd \
diff --git a/man/TIMESPEC_TO_TIMEVAL.3bsd b/man/TIMESPEC_TO_TIMEVAL.3bsd
new file mode 100644
index 0000000..e47176e
--- /dev/null
+++ b/man/TIMESPEC_TO_TIMEVAL.3bsd
@@ -0,0 +1 @@
+.so man3/timeval.3bsd
diff --git a/man/TIMEVAL_TO_TIMESPEC.3bsd b/man/TIMEVAL_TO_TIMESPEC.3bsd
new file mode 100644
index 0000000..e47176e
--- /dev/null
+++ b/man/TIMEVAL_TO_TIMESPEC.3bsd
@@ -0,0 +1 @@
+.so man3/timeval.3bsd
diff --git a/man/libbsd.7 b/man/libbsd.7
index 216bc01..19af0aa 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -108,6 +108,7 @@ be prefixed with
.It In sys/endian.h
.It In sys/poll.h
.It In sys/queue.h
+.It In sys/time.h
.It In sys/tree.h
.It In timeconv.h
.It In unistd.h
@@ -191,6 +192,8 @@ might disappear on the next SONAME bump.
.Xr strmode 3bsd ,
.Xr strnstr 3bsd ,
.Xr strtonum 3bsd ,
+.Xr timeradd 3bsd ,
+.Xr timeval 3bsd ,
.Xr tree 3bsd ,
.Xr unvis 3bsd ,
.Xr vis 3bsd ,
diff --git a/man/timeradd.3bsd b/man/timeradd.3bsd
new file mode 100644
index 0000000..df821de
--- /dev/null
+++ b/man/timeradd.3bsd
@@ -0,0 +1,159 @@
+.\" $NetBSD: timeradd.3,v 1.8 2010/06/07 18:40:16 jruoho Exp $
+.\"
+.\" Copyright (c) 2009 Jukka Ruohonen <jruohonen@iki.fi>
+.\" Copyright (c) 1999 Kelly Yancey <kbyanc@posi.net>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the author nor the names of any co-contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
+.\"
+.Dd June 7, 2010
+.Dt TIMERADD 3
+.Os
+.Sh NAME
+.Nm timeradd ,
+.Nm timersub ,
+.Nm timerclear ,
+.Nm timerisset ,
+.Nm timercmp ,
+.Nm timespecadd ,
+.Nm timespecsub ,
+.Nm timespecclear ,
+.Nm timespecisset ,
+.Nm timespeccmp
+.Nd operations on time structure
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/time.h
+(See
+.Xr libbsd 7
+for include usage.)
+.Ft void
+.Fn timeradd "struct timeval *a" "struct timeval *b" "struct timeval *res"
+.Ft void
+.Fn timersub "struct timeval *a" "struct timeval *b" "struct timeval *res"
+.Ft void
+.Fn timerclear "struct timeval *tv"
+.Ft int
+.Fn timerisset "struct timeval *tv"
+.Ft int
+.Fn timercmp "struct timeval *a" "struct timeval *b" CMP
+.Ft void
+.Fn timespecadd "struct timespec *a" \
+"struct timespec *b" "struct timespec *res"
+.Ft void
+.Fn timespecsub "struct timespec *a" \
+"struct timespec *b" "struct timespec *res"
+.Ft void
+.Fn timespecclear "struct timespec *ts"
+.Ft int
+.Fn timespecisset "struct timespec *ts"
+.Ft int
+.Fn timespeccmp "struct timespec *a" "struct timespec b" CMP
+.Sh DESCRIPTION
+These macros are provided for manipulating the
+.Fa timeval
+and
+.Fa timespec
+structures described in
+.Xr timeval 3 .
+.Pp
+The
+.Fn timeradd
+and
+.Fn timespecadd
+macros add the time information stored in
+.Fa a
+to
+.Fa b ,
+storing the result in
+.Fa res .
+With
+.Fn timeradd
+the results are simplified such that the value of
+.Fa res->tv_usec
+is always less than 1,000,000 (1 second).
+With
+.Fn timespecadd
+the
+.Fa res->tv_nsec
+member of
+.Fa struct timespec
+is always less than 1,000,000,000.
+.Pp
+The
+.Fn timersub
+and
+.Fn timespecsub
+macros subtract the time information stored in
+.Fa b
+from
+.Fa a
+and store the resulting structure
+in
+.Fa res .
+.Pp
+The
+.Fn timerclear
+and
+.Fn timespecclear
+macros initialize the structures
+to midnight (0 hour) January 1st, 1970 (the Epoch).
+In other words, they set the members of the structure to zero.
+.Pp
+The
+.Fn timerisset
+and
+.Fn timespecisset
+macros return true if the input structure
+is set to any time value other than the Epoch.
+.Pp
+The
+.Fn timercmp
+and
+.Fn timespeccmp
+macros compare
+.Fa a
+to
+.Fa b
+using the comparison operator given in
+.Fa CMP .
+The result of the comparison is returned.
+.Sh SEE ALSO
+.Xr timeval 3
+.Sh HISTORY
+The
+.Fn timeradd
+family of macros first appeared in
+.Nx 1.1 .
+These were later ported to
+.Fx 2.2.6 .
+The
+.Fn timespec
+family of macros first appeared in
+.Nx 1.2 .
diff --git a/man/timerclear.3bsd b/man/timerclear.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timerclear.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timercmp.3bsd b/man/timercmp.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timercmp.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timerisset.3bsd b/man/timerisset.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timerisset.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timersub.3bsd b/man/timersub.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timersub.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecadd.3bsd b/man/timespecadd.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecadd.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecclear.3bsd b/man/timespecclear.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecclear.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespeccmp.3bsd b/man/timespeccmp.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespeccmp.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecisset.3bsd b/man/timespecisset.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecisset.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timespecsub.3bsd b/man/timespecsub.3bsd
new file mode 100644
index 0000000..9ac4e5c
--- /dev/null
+++ b/man/timespecsub.3bsd
@@ -0,0 +1 @@
+.so man3/timeradd.3bsd
diff --git a/man/timeval.3bsd b/man/timeval.3bsd
new file mode 100644
index 0000000..8f0e3aa
--- /dev/null
+++ b/man/timeval.3bsd
@@ -0,0 +1,133 @@
+.\" $NetBSD: timeval.3,v 1.12 2011/04/12 08:39:26 jruoho Exp $
+.\"
+.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Jukka Ruohonen.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 12, 2011
+.Dt TIMEVAL 3
+.Os
+.Sh NAME
+.Nm timeval ,
+.Nm timespec
+.Nd time structures
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.Lb libbsd
+.Sh SYNOPSIS
+.In sys/time.h
+(See
+.Xr libbsd 7
+for include usage.)
+.Ft void
+.Fn TIMEVAL_TO_TIMESPEC "struct timeval *tv" "struct timespec *ts"
+.Ft void
+.Fn TIMESPEC_TO_TIMEVAL "struct timeval *tv" "struct timespec *ts"
+.Sh DESCRIPTION
+The
+.In sys/time.h
+header, included by
+.In time.h ,
+defines various structures related to time and timers.
+.Bl -enum -offset 1n
+.It
+The following structure is used by
+.Xr gettimeofday 2 ,
+among others:
+.Bd -literal -offset indent
+struct timeval {
+ time_t tv_sec;
+ suseconds_t tv_usec;
+};
+.Ed
+.Pp
+The
+.Va tv_sec
+member represents the elapsed time, in whole seconds.
+The
+.Va tv_usec
+member captures rest of the elapsed time,
+represented as the number of microseconds.
+.It
+The following structure is used by
+.Xr nanosleep 2 ,
+among others:
+.Bd -literal -offset indent
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+.Ed
+.Pp
+The
+.Va tv_sec
+member is again the elapsed time in whole seconds.
+The
+.Va tv_nsec
+member represents the rest of the elapsed time in nanoseconds.
+.Pp
+A microsecond is equal to one millionth of a second,
+1000 nanoseconds, or 1/1000 milliseconds.
+To ease the conversions, the macros
+.Fn TIMEVAL_TO_TIMESPEC
+and
+.Fn TIMESPEC_TO_TIMEVAL
+can be used to convert between
+.Em struct timeval
+and
+.Em struct timespec .
+.El
+.Sh EXAMPLES
+It can be stressed that the traditional
+.Tn UNIX
+.Va timeval
+and
+.Va timespec
+structures represent elapsed time, measured by the system clock.
+The following sketch implements a function suitable
+for use in a context where the
+.Va timespec
+structure is required for a conditional timeout:
+.Bd -literal -offset indent
+static void
+example(struct timespec *spec, time_t minutes)
+{
+ struct timeval elapsed;
+
+ (void)gettimeofday(&elapsed, NULL);
+
+ _DIAGASSERT(spec != NULL);
+ TIMEVAL_TO_TIMESPEC(&elapsed, spec);
+
+ /* Add the offset for timeout in minutes. */
+ spec->tv_sec = spec->tv_sec + minutes * 60;
+}
+.Ed
+.Pp
+A better alternative would use the more precise
+.Xr clock_gettime 2 .
+.Sh SEE ALSO
+.Xr timeradd 3