EXPLAIN_NANOSLEEP_OR_DIE(3)

📦
version 1.4.D001 · 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

💤 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 — the req, exactly as to be passed to the nanosleep(2) system call.
  • rem — the rem, exactly as to be passed to the nanosleep(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 🔥


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. 💜