explain_system_or_die(3)

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

πŸ’– explain_system_or_die(3) πŸ’–

okay bestie, so this is explain_system_or_die from the Library Functions Manual β€” yes she's a manual page, yes she's serving, and yes she will help you run shell commands without the whole "why did it break tho" situation. sit down, hydrate, let's go. 🫢


✨ NAME ✨

explain_system_or_die β€” execute a shell command and report errors, like a bestie who tells you the truth πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/system.h>
void explain_system_or_die(const char *command);
void explain_system_success_or_die(const char *command);
int explain_system_success(const char *command);

three little functions, all in the group chat, all here to run your command and spill the tea when something goes wrong. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so these functions? they exist to run commands via the system(3) function, and then report the results. that's the whole vibe. no cap.

πŸ’œ explain_system_or_die

void explain_system_or_die(const char *command);

okay so explain_system_or_die is used to call the system(3) system call. and if it fails? an explanation gets printed to stderr (obtained from explain_system(3), iconic of her) and then the process terminates by calling exit(EXIT_FAILURE). she does not play. πŸ’€

the intended use is giving something like this:

int status = explain_system_or_die(command);
  • command β€” the command, exactly as to be passed to the system(3) system call. exactly. don't freestyle it.

Returns:

this function only returns on success β€” see system(3) for more info, bestie. on failure, it prints an explanation and exits. periodt.

🌈 explain_system_success_or_die

void explain_system_success_or_die(const char *command);

explain_system_success_or_die also calls the system(3) system call. but here's the plot twist: on failure β€” and "failure" here means any exit status other than EXIT_SUCCESS β€” an explanation gets printed to stderr, obtained from explain_system(3), and then the process terminates by calling exit(EXIT_FAILURE). so not only do you have to actually fail, you also have to not-EXIT_SUCCESS, which is a very high bar to clear. πŸ”₯

intended to be used like this:

explain_system_success_or_die(command);
  • command β€” the command, exactly as to be passed to the system(3) system call.

Returns:

only returns on success. on failure, prints an explanation and exits. that's it, that's the energy. ✨

πŸ“ explain_system_success

int explain_system_success(const char *command);

explain_system_success calls the system(3) system call too. on failure β€” again, including any exit status other than EXIT_SUCCESS β€” an explanation will be printed to stderr, obtained from explain_system(3). and then here's the key difference, bestie, listen closely: the printing of an error message does not also cause exit(2) to be called. she tells you what went wrong and then lets you live your life. main character energy honestly. πŸ‘‘

intended to be used like this:

int status = explain_system_success(command);
  • command β€” the command, exactly as to be passed to the system(3) system call.

Returns:

the value returned by the system(3) system call. and in all cases other than EXIT_SUCCESS, an error message will also have been printed to stderr. so you get the int and the drama. πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘


libexplain version 1.4

Copyright (C) 2008 Peter Miller


and that's the whole page bestie, we ate and left no crumbs πŸ’…βœ¨ this was explain_system_or_die(3) β€” go forth, run your commands, and let her explain the errors so you don't have to guess. mwah. πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from