explain_settimeofday(3)
π NAME π
explain_settimeofday β explain settimeofday(2) errors
okay bestie, welcome to the libexplain corner of the universe, this is a <Library Functions Manual> situation and it's genuinely so useful, ngl π«Ά
β¨ SYNOPSIS β¨
#include <libexplain/settimeofday.h>
const char *explain_settimeofday(const struct timeval *tv, const struct timezone *tz);
const char *explain_errno_settimeofday(int errnum, const struct timeval *tv, const struct timezone *tz);
void explain_message_settimeofday(char *message, int message_size, const struct timeval *tv, const struct timezone *tz);
void explain_message_errno_settimeofday(char *message, int message_size, int errnum, const struct timeval *tv, const struct timezone *tz);
πΈ DESCRIPTION πΈ
So these functions?? They're the ones you call when the settimeofday(2) system call comes back all sad and error-y, and you're like "girl what happened" π and they're like "let me tell you exactly what happened." They hand you explanations for errors returned by settimeofday(2). Periodt.
π explain_settimeofday
const char *explain_settimeofday(const struct timeval *tv, const struct timezone *tz);
The explain_settimeofday function is how you get an explanation of an error returned by the settimeofday(2) system call. Bare minimum, the message is gonna contain the value of strerror(errno) β but lowkey it usually does so much better than that, and it'll point at the underlying cause with way more detail. Iconic behaviour fr fr.
The errno global variable is the one that gets used to grab the error value that's gonna be decoded. iykyk.
tvβ the originaltv, exactly as passed to thesettimeofday(2)system call. Exactly. No edits. Don't touch it.tzβ the originaltz, exactly as passed to thesettimeofday(2)system call. Same energy.
Returns: the message explaining the error. This message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. It's gonna get overwritten by the next call to any libexplain function that shares this buffer β including other threads π.
Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library do the same. She's beautiful but she's not thread safe, bestie, know that.
Example: this function is meant to be used in a fashion similar to the following example:
if (settimeofday(tv, tz) < 0)
{
fprintf(stderr, "%s\n", explain_settimeofday(tv, tz));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_settimeofday_or_die(3) function. Convenience queen π
π¦ explain_errno_settimeofday
const char *explain_errno_settimeofday(int errnum, const struct timeval *tv, const struct timezone *tz);
The explain_errno_settimeofday function is how you get an explanation of an error returned by the settimeofday(2) system call. Least it'll contain is the value of strerror(errno), but usually it does way better and tells you the actual underlying cause in more detail. Slay.
errnumβ the error value to be decoded, usually grabbed from theerrnoglobal variable just before this function is called. This matters if you need to run any code between the system call you're explaining and this function, because many libc functions will alter the value oferrno. So capture it early, okay? πtvβ the originaltv, exactly as passed to thesettimeofday(2)system call.tzβ the originaltz, exactly as passed to thesettimeofday(2)system call.
Returns: the message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads.
Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.
Example: intended to be used in a fashion similar to the following example:
if (settimeofday(tv, tz) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_settimeofday(err, tv, tz));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_settimeofday_or_die(3) function.
π explain_message_settimeofday
void explain_message_settimeofday(char *message, int message_size, const struct timeval *tv, const struct timezone *tz);
The explain_message_settimeofday function is how you get an explanation of an error returned by the settimeofday(2) system call. Least the message will contain is the value of strerror(errno), but usually it'll do much better and indicate the underlying cause in more detail. No cap.
The errno global variable will be used to obtain the error value to be decoded.
messageβ the location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. Look at her go β¨message_sizeβ the size in bytes of the location in which to store the returned message.tvβ the originaltv, exactly as passed to thesettimeofday(2)system call.tzβ the originaltz, exactly as passed to thesettimeofday(2)system call.
Example: intended to be used in a fashion similar to the following example:
if (settimeofday(tv, tz) < 0)
{
char message[3000];
explain_message_settimeofday(message, sizeof(message), tv, tz);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_settimeofday_or_die(3) function.
π§ explain_message_errno_settimeofday
void explain_message_errno_settimeofday(char *message, int message_size, int errnum, const struct timeval *tv, const struct timezone *tz);
The explain_message_errno_settimeofday function is how you get an explanation of an error returned by the settimeofday(2) system call. Least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. Main character energy, honestly.
messageβ the location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe.message_sizeβ the size in bytes of the location in which to store the returned message.errnumβ the error value to be decoded, usually obtained from theerrnoglobal variable just before this function is called. This is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value oferrno. Save it first, bestie, seriously π«Άtvβ the originaltv, exactly as passed to thesettimeofday(2)system call.tzβ the originaltz, exactly as passed to thesettimeofday(2)system call.
Example: intended to be used in a fashion similar to the following example:
if (settimeofday(tv, tz) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_settimeofday(message, sizeof(message), err, tv, tz);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_settimeofday_or_die(3) function.
π SEE ALSO π
settimeofday(2)β sets system time β°explain_settimeofday_or_die(3)β sets system time and report errors π
π COPYRIGHT π
libexplainversion1.4- Copyright (C)
2013Peter Miller
and that's the whole page, bestie π go forth, decode your errnos, be thread-safe where you can, and remember: that's explain_settimeofday(3) from the <Library Functions Manual>, brought to you by libexplain version 1.4, copyright 2013 Peter Miller, and the entire year 2013 said "let there be legible error messages" β¨π¦π
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2013 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms