EXPLAIN_NANOSLEEP_OR_DIE(3)
💤 explain_nanosleep_or_die(3) 💤
okay bestie, so this one lives in the Library Functions Manual section 3, and it's literally just "take a nap, but if the nap goes wrong, we're gonna talk about it" energy. no cap. 🫶
✨ NAME ✨
explain_nanosleep_or_die — high-resolution sleep and report errors
🌸 SYNOPSIS 🌸
#include <libexplain/nanosleep.h>
void explain_nanosleep_or_die(const struct timespec *req, struct
timespec *rem);
int explain_nanosleep_on_error(const struct timespec *req, struct
timespec *rem);
💅 DESCRIPTION 💅
so there's two functions here and they're like sisters, same vibe, different endings. 🎀
explain_nanosleep_or_die — this one calls the nanosleep(2) system call for you. and if it fails? it prints an explanation to stderr, and that explanation is grabbed from the explain_nanosleep(3) function. then it just… ends the whole process by calling exit(EXIT_FAILURE). it's giving main character exit. periodt. 💀
explain_nanosleep_on_error — same deal, it calls the nanosleep(2) system call. if it fails it also prints an explanation to stderr, also grabbed from explain_nanosleep(3). BUT. it still returns to the caller. no dramatic exit. it just hands you the info and lets you keep going. 🦋
req— thereq, exactly as to be passed to thenanosleep(2)system call.rem— therem, exactly as to be passed to thenanosleep(2)system call.
like, no transformations, no extra seasoning, they go through exactly as-is. ✨
🌈 RETURN VALUE 🌈
explain_nanosleep_or_die only returns on success — and if you wanna know more about what success even looks like here, go check nanosleep(2). on failure it prints an explanation and exits, so like… it does not return. it left the chat. 👑😭
explain_nanosleep_on_error always returns the value returned by the wrapped nanosleep(2) system call. that's it, that's the whole tea. 🍓
⭐ EXAMPLE ⭐
the explain_nanosleep_or_die function is intended to be used in a fashion similar to the following example:
explain_nanosleep_or_die(req, rem);
look at that. one line. iconic. no error handling because the handling is the dying. 💅
🔥 SEE ALSO 🔥
nanosleep(2)— high-resolution sleepexplain_nanosleep(3)— explainnanosleep(2)errorsexit(2)— terminate the calling process
🎀 COPYRIGHT 🎀
libexplain version 1.4 Copyright (C) 2013 Peter Miller
ngl bestie, if you're calling the _or_die version, make sure you actually want the process to end on failure, because it absolutely will. no takebacks. 🙈
that's the whole page, you ate it, mwah 💖
— explain_nanosleep_or_die(3), out. 💜
📦 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