explain_settimeofday(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– 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 original tv, exactly as passed to the settimeofday(2) system call. Exactly. No edits. Don't touch it.
  • tz β€” the original tz, exactly as passed to the settimeofday(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 the errno global 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 of errno. So capture it early, okay? πŸ™ˆ
  • tv β€” the original tv, exactly as passed to the settimeofday(2) system call.
  • tz β€” the original tz, exactly as passed to the settimeofday(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 original tv, exactly as passed to the settimeofday(2) system call.
  • tz β€” the original tz, exactly as passed to the settimeofday(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 the errno global 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 of errno. Save it first, bestie, seriously 🫢
  • tv β€” the original tv, exactly as passed to the settimeofday(2) system call.
  • tz β€” the original tz, exactly as passed to the settimeofday(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 πŸ‘€


  • libexplain version 1.4
  • Copyright (C) 2013 Peter 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