explain_realloc(3)

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

πŸ’– explain_realloc(3) πŸ’–

okay bestie, gather round, because we're about to get deeply into explain_realloc from the Library Functions Manual and honestly? it's giving lifesaver. 🫢


✨ NAME ✨

explain_realloc β€” the girl whose whole job is explaining realloc(3) errors to you like a friend, not a compiler. πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/realloc.h>
const char *explain_realloc(void *ptr, size_t size);
const char *explain_errno_realloc(int errnum, void *ptr, size_t size);
void explain_message_realloc(char *message, int message_size, void *ptr,
size_t size);
void explain_message_errno_realloc(char *message, int message_size, int
errnum, void *ptr, size_t size);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: these functions exist so you can get explanations for errors that come back from the realloc(3) system call. like, actual words. actual reasons. not just a sad little NULL and vibes. 😭


🌟 explain_realloc

const char *explain_realloc(void *ptr, size_t size);

The explain_realloc function is how you get an explanation of an error returned by the realloc(3) system call. The least the message will contain is the value of strerror(errno), but usually it does so much better than that and tells you the underlying cause in way more detail. iconique behavior, no cap. πŸ‘‘

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

This function is meant to be used in a fashion similar to this example:

void *new_ptr = realloc(ptr, size);
if (!new_ptr)
{
    fprintf(stderr, "%s\n", explain_realloc(ptr, size));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_realloc_or_die(3) function. πŸŽ€

  • ptr β€” the original ptr, exactly as passed to the realloc(3) system call. don't get cute with it, pass it as-is.
  • size β€” the original size, exactly as passed to the realloc(3) system call. same energy.

Returns: The message explaining the error. This message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. It will be overwritten by the next call to any libexplain function that shares this buffer β€” including calls from other threads. so yeah. it's communal. πŸ™ˆ

Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library do the same thing. lowkey a group project situation and you know how those go. πŸ’€

🌈 explain_errno_realloc

const char *explain_errno_realloc(int errnum, void *ptr, size_t size);

The explain_errno_realloc function gets you an explanation of an error returned by the realloc(3) system call. The least the message will contain is the value of strerror(errnum), but usually it does way better and points at the underlying cause in more detail. obsessed. ✨

This function is meant to be used in a fashion similar to this example:

void *new_ptr = realloc(ptr, size);
if (!new_ptr)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_realloc(err, ptr, size));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_realloc_or_die(3) function. πŸŽ€

  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right before this function is called. This matters if you need to run any code between the system call being explained and this function, because lots of libc functions will go and change the value of errno on you. sneaky. 😀
  • ptr β€” the original ptr, exactly as passed to the realloc(3) system call.
  • size β€” the original size, exactly as passed to the realloc(3) system call.

Returns: The message explaining the error. This message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. It will be overwritten by the next call to any libexplain function that shares this buffer, including other threads.

Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. periodt.

πŸ’œ explain_message_realloc

void explain_message_realloc(char *message, int message_size, void *ptr,
size_t size);

The explain_message_realloc function may be used to obtain an explanation of an error returned by the realloc(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. it's giving thorough. πŸ’…

The errno global variable will be used to obtain the error value to be decoded.

This function is meant to be used in a fashion similar to this example:

void *new_ptr = realloc(ptr, size);
if (!new_ptr)
{
    char message[3000];
    explain_message_realloc(message, sizeof(message), ptr, size);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_realloc_or_die(3) function. πŸŽ€

  • message β€” the location where the returned message gets stored. If you supply a suitable message return buffer, this function is thread safe. slay. πŸ”₯
  • message_size β€” the size in bytes of the location where the returned message gets stored.
  • ptr β€” the original ptr, exactly as passed to the realloc(3) system call.
  • size β€” the original size, exactly as passed to the realloc(3) system call.

🧚 explain_message_errno_realloc

void explain_message_errno_realloc(char *message, int message_size, int
errnum, void *ptr, size_t size);

The explain_message_errno_realloc function may be used to obtain an explanation of an error returned by the realloc(3) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. main character explanation energy, honestly. πŸ‘‘

This function is meant to be used in a fashion similar to this example:

void *new_ptr = realloc(ptr, size);
if (!new_ptr)
{
    int err = errno;
    char message[3000];
    explain_message_errno_realloc(message, sizeof(message), err, ptr, size);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_realloc_or_die(3) function. πŸŽ€

  • message β€” the location where the returned message gets stored. If you supply a suitable message return buffer, this function is thread safe. we love a safe queen. πŸ’–
  • message_size β€” the size in bytes of the location where the returned message gets stored.
  • 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. (rude of them, but okay.)
  • ptr β€” the original ptr, exactly as passed to the realloc(3) system call.
  • size β€” the original size, exactly as passed to the realloc(3) system call.

πŸ‘€ SEE ALSO πŸ‘€


libexplain version 1.4 Copyright (C) 2009 Peter Miller


okay that's the whole page bestie, go forth and decode your errors. πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ’…πŸ«ΆπŸ‘‘

this has been explain_realloc(3) from the Library Functions Manual, brought to you by libexplain version 1.4, copyright (C) 2009 Peter Miller β€” mwah, take care of her, she's iconic πŸŽ€

πŸ“¦ where this page comes from