explain_nanosleep(3)
π€ explain_nanosleep(3) β Library Functions Manual π€
okay bestie, sit DOWN because we're about to talk about explain_nanosleep(3), from the libexplain library functions manual. this is the page that tells you why your nanosleep(2) call flopped, and honestly? it's giving "therapist for your errno" and i'm obsessed π
β¨ NAME β¨
explain_nanosleep β explain nanosleep(2) errors π«Ά
β¨ SYNOPSIS β¨
#include <libexplain/nanosleep.h>
const char *explain_nanosleep(const struct timespec *req, struct
timespec *rem);
const char *explain_errno_nanosleep(int errnum, const struct timespec
*req, struct timespec *rem);
void explain_message_nanosleep(char *message, int message_size, const
struct timespec *req, struct timespec *rem);
void explain_message_errno_nanosleep(char *message, int message_size,
int errnum, const struct timespec *req, struct timespec *rem);
β¨ DESCRIPTION β¨
so here's the tea β β these functions are your little translators. you hand them the wreckage of a failed nanosleep(2) system call, and they hand you back an explanation. not just a shrug, an actual explanation. periodt.
πΈ explain_nanosleep πΈ
const char *explain_nanosleep(const struct timespec *req, struct
timespec *rem);
explain_nanosleep is the one you call to get an explanation of an error returned by the nanosleep(2) system call. the least you're gonna get in that message is the value of strerror(errno), but usually it does so much better and actually tells you the underlying cause in more detail. like, it's not just gonna say "something broke", it's gonna say what broke and why. main character energy fr fr β¨
the errno global variable is what gets used to grab the error value that's gonna be decoded.
reqβ the originalreq, exactly as passed to thenanosleep(2)system call. no edits, no glow-up, just the raw original.remβ the originalrem, exactly as passed to thenanosleep(2)system call. same deal π
Returns: the message explaining the error. and here's the important part bestie β this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. so it will be overwritten by the next call to any libexplain function that shares this buffer, including calls from other threads. so don't get attached to it, okay? π
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. not me calling this from multiple threads and wondering why everything's cursed π
Example: this function is meant to be used in a fashion similar to the following example:
if (nanosleep(req, rem) < 0)
{
fprintf(stderr, "%s\n", explain_nanosleep(req, rem));
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function. so if you want the whole thing ready-made, that's your girl π
π explain_errno_nanosleep π
const char *explain_errno_nanosleep(int errnum, const struct timespec
*req, struct timespec *rem);
explain_errno_nanosleep is used to obtain an explanation of an error returned by the nanosleep(2) system call. again, 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, no notes π
errnumβ the error value to be decoded, usually obtained from theerrnoglobal variable just before this function is called. and why does the timing matter? because if you need to call any code between the system call you're explaining and this function, you HAVE to stash it first β many libc functions will alter the value oferrno. so grab it early or it's gone, girl πreqβ the originalreq, exactly as passed to thenanosleep(2)system call.remβ the originalrem, exactly as passed to thenanosleep(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. it will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. yes, again. it's the same buffer, bestie, it's a whole vibe π¦
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.
Example: this function is intended to be used in a fashion similar to the following example:
if (nanosleep(req, rem) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_nanosleep(err, req,
rem));
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function.
π explain_message_nanosleep π
void explain_message_nanosleep(char *message, int message_size, const
struct timespec *req, struct timespec *rem);
explain_message_nanosleep is used to obtain an explanation of an error returned by the nanosleep(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. we love an overachiever π
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. and here's the slay: 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.reqβ the originalreq, exactly as passed to thenanosleep(2)system call.remβ the originalrem, exactly as passed to thenanosleep(2)system call.
Example: this function is intended to be used in a fashion similar to the following example:
if (nanosleep(req, rem) < 0)
{
char message[3000];
explain_message_nanosleep(message, sizeof(message), req,
rem);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function. yes, char message[3000], that's the size, don't come for me, it's literally what the page says π
π§ explain_message_errno_nanosleep π§
void explain_message_errno_nanosleep(char *message, int message_size,
int errnum, const struct timespec *req, struct timespec *rem);
explain_message_errno_nanosleep is used to obtain an explanation of an error returned by the nanosleep(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 whole combo meal, fr fr π
messageβ the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. she said "i bring my own buffer" and honestly? respect π«Ά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 before something else eats it, bestie πreqβ the originalreq, exactly as passed to thenanosleep(2)system call.remβ the originalrem, exactly as passed to thenanosleep(2)system call.
Example: this function is intended to be used in a fashion similar to the following example:
if (nanosleep(req, rem) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_nanosleep(message, sizeof(message),
err, req, rem);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_nanosleep_or_die(3) function.
β¨ SEE ALSO β¨
nanosleep(2)β high-resolution sleep π΄explain_nanosleep_or_die(3)β high-resolution sleep and report errors πβ‘οΈπ
β¨ COPYRIGHT β¨
libexplain version 1.4 Copyright (C) 2013 Peter Miller
and that's the whole page, bestie!! π go forth, sleep with high resolution, and if it fails, at least you'll know exactly why. this has been the explain_nanosleep(3) page from the Library Functions Manual β libexplain version 1.4, Copyright (C) 2013 Peter Miller, dated and everything. mwah π
β¨πΈ
π¦ 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