BINTIMEADD(9)

πŸ“¦ in nixpkgs unstable

πŸ’– BINTIMEADD(9) πŸ’–

okay bestie, so this is from the Kernel Developer's Manual β€” section 9, kernel land, big brain hours πŸ‘‘ β€” and it's literally all about poking at kernel time structures without losing your mind. stay with me, it's gonna slay πŸ’…


✨ NAME ✨

bintimecmp, bintimesub, bintimeadd, bintimeaddfrac, BINTIME_TO_TIMEVAL, BINTIME_TO_TIMESPEC, TIMEVAL_TO_BINTIME, TIMESPEC_TO_BINTIME β€” these are the little helpers that let you manipulate kernel time structures, bestie 🫢


🌸 SYNOPSIS 🌸

so first, you gotta bring in the header, no cap:

#include <sys/time.h>

and then here's the whole squad, exactly as they show up:

int
bintimecmp(struct bintime *a, struct bintime *b, operator);

void
bintimesub(const struct bintime *a, const struct bintime *b,
    struct bintime *c);

void
bintimeadd(const struct bintime *a, const struct bintime *b,
    struct bintime *c);

void
bintimeaddfrac(const struct bintime *a, uint64_t fraction,
    struct bintime *b);

void
BINTIME_TO_TIMEVAL(const struct bintime *bt, struct timeval *tv);

void
BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts);

void
TIMEVAL_TO_BINTIME(const struct timeval *tv, struct bintime *bt);

void
TIMESPEC_TO_BINTIME(const struct timespec *ts, struct bintime *bt);

πŸ¦‹ DESCRIPTION πŸ¦‹

bestie, the whole point of these functions is that they simplify the use of bintime structures and the conversion to and from other time representations. that's it, that's the vibe πŸ’«

The following functions are available β€” line them up, they're all iconic:

  • bintimecmp(a, b, operator) β€” test if the expression a operator b is true, where operator is one of <, <=, ==, !=, >=, or >. like a vibe check for time comparisons fr fr ⭐
  • bintimesub(a, b, c) β€” subtract b from a and store the result in c. bye subtraction anxiety, hello c πŸ’€
  • bintimeadd(a, b, c) β€” add b to a and store the result in c. math but make it cute πŸŽ€
  • bintimeaddfrac(a, fraction, b) β€” add fraction fractional seconds to a and store the result in b. and heads up, a fractional second is equal to 1 / (2^64) seconds β€” tiny tiny tiny, microscopic even πŸ”₯
  • BINTIME_TO_TIMEVAL(bt, tv) β€” convert bt to a struct timeval and store the result in tv. glow-up from one struct to another ✨
  • BINTIME_TO_TIMESPEC(bt, ts) β€” convert bt to a struct timespec and store the result in ts. same energy, different struct 🌈
  • TIMEVAL_TO_BINTIME(tv, bt) β€” convert tv to a struct bintime and store the result in bt. coming back the other way, main character energy πŸ‘‘
  • TIMESPEC_TO_BINTIME(ts, bt) β€” convert ts to a struct bintime and store the result in bt. round trip complete, we love to see it πŸ’œ

🌟 RETURN VALUES 🌟

bintimecmp() returns 1 if the tested condition holds or 0 otherwise. that's it. binary queen behavior, periodt πŸ’…


πŸ“ CODE REFERENCES πŸ“

These functions are implemented in the file sys/sys/time.h β€” that's the spot, go look, iykyk πŸ“–


🧚 SEE ALSO 🧚

okay so go read these too, they're literally right there:


🌸 HISTORY 🌸

Predecessors to these functions first appeared in FreeBSD 5.0 and were ported to OpenBSD 3.6. then they got modified to more closely resemble the timeradd(3) macros for OpenBSD 6.6. a whole origin story, honestly πŸ˜­πŸ’–


πŸ’« AUTHORS πŸ’«

Poul-Henning Kamp <phk@freebsd.org> β€” thank you king 🫢


lowkey remember: these are tiny helpers, so don't try to make them do something they don't do. the manpage says exactly what it says, and that's the whole tea 🍡

and that's a wrap bestie!! this page is from Debian, dated June 3, 2019, and you just read the whole thing β€” no skimming, i'm so proud of you πŸ˜­πŸŽ€πŸ’–

πŸ“¦ where this page comes from
  • nixpkgs unstable: cvs-export
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms