explain_symlink(3)
okay bestie, pull up a chair β this is explain_symlink(3) from the Library Functions Manual, and it's basically the glow-up your error messages have been begging for. It's all about turning those cursed symlink(2) failures into something that actually tells you what went wrong. π
β¨ NAME β¨
explain_symlink β explain symlink(2) errors π«Ά
πΈ SYNOPSIS πΈ
#include <libexplain/symlink.h>
const char *explain_symlink(const char *oldpath, const char *newpath);
const char *explain_errno_symlink(int errnum, const char *oldpath, const
char *newpath);
void explain_message_symlink(char *message, int message_size, const char
*oldpath, const char *newpath);
void explain_message_errno_symlink(char *message, int message_size, int
errnum, const char *oldpath, const char *newpath);
π¦ DESCRIPTION π¦
So these functions? They're how you get explanations for symlink(2) errors. Like, actual explanations. Not just "something broke lol". No cap. π
π explain_symlink
const char *explain_symlink(const char *oldpath, const char *newpath);
The explain_symlink function is your go-to for getting an explanation of an error returned by the symlink(2) system call. The bare minimum the message will contain is the value of strerror(errno), but honestly? Usually it does so much better, and it'll point at the underlying cause in way more detail. It's giving detective energy. π
The errno global variable is what gets used to obtain the error value to be decoded.
This function is intended to be used in a fashion similar to the following example:
if (symlink(oldpath, rewpath) < 0)
{
fprintf(stderr, '%s0, explain_symlink(oldpath, newpath));
exit(EXIT_FAILURE);
}
oldpathβ The original oldpath, exactly as passed to thesymlink(2)system call. Don't get cute with it, pass it as-is. β¨newpathβ The original newpath, exactly as passed to thesymlink(2)system call. Same deal. π«
Returns:
The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. So like... don't hold onto it, bestie. π
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_errno_symlink
const char *explain_errno_symlink(int errnum, const char *oldpath, const
char * newpath);
The explain_errno_symlink function is used to obtain an explanation of an error returned by the symlink(2) 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. Iconic behaviour, honestly. π
This function is intended to be used in a fashion similar to the following example:
if (symlink(oldpath, newpath) < 0)
{
int err = errno;
fprintf(stderr, '%s0, explain_errno_symlink(err, oldpath,
newpath));
exit(EXIT_FAILURE);
}
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. Snatch that value immediately, okay? πβοΈoldpathβ The original oldpath, exactly as passed to thesymlink(2)system call.newpathβ The original newpath, exactly as passed to thesymlink(2)system call.
Returns:
The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which 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. Same warning, same vibe. π
π explain_message_symlink
void explain_message_symlink(char *message, int message_size, const char
*oldpath, const char *newpath);
The explain_message_symlink function is used to obtain an explanation of an error returned by the symlink(2) 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. π
The errno]fP global variable will be used to obtain the error value to be decoded. (Yes, we are reading that exactly as written. No, we are not touching it. π
)
This function is intended to be used in a fashion similar to the following example:
if (symlink(oldpath, newpath) < 0)
{
char message[3000];
explain_message_symlink(message, sizeof(message), oldpath,
newpath);
fprintf(stderr, '%s0, message);
exit(EXIT_FAILURE);
}
messageβ The location in which to store the returned message. Because a message return buffer has been supplied, this function is thread safe. Glow up achieved. β¨message_sizeβ The size in bytes of the location in which to store the returned message. πoldpathβ The original oldpath, exactly as passed to thesymlink(2)system call.newpathβ The original newpath, exactly as passed to thesymlink(2)system call.
π§ explain_message_errno_symlink
void explain_message_errno_symlink(char *message, int message_size, int
errnum, const char *oldpath, const char *newpath);
The explain_message_errno_symlink function is used to obtain an explanation of an error returned by the symlink(2) 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. π
This function is intended to be used in a fashion similar to the following example:
if (symlink(oldpath, newpath) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_symlink(message, sizeof(message), err,
oldpath, newpath);
fprintf(stderr, '%s0, message);
exit(EXIT_FAILURE);
}
messageβ The location in which to store the returned message. Because a message return buffer has been 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 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. Grab it early, bestie. πβοΈoldpathβ The original oldpath, exactly as passed to thesymlink(2)system call.newpathβ The original newpath, exactly as passed to thesymlink(2)system call.
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2008 Peter Miller
π AUTHOR π
Written by Peter Miller <pmiller@opensource.org.au>
and that's the whole page, no notes. This was explain_symlink(3), straight out of the Library Functions Manual β shoutout to libexplain version 1.4 for the source and version, and to the date this beauty was stamped, all wrapped up in that final explain_symlink(3) footer energy. bye bestie, go explain some errors πβ¨
π¦ 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) 2008, 2009, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms