explain_symlink(3)

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

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. πŸ’–

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 the symlink(2) system call. Don't get cute with it, pass it as-is. ✨
  • newpath β€” The original newpath, exactly as passed to the symlink(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. πŸ’€
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 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. Snatch that value immediately, okay? πŸƒβ™€οΈ
  • oldpath β€” The original oldpath, exactly as passed to the symlink(2) system call.
  • newpath β€” The original newpath, exactly as passed to the symlink(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. πŸ™ˆ
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 the symlink(2) system call.
  • newpath β€” The original newpath, exactly as passed to the symlink(2) system call.
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 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. Grab it early, bestie. πŸƒβ™€οΈ
  • oldpath β€” The original oldpath, exactly as passed to the symlink(2) system call.
  • newpath β€” The original newpath, exactly as passed to the symlink(2) system call.

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