explain_sleep(3)

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

πŸ’€ explain_sleep(3) β€” Library Functions Manual πŸ’€

okay bestie, sit DOWN, because this is the explain_sleep(3) page from the Library Functions Manual, and it's literally the glow-up your error messages have been waiting for 🫢


✨ NAME ✨

explain_sleep β€” explain sleep(3) errors. that's it, that's the job, and she does it flawlessly πŸ’…


✨ SYNOPSIS ✨

#include <libexplain/sleep.h>
const char *explain_sleep(unsigned int seconds);
const char *explain_errno_sleep(int errnum, unsigned int seconds);
void explain_message_sleep(char *message, int message_size, unsigned int
seconds);
void explain_message_errno_sleep(char *message, int message_size, int
errnum, unsigned int seconds);

four functions, one mission: telling you why your sleep(3) call said no 😭


✨ DESCRIPTION ✨

so these functions β€” all of them β€” exist to hand you explanations for errors that come back from the sleep(3) system call. like, the actual tea, not just a vibe. πŸ“


🌸 explain_sleep 🌸

const char *explain_sleep(unsigned int seconds);

the explain_sleep function gets you an explanation of an error returned by the sleep(3) system call. the least the message will contain is the value of strerror(errno) β€” but usually it does much better and tells you the underlying cause in more detail. it's giving overachiever, and we love that for her ✨

the errno global variable is what gets used to obtain the error value to be decoded.

  • seconds β€” the original seconds, exactly as passed to the sleep(3) system call. no edits, no remix, the original πŸŽ€

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

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. no cap, that's a real caveat.

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

unsigned int result = sleep(seconds);
if (result < 0)
{
    fprintf(stderr, "%s\n", explain_sleep(seconds));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_sleep_or_die(3) function. slay, no assembly required πŸ’–


🌸 explain_errno_sleep 🌸

const char *explain_errno_sleep(int errnum, unsigned int seconds);

the explain_errno_sleep function gets you an explanation of an error returned by the sleep(3) 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. iconic behaviour, truly ✨

  • 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. so like, grab it early or it's gone, iykyk πŸ’€
  • seconds β€” the original seconds, exactly as passed to the sleep(3) 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. yes, again. it's a whole thing πŸ™ˆ

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.

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

unsigned int result = sleep(seconds);
if (result < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_sleep(err, seconds));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_sleep_or_die(3) function. πŸŽ€


🌸 explain_message_sleep 🌸

void explain_message_sleep(char *message, int message_size, unsigned int
seconds);

the explain_message_sleep function gets you an explanation of an error returned by the sleep(3) 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. main character energy fr fr πŸ‘‘

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, being all responsible πŸ¦‹
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • seconds β€” the original seconds, exactly as passed to the sleep(3) system call.

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

unsigned int result = sleep(seconds);
if (result < 0)
{
    char message[3000];
    explain_message_sleep(message, sizeof(message), seconds);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_sleep_or_die(3) function. πŸ’œ


🌸 explain_message_errno_sleep 🌸

void explain_message_errno_sleep(char *message, int message_size, int
errnum, unsigned int seconds);

the explain_message_errno_sleep function gets you an explanation of an error returned by the sleep(3) 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. she ate and left no crumbs 🍽️✨

  • 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. protect your errno, bestie 🫢
  • seconds β€” the original seconds, exactly as passed to the sleep(3) system call.

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

unsigned int result = sleep(seconds);
if (result < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_sleep(message, sizeof(message), err,
    seconds);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_sleep_or_die(3) function. 🌈


✨ SEE ALSO ✨

  • sleep(3) β€” Sleep for the specified number of seconds. the original, the blueprint, the moment πŸ’€
  • explain_sleep_or_die(3) β€” Sleep for the specified number of seconds and report errors. same energy, but she handles the dying for you πŸ’€βœ¨

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

and that's the whole page, bestie!! go forth and let your error messages be ✨legible✨. this has been explain_sleep(3) from the Library Functions Manual, libexplain version 1.4, Copyright (C) 2013 Peter Miller β€” periodt πŸ’…πŸŽ€

πŸ“¦ where this page comes from