GETTIMEOFDAY(3POSIX)

πŸ•°οΈ GETTIMEOFDAY(3POSIX) β€” ok bestie, it's a POSIX Programmer's Manual page πŸ’–


🌸 PROLOG (read this first, it's giving ✨fine print✨)

Okay so real talk before we get into it: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β€” so if you're on Linux, lowkey go consult the corresponding Linux manual page for the actual tea on Linux behavior β€” or, plot twist, the interface may not even be implemented on Linux at all. πŸ’€


πŸ‘‘ NAME

gettimeofday β€” get the date and time, periodt.


πŸŽ€ SYNOPSIS

#include <sys/time.h>

int gettimeofday(struct timeval *restrict tp, void *restrict tzp);

Not me showing you the exact signature so you can't mess it up. Copy it character for character, bestie. 🫢


πŸ¦‹ DESCRIPTION

So the gettimeofday() function shall obtain the current time β€” expressed as seconds and microseconds since the Epoch β€” and store it in the timeval structure pointed to by tp. ✨

The resolution of the system clock is unspecified. Yeah. Unspecified. It's giving mystery, it's giving "don't ask", it's giving we're not telling you the precision. πŸ™ˆ

And if tzp is not a null pointer? The behavior is unspecified. Not undefined, not defined, just… unspecified. Nobody knows. Nobody's checking. Keep it NULL and keep it moving. πŸ’…


⭐ RETURN VALUE

gettimeofday() shall return 0, and β€” listen carefully β€” no value shall be reserved to indicate an error. Zero. That's it. That's the whole story. There's no secret error code hiding in the return value, so don't go looking for one. πŸ”₯


πŸ’€ ERRORS

No errors are defined.

That's the whole section. Iconic, honestly. Nothing to report.

Heads up though: the following sections are informative. Not normative. Informative. So they're the vibes, not the rules. 🧚

πŸ“ EXAMPLES

None. Literally none. We're moving on. 😭


🌈 APPLICATION USAGE

Real talk: applications should use the clock_gettime() function instead of the gettimeofday() function β€” because gettimeofday() is obsolescent. That's the technical term for "it's on its way out, bestie, don't get attached." πŸ₯€


πŸ’œ RATIONALE

None. Nothing. The rationale is a void. We respect the void. ✨


⚠️ FUTURE DIRECTIONS

The gettimeofday() function may be removed in a future version.

Not a drill. This is the actual warning. If you're building something new on top of it, just know you're building on a bridge that might get demolished. 🚧


πŸ”— SEE ALSO

  • clock_getres()
  • ctime()

Also, from the Base Definitions volume of POSIX.1‐2017: <sys_time.h> β€” note that underscore, iykyk, it's not the header you think it is. πŸ‘‘


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (Translation: if this page and the official standard disagree, the official standard wins, no cap. πŸ‘‘)

The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay that's the whole page bestie, thanks for reading my little lecture about a function you should probably stop using πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

Signing off with love β€” this page came from the good people at IEEE/The Open Group, dated 2017, filed under GETTIMEOFDAY(3POSIX). Go forth and call clock_gettime() instead. periodt. πŸ’