explain_realpath(3)

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

πŸ’– explain_realpath β€” the manual page, but make it make sense πŸ’–

okay bestie, so this is a page from the Library Functions Manual, and it's all about explain_realpath, a lil function that tells you why your realpath(3) call flopped. no cap, it's actually so useful. 🫢


✨ NAME ✨

explain_realpath β€” explain realpath(3) errors

like... it explains the errors. from realpath(3). that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/realpath.h>
const char *explain_realpath(const char *pathname, char *resolved_pathname);
const char *explain_errno_realpath(int errnum, const char *pathname,
        char *resolved_pathname);
void explain_message_realpath(char *message, int message_size,
        const char *pathname, char *resolved_pathname);
void explain_message_errno_realpath(char *message, int message_size, int errnum,
        const char *pathname, char *resolved_pathname);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically these functions are your little translators πŸ’¬ β€” you use them to get explanations for errors that the realpath(3) system call hands back to you. it's giving "your code messed up and now someone's gonna tell you exactly why."


πŸŽ€ explain_realpath πŸŽ€

const char *explain_realpath(const char *pathname, char *resolved_pathname);

ok so explain_realpath is the one you call to get an explanation of an error that came back from the realpath(3) system call. the least the message is gonna contain is the value of strerror(errno), but honestly? usually it does way better than that and tells you the actual underlying cause in more detail. slay. ✨

the errno global variable is what gets used to grab the error value that's gonna be decoded.

  • pathname β€” the original pathname, exactly as passed to the realpath(3) system call. exactly. don't be cute about it.
  • resolved_pathname β€” the original resolved_pathname, exactly as passed to the realpath(3) system call.

Returns: the message explaining the error. heads up though β€” this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. so it gets overwritten by the next call to any libexplain function that shares this buffer, including calls from 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 do too. periodt.

Example: this function is meant to be used in a fashion similar to the following example:

char *result = realpath(pathname, resolved_pathname);
if (!result)
{
    fprintf(stderr, "%s\n", explain_realpath(pathname,
    resolved_pathname));
    exit(EXIT_FAILURE);
}

and the above code example? it's available pre-packaged as the explain_realpath_or_die(3) function. iconic. πŸ‘‘


πŸ’œ explain_errno_realpath πŸ’œ

const char *explain_errno_realpath(int errnum, const char *pathname,
        char *resolved_pathname);

explain_errno_realpath is the one you use to obtain an explanation of an error returned by the realpath(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. fr fr. πŸ’…

  • 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. don't skip this step bestie, it will bite you. πŸ™ˆ
  • pathname β€” the original pathname, exactly as passed to the realpath(3) system call.
  • resolved_pathname β€” the original resolved_pathname, exactly as passed to the realpath(3) 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. 🫠

Example: this function is intended to be used in a fashion similar to the following example:

char *result = realpath(pathname, resolved_pathname);
if (!result)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_realpath(err, pathname,
    resolved_pathname));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_realpath_or_die(3) function. πŸŽ€


🌈 explain_message_realpath 🌈

void explain_message_realpath(char *message, int message_size,
        const char *pathname, char *resolved_pathname);

explain_message_realpath is used to obtain an explanation of an error returned by the realpath(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.

the errno global variable will be used to obtain the error value to be decoded.

  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. 🧚 that's the glow-up right there.
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • pathname β€” the original pathname, exactly as passed to the realpath(3) system call.
  • resolved_pathname β€” the original resolved_pathname, exactly as passed to the realpath(3) system call.

Example: this function is intended to be used in a fashion similar to the following example:

char *result = realpath(pathname, resolved_pathname);
if (!result)
{
    char message[3000];
    explain_message_realpath(message, sizeof(message), pathname,
    resolved_pathname);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_realpath_or_die(3) function. ✨


πŸ“ explain_message_errno_realpath πŸ“

void explain_message_errno_realpath(char *message, int message_size, int errnum,
        const char *pathname, char *resolved_pathname);

explain_message_errno_realpath is used to obtain an explanation of an error returned by the realpath(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.

  • 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. 😭 seriously, grab that errno first.
  • pathname β€” the original pathname, exactly as passed to the realpath(3) system call.
  • resolved_pathname β€” the original resolved_pathname, exactly as passed to the realpath(3) system call.

Example: this function is intended to be used in a fashion similar to the following example:

char *result = realpath(pathname, resolved_pathname);
if (!result)
{
    int err = errno;
    char message[3000];
    explain_message_errno_realpath(message, sizeof(message), err,
    pathname, resolved_pathname);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_realpath_or_die(3) function. πŸ’–


πŸ‘€ SEE ALSO πŸ‘€


  • libexplain version 1.4
  • Copyright (C) 2011 Peter Miller

ok that's the whole page, bestie, you're officially educated πŸŽ“πŸ’… no notes, you ate. this was the Library Functions Manual edition of explain_realpath(3), brought to you by libexplain version 1.4, copyright 2011 Peter Miller β€” go forth and debug like the main character you are. πŸ‘‘πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from