explain_link(3)
β¨ explain_link(3) β¨ β Library Functions Manual
okay bestie, gather round, because this one is so useful and also kind of niche and I'm obsessed π
πΈ NAME πΈ
explain_link β bestie, this is the function family that explains your link(2) errors to you. Like, actually explains them. Not just "it broke lol". π
π¦ SYNOPSIS π¦
#include <libexplain/link.h>
const char *explain_link(const char *oldpath, const char *newpath);
const char *explain_errno_link(int errnum, const char *oldpath, const char *newpath);
void explain_message_link(char *message, int message_size, const char *oldpath, const char *newpath);
void explain_message_errno_link(char *message, int message_size, int errnum, const char *oldpath, const char *newpath);
π DESCRIPTION π
So these functions? They're how you get explanations for errors that came back from the link(2) system call. You know how link(2) just goes "nope" and hands you an errno and leaves you on read? Yeah. These fix that. π
π explain_link π
const char *explain_link(const char *oldpath, const char *newpath);
The explain_link function is your go-to for getting an explanation of an error that link(2) threw back at you. The bare minimum it'll ever contain is the value of strerror(errno) β but lowkey it usually does so much better than that, and tells you the actual underlying cause with way more detail. It's giving overachiever. β
The errno global variable is what it reads to figure out which error value to decode. iykyk.
This function is meant to be used in a fashion similar to this lil example right here:
if (link(oldpath, newpath) < 0)
{
fprintf(stderr, "%s\n", explain_link(oldpath, newpath));
exit(EXIT_FAILURE);
}
oldpathβ the originaloldpath, exactly as it was passed to thelink(2)system call. don't get creative with it, fr fr.newpathβ the originalnewpath, also exactly as passed to thelink(2)system call.
Returns:
The message explaining the error. π But here's the thing bestie β this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. So the next call to any libexplain function that shares this buffer will overwrite it, including calls from other threads. Yes, other threads. It said what it said. π
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. not me getting caught out by that at 3am π
π explain_errno_link π
const char *explain_errno_link(int errnum, const char *oldpath, const char *newpath);
The explain_errno_link function gets you an explanation of an error returned by the link(2) system call. The least the message will contain is the value of strerror(errnum), but usually it goes way harder and points at the underlying cause in more detail. π
This one is intended to be used like this:
if (link(oldpath, newpath) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_link(err, oldpath, newpath));
exit(EXIT_FAILURE);
}
errnumβ the error value to be decoded, usually grabbed from theerrnoglobal variable just before this function is called. And bestie, this part is necessary if you need to run any code between the system call you're explaining and this function, because so many libc functions will just casually alter the value oferrnobehind your back. π«oldpathβ the originaloldpath, exactly as passed to thelink(2)system call.newpathβ the originalnewpath, exactly as passed to thelink(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. periodt.
π§ explain_message_link π§
void explain_message_link(char *message, int message_size, const char *oldpath, const char *newpath);
The explain_message_link function may be used to obtain an explanation of an error returned by the link(2) 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 will be 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 (link(oldpath, newpath) < 0)
{
char message[3000];
explain_message_link(message, sizeof(message), oldpath, newpath);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
messageβ the location in which to store the returned message. And here's the slay part: if a suitable message return buffer is supplied, this function is thread safe. we love a safe queen πmessage_sizeβ the size in bytes of the location in which to store the returned message.oldpathβ the originaloldpath, exactly as passed to thelink(2)system call.newpathβ the originalnewpath, exactly as passed to thelink(2)system call.
π explain_message_errno_link π
void explain_message_errno_link(char *message, int message_size, int errnum, const char *oldpath, const char *newpath);
The explain_message_errno_link function may be used to obtain an explanation of an error returned by the link(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 (link(oldpath, newpath) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_link(message, sizeof(message), err,
oldpath, newpath);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
messageβ the location in which 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 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. (yes, again. it's a whole thing.)oldpathβ the originaloldpath, exactly as passed to thelink(2)system call.newpathβ the originalnewpath, exactly as passed to thelink(2)system call.
π₯ SEE ALSO π₯
link(2)β make a new name for a file β¨explain_link_or_die(3)β make a new name for a file and report errors πΈ
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2008 Peter Miller
and that's the whole page bestie!! π go forth, link your files, explain your errors, and remember: check errno immediately, stay thread safe, and never let anyone overwrite your buffer. π
β¨
libexplain version 1.4 Β· Copyright (C) 2008 Peter Miller Β· mwah, catch you on the next manpage π¦
π¦ 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