explain_realloc(3)
π 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 originalptr, exactly as passed to therealloc(3)system call. don't get cute with it, pass it as-is.sizeβ the originalsize, exactly as passed to therealloc(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 theerrnoglobal 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 oferrnoon you. sneaky. π€ptrβ the originalptr, exactly as passed to therealloc(3)system call.sizeβ the originalsize, exactly as passed to therealloc(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 originalptr, exactly as passed to therealloc(3)system call.sizeβ the originalsize, exactly as passed to therealloc(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 theerrnoglobal 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 oferrno. (rude of them, but okay.)ptrβ the originalptr, exactly as passed to therealloc(3)system call.sizeβ the originalsize, exactly as passed to therealloc(3)system call.
π SEE ALSO π
realloc(3)β Allocate and free dynamic memoryexplain_realloc_or_die(3)β Allocate and free dynamic memory and report errors
π COPYRIGHT π
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
- 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