explain_link(3)

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

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. πŸ™ˆ


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 original oldpath, exactly as it was passed to the link(2) system call. don't get creative with it, fr fr.
  • newpath β€” the original newpath, also exactly as passed to the link(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 πŸ’€

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 the errno global 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 of errno behind your back. 🫠
  • oldpath β€” the original oldpath, exactly as passed to the link(2) system call.
  • newpath β€” the original newpath, exactly as passed to the link(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.

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 original oldpath, exactly as passed to the link(2) system call.
  • newpath β€” the original newpath, exactly as passed to the link(2) system call.

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 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. it's a whole thing.)
  • oldpath β€” the original oldpath, exactly as passed to the link(2) system call.
  • newpath β€” the original newpath, exactly as passed to the link(2) system call.

πŸ”₯ SEE ALSO πŸ”₯


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