explain_strndup(3)

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

✨ explain_strndup(3) ✨

Library Functions Manual πŸŽ€ β€” yeah bestie, this is the libexplain page that turns your cursed strndup(3) errors into actual sentences. Let's get into it πŸ’…


🌸 NAME 🌸

explain_strndup β€” explain strndup(3) errors πŸ’–


✨ SYNOPSIS ✨

#include <libexplain/strndup.h>
const char *explain_strndup(const char *data, size_t data_size);
const char *explain_errno_strndup(int errnum, const char *data, size_t
data_size);
void explain_message_strndup(char *message, int message_size, const char
*data, size_t data_size);
void explain_message_errno_strndup(char *message, int message_size, int
errnum, const char *data, size_t data_size);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so, the whole vibe of these functions? They hand you explanations for errors that came back from the strndup(3) system call. That's it. That's the job. πŸ‘‘


πŸ’œ explain_strndup

const char *explain_strndup(const char *data, size_t data_size);

So explain_strndup is your girl for getting an explanation of an error returned by the strndup(3) system call. The absolute least the message will contain is the value of strerror(errno) β€” but honestly? Usually it does so much better and points at the actual underlying cause in more detail. no cap πŸ”₯

The errno global variable is what gets used to grab the error value that needs decoding. periodt.

  • data β€” the original data, exactly as passed to the strndup(3) system call. like, exactly. don't get cute with it πŸ™ˆ
  • data_size β€” the original data_size, exactly as passed to the strndup(3) system call.

Returns: the message explaining the error. πŸ’Œ Heads up though β€” this message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. It gets overwritten by the next call to any libexplain function that shares this buffer, including from other threads. so yeah 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library too. it's giving communal energy in the worst way πŸ’€

Example: this function is meant to be used in a fashion similar to the following example:

char *result = strndup(data, data_size);
if (!result)
{
    fprintf(stderr, "%s\n", explain_strndup(data, data_size));
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_strndup_or_die(3) function. iconic, honestly 🫢


🌈 explain_errno_strndup

const char *explain_errno_strndup(int errnum, const char *data, size_t
data_size);

explain_errno_strndup is here to obtain an explanation of an error returned by the strndup(3) system call. Least it'll give you is the value of strerror(errno), but usually it goes way harder and shows the underlying cause in more detail. ⭐

  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right before this function is called. Why does that matter? Because if you need to run any code between the system call you're explaining and this function, you gotta stash it β€” tons of libc functions will mess with the value of errno behind your back. rude of them fr fr πŸ’€
  • data β€” the original data, exactly as passed to the strndup(3) system call.
  • data_size β€” the original data_size, exactly as passed to the strndup(3) system call.

Returns: the message explaining the error. Same deal as before: this message buffer is shared by all libexplain functions which do not supply a buffer in their argument list, and it will be overwritten by the next call to any libexplain function sharing this buffer β€” other threads included. πŸ™ˆ

Note: not thread safe, because it shares a return buffer across all threads, and many other functions in this library. same warning, different function, still important bestie 😭

Example: this function is meant to be used in a fashion similar to the following example:

char *result = strndup(data, data_size);
if (!result)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_strndup(err, data,
    data_size));
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_strndup_or_die(3) function. slay πŸ’…


πŸŽ€ explain_message_strndup

void explain_message_strndup(char *message, int message_size, const char
*data, size_t data_size);

explain_message_strndup obtains an explanation of an error returned by the strndup(3) system call. The least the message will contain is the value of strerror(errno), but usually it does much better and indicates the underlying cause in more detail. πŸ’–

The errno global variable is what's used to obtain the error value to be decoded.

  • message β€” where to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. look at her go, being all safe and considerate ✨
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • data β€” the original data, exactly as passed to the strndup(3) system call.
  • data_size β€” the original data_size, exactly as passed to the strndup(3) system call.

Example: this function is meant to be used in a fashion similar to the following example:

char *result = strndup(data, data_size);
if (!result)
{
    char message[3000];
    explain_message_strndup(message, sizeof(message), data,
    data_size);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_strndup_or_die(3) function. πŸ¦‹


⭐ explain_message_errno_strndup

void explain_message_errno_strndup(char *message, int message_size, int
errnum, const char *data, size_t data_size);

explain_message_errno_strndup obtains an explanation of an error returned by the strndup(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. main character energy fr πŸ‘‘

  • message β€” where to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. 🫢
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • errnum β€” the error value to be decoded, usually obtained from the errno global variable just before this function is called. This is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. (yes, again. they do it every time 😭)
  • data β€” the original data, exactly as passed to the strndup(3) system call.
  • data_size β€” the original data_size, exactly as passed to the strndup(3) system call.

Example: this function is meant to be used in a fashion similar to the following example:

char *result = strndup(data, data_size);
if (!result)
{
    int err = errno;
    char message[3000];
    explain_message_errno_strndup(message, sizeof(message), err,
    data, data_size);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_strndup_or_die(3) function. ate. no crumbs. πŸ’…


🌈 SEE ALSO 🌈


  • libexplain version 1.4
  • Copyright (C) 2009 Peter Miller

and that's the whole page bestie πŸ’– thanks for reading the explain_strndup(3) manual, brought to you by libexplain version 1.4, with Copyright (C) 2009 Peter Miller holding it down since way back. mwah πŸŽ€βœ¨πŸ’œ

πŸ“¦ where this page comes from