explain_strndup_or_die(3)
π 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 thestrndup(3)system call. no edits, no remixes, pass it through fr fr.data_sizeβ thedata_size, exactly as to be passed to thestrndup(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 π₯
strndup(3)β duplicate a stringexplain_strndup(3)β explainstrndup(3)errorsexit(2)β terminate the calling process
π COPYRIGHT π
libexplain version 1.4Copyright (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
- 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) 2009, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms