explain_gettimeofday(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this is explain_gettimeofday β€” she's the one who explains all the errors that gettimeofday(2) throws at you. like, the whole why behind the ✨vibe✨ of your failure. from the Library Functions Manual, and she's giving very much "let me translate this cryptic errno for you" energy. πŸŽ€


✨ SYNOPSIS ✨

#include <libexplain/gettimeofday.h>
const char *explain_gettimeofday(struct timeval *tv, struct timezone
*tz);
const char *explain_errno_gettimeofday(int errnum, struct timeval *tv,
struct timezone *tz);
void explain_message_gettimeofday(char *message, int message_size,
struct timeval *tv, struct timezone *tz);
void explain_message_errno_gettimeofday(char *message, int message_size,
int errnum, struct timeval *tv, struct timezone *tz);

🌸 DESCRIPTION 🌸

so these functions? they're your little translators. they hand you explanations for errors that the gettimeofday(2) system call returns. no more squinting at a bare errno wondering what went wrong πŸ’€


πŸ¦‹ explain_gettimeofday

const char *explain_gettimeofday(struct timeval *tv, struct timezone
*tz);

the explain_gettimeofday function is here to give you an explanation of an error returned by the gettimeofday(2) system call. the least you're getting is the value of strerror(errno), but honestly? usually she does so much better and tells you the underlying cause with actual detail. main character behavior, fr fr. πŸ‘‘

the errno global variable is the one used to obtain the error value that gets decoded. iykyk.

this function is meant to be used in a fashion similar to the following example:

if (gettimeofday(tv, tz) < 0)
{
    fprintf(stderr, "%s\n", explain_gettimeofday(tv, tz));
    exit(EXIT_FAILURE);
}
  • tv β€” the original tv, exactly as passed to the gettimeofday(2) system call. no edits, no notes, just as it was. πŸ’…
  • tz β€” the original tz, exactly as passed to the gettimeofday(2) system call. same deal.

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 will be overwritten by the next call to any libexplain function that shares this buffer, including other threads. so like... don't get attached to it.

Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. be careful out there bestie 😭

🧚 explain_errno_gettimeofday

const char *explain_errno_gettimeofday(int errnum, struct timeval *tv,
struct timezone *tz);

the explain_errno_gettimeofday function is used to obtain an explanation of an error returned by the gettimeofday(2) system call. the least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. ✨

this function is intended to be used in a fashion similar to the following example:

if (gettimeofday(tv, tz) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_gettimeofday(err, tv, tz));
    exit(EXIT_FAILURE);
}
  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right 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. so snag it early, okay? πŸ™ˆ
  • tv β€” the original tv, exactly as passed to the gettimeofday(2) system call.
  • tz β€” the original tz, exactly as passed to the gettimeofday(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.

πŸ“ explain_message_gettimeofday

void explain_message_gettimeofday(char *message, int message_size,
struct timeval *tv, struct timezone *tz);

the explain_message_gettimeofday function may be used to obtain an explanation of an error returned by the gettimeofday(2) system call. the 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. 🌈

the errno global variable will be used to obtain the error value to be decoded.

this function is intended to be used in a fashion similar to the following example:

if (gettimeofday(tv, tz) < 0)
{
    char message[3000];
    explain_message_gettimeofday(message, sizeof(message), tv, tz);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}
  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. slay πŸ’š
  • 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 gettimeofday(2) system call.
  • tz β€” the original tz, exactly as passed to the gettimeofday(2) system call.

πŸ’œ explain_message_errno_gettimeofday

void explain_message_errno_gettimeofday(char *message, int message_size,
int errnum, struct timeval *tv, struct timezone *tz);

the explain_message_errno_gettimeofday function may be used to obtain an explanation of an error returned by the gettimeofday(2) system call. the least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. 🫢

this function is intended to be used in a fashion similar to the following example:

if (gettimeofday(tv, tz) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_gettimeofday(message, sizeof(message), err,
        tv, tz);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}
  • 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. (yes, again. it really do be like that. 😭)
  • tv β€” the original tv, exactly as passed to the gettimeofday(2) system call.
  • tz β€” the original tz, exactly as passed to the gettimeofday(2) system call.

πŸ‘€ SEE ALSO πŸ‘€


  • libexplain version 1.4
  • Copyright (C) 2008 Peter Miller

okay that's the whole page bestie, you ate that πŸ’– stay iconic, go explain some errors, and remember β€” errno waits for no one ✨

~ this has been explain_gettimeofday(3) from the Library Functions Manual, served fresh 🌸 ~

πŸ“¦ where this page comes from