timeradd(3)

โœจ timeradd โ€” the timeval glow-up page โœจ

okay bestie, welcome to timeradd(3), aka the Library Functions Manual entry for a whole lil squad of macros: timeradd, timersub, timercmp, timerclear, timerisset. they do operations on timeval. that's the whole vibe. ๐Ÿ’–


๐ŸŒธ NAME ๐ŸŒธ

timeradd, timersub, timercmp, timerclear, timerisset โ€” timeval operations ๐Ÿ’…


๐ŸŽ€ LIBRARY ๐ŸŽ€

Standard C library (libc, -lc)


โœจ SYNOPSIS โœจ

#include <sys/time.h>

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 *tvp);
int timerisset(struct timeval *tvp);

int timercmp(struct timeval *a, struct timeval *b, CMP);

๐Ÿงš Feature Test Macro Requirements for glibc ๐Ÿงš

(peep feature_test_macros(7) if you wanna go deeper, bestie)

  • All functions shown above:
    • Since glibc 2.19:
      • _DEFAULT_SOURCE
    • glibc 2.19 and earlier:
      • _BSD_SOURCE

๐Ÿ’– DESCRIPTION ๐Ÿ’–

so these macros are here to operate on timeval structures, and <sys/time.h> defines them like this:

struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* microseconds */
};

not me obsessing over how clean that is. anyway, one by one:

  • timeradd() โ€” adds the time values in a and b, and drops the sum into the timeval pointed to by res. the result gets normalized so that res->tv_usec lands in the range 0 to 999,999. no cap. โœจ
  • timersub() โ€” subtracts the time value in b from the time value in a, and puts the result in the timeval pointed to by res. also normalized so res->tv_usec is in the range 0 to 999,999. periodt. ๐Ÿซถ
  • timerclear() โ€” zeros out the timeval structure pointed to by tvp, so it represents the Epoch: 1970-01-01 00:00:00 +0000 (UTC). it's giving the beginning of time, literally. ๐Ÿ’€
  • timerisset() โ€” returns true (nonzero) if either field of the timeval structure pointed to by tvp contains a nonzero value. vibe check on your timer. ๐Ÿ‘‘
  • timercmp() โ€” compares the timer values in a and b using the comparison operator CMP, and returns true (nonzero) or false (0) depending on how that comparison went.
โš ๏ธ bestie listen. some systems (but not Linux/glibc) have a broken timercmp() implementation where CMP of >=, <=, and == just do not work. tragic. iconic fail. so portable applications can instead use: c !timercmp(..., <) !timercmp(..., >) !timercmp(..., !=)

๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

timerisset() and timercmp() return true (nonzero) or false (0). that's it, that's the tea. ๐Ÿ“


๐Ÿ’œ ERRORS ๐Ÿ’œ

No errors are defined. โœจ zero drama, zero errors, we love a low-maintenance function.


๐ŸŒŸ STANDARDS ๐ŸŒŸ

None. ๐Ÿ˜ญ it's just out here living its truth, unstandardized.


๐Ÿฆ‹ HISTORY ๐Ÿฆ‹

BSD. old money, honestly. ๐Ÿ‘‘


๐Ÿ’ซ SEE ALSO ๐Ÿ’ซ


and that's the whole page, bestie!! go forth and normalize your microseconds responsibly ๐Ÿ’…

signing off โ€” this was Linux man-pages 6.20, dated 2026-02-08, page timeradd(3) ๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms