timeradd(3bsd)
π timeradd β ok bestie, let's talk time structures π
So likeβ¦ this is the timeradd(3bsd) page, from the BSD-flavoured corner of your system, and it's genuinely one of my faves because it's just ten little macros that do math on time and never once yells at you. πΈ
β¨ NAME β¨
timeradd, timersub, timerclear, timerisset, timercmp, timespecadd, timespecsub, timespecclear, timespecisset, timespeccmp β operations on time structure π
π LIBRARY π
Utility functions from BSD systems β that's libbsd, and you link it with -lbsd. π«Ά
π SYNOPSIS π
#include <sys/time.h>
(See libbsd(7) for include usage.)
void
timeradd(struct timeval *a, struct timeval *b, struct timeval *res);
void
timersub(struct timeval *a, struct timeval *b, struct timeval *res);
void
timerclear(struct timeval *tv);
int
timerisset(struct timeval *tv);
int
timercmp(struct timeval *a, struct timeval *b, CMP);
void
timespecadd(struct timespec *a, struct timespec *b,
struct timespec *res);
void
timespecsub(struct timespec *a, struct timespec *b,
struct timespec *res);
void
timespecclear(struct timespec *ts);
int
timespecisset(struct timespec *ts);
int
timespeccmp(struct timespec *a, struct timespec b, CMP);
lowkey important: the include line comes with a lil note attached β (See libbsd(7) for include usage.) β so go read that one too, bestie, it explains how the includes actually work here. π
π DESCRIPTION π
These are macros, not fancy functions, and they exist so you can mess with the timeval and timespec structures β the ones that get described over in timeval(3bsd). It's giving "tiny utility, enormous slay". β¨
timeradd()andtimespecadd()add the time info stored in a to b, and drop the result into res. Withtimeradd()the results get simplified so that the value ofres->tv_usecis always less than 1,000,000 (that's 1 second, for the people in the back). Withtimespecadd()theres->tv_nsecmember ofstruct timespecis always less than 1,000,000,000. Normalisation? Handled. You're welcome. πtimersub()andtimespecsub()go the other way β they subtract the time info stored in b from a, and store the resulting structure in res. Math but make it cute. π¦timerclear()andtimespecclear()initialize the structures to midnight (0 hour) January 1st, 1970 β aka the Epoch. In other words, they set the members of the structure to zero. Clean slate, fresh start, new me energy. πtimerisset()andtimespecisset()return true if the input structure is set to any time value other than the Epoch. So like, "is this thing actually set or is it just zero" β that's the whole vibe check. βtimercmp()andtimespeccmp()compare a to b using the comparison operator you hand them inCMP, and the result of the comparison gets returned. You bring the operator, they bring the answer. π€
also real talk: peep that last synopsis signature βtimespeccmp()takesstruct timespec b, not a pointer, while its friends take pointers. That's not a typo on my end, that's literally what's written. Copy it exactly, bestie. π
π SEE ALSO π
π°οΈ HISTORY π°οΈ
The timeradd() family of macros first appeared in NetBSD 1.1. These were later ported to FreeBSD 2.2.6. The timespec() family of macros first appeared in NetBSD 1.2. Iconic lineage fr fr. π
and that's the whole page!! this one's from Debian, dated June 7, 2010 β so yeah, a lil vintage, but she still eats. mwah, go normalise your timevals responsibly πβ¨π
π¦ where this page comes from
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian bookworm: libbsd-dev 0.11.7-2
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- nixpkgs unstable: libbsd 0.12.2
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 2009 Jukka Ruohonen <jruohonen@iki.fi>
- Copyright (c) 1999 Kelly Yancey <kbyanc@posi.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms