explain_sleep(3)
π€ 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 originalseconds, exactly as passed to thesleep(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 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. so like, grab it early or it's gone, iykyk πsecondsβ the originalseconds, exactly as passed to thesleep(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 originalseconds, exactly as passed to thesleep(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 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. protect yourerrno, bestie π«Άsecondsβ the originalseconds, exactly as passed to thesleep(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 πβ¨
β¨ COPYRIGHT β¨
libexplainversion1.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
- 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