explain_strndup_or_die(3)

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

πŸ’– explain_strndup_or_die(3) πŸ’–

okay bestie, so this one lives in the Library Functions Manual and it's literally called explain_strndup_or_die β€” say that three times fast, I dare you 🫢


✨ NAME ✨

explain_strndup_or_die β€” duplicate a string and report errors πŸ¦‹


🌸 SYNOPSIS 🌸

#include <libexplain/strndup.h>
char *explain_strndup_or_die(const char *data, size_t data_size);
char *explain_strndup_on_error(const char *data, size_t data_size);

πŸ’… DESCRIPTION πŸ’…

So the explain_strndup_or_die function is what you call when you wanna call the strndup(3) system call, but with backup. Like, if things go wrong? An explanation gets printed to stderr, and it comes straight from the explain_strndup(3) function, and then the process terminates by calling exit(EXIT_FAILURE). No take-backs, no second chances. it's giving dramatic exit πŸ’€

The explain_strndup_on_error function is the gentler sibling ✨. It also calls the strndup(3) system call, and on failure it also prints an explanation to stderr (again obtained from the explain_strndup(3) function) β€” but instead of ending it all, it still returns to the caller. So you get the tea and you survive. queen behavior πŸ‘‘

  • data β€” the data, exactly as to be passed to the strndup(3) system call. no edits, no remixes, pass it through fr fr.
  • data_size β€” the data_size, exactly as to be passed to the strndup(3) system call. same energy, same deal.

πŸŽ€ RETURN VALUE πŸŽ€

The explain_strndup_or_die function only returns on success β€” peep strndup(3) for more info on that. On failure, it prints an explanation and exits, it does not return. like, at all. gone. bye πŸ‘‹

The explain_strndup_on_error function always returns the value returned by the wrapped strndup(3) system call. always. that's its whole thing πŸ’œ


🌈 EXAMPLE 🌈

The explain_strndup_or_die function is intended to be used in a fashion similar to the following example:

char *result = explain_strndup_or_die(data, data_size);

look at her go 😭 so clean, so simple, so iconic.


πŸ”₯ SEE ALSO πŸ”₯


libexplain version 1.4 Copyright (C) 2009 Peter Miller

and that's the whole page bestie, no cap 🫢 this was explain_strndup_or_die(3) from the Library Functions Manual, brought to you by libexplain version 1.4, Copyright (C) 2009 Peter Miller β€” mwah, slay, periodt πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from