explain_fchdir(3)

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

πŸ’– explain_fchdir(3) β€” Library Functions Manual πŸ’–

okay bestie, sit down, hydrate, and let me tell you about explain_fchdir from the library functions manual β€” she's a lil function that translates your fchdir(2) disasters into actual human words 🫢


✨ NAME ✨

explain_fchdir β€” bestie, this one exists purely to explain your fchdir(2) errors 😭 no more staring at a cryptic number like it owes you money.


🌸 SYNOPSIS 🌸

#include <libexplain/fchdir.h>
const char *explain_fchdir(int fildes);
void explain_message_fchdir(char *message, int message_size, int
fildes);
const char *explain_errno_fchdir(int errnum, int fildes);
void explain_message_errno_fchdir(char *message, int message_size, int
errnum, int fildes);

πŸ¦‹ DESCRIPTION πŸ¦‹

These functions are the whole point of the vibe: you use them to get explanations for errors coming back from the fchdir(2) system call. Like, the actual reason. Iconic behaviour honestly ✨

πŸ’œ explain_fchdir

const char *explain_fchdir(int fildes);

So the explain_fchdir function hands you an explanation of an error that fchdir(2) returned. The absolute minimum it'll give you is the value of strerror(errno) β€” but bestie, usually she does so much better and points straight at the underlying cause in way more detail. Ate. πŸ’…

The errno global variable is what gets used to grab the error value that needs decoding.

She's meant to be used in a fashion like this little example here:

if (fchdir(fildes) < 0)
{
    fprintf(stderr, '%s0, explain_fchdir(fildes));
    exit(EXIT_FAILURE);
}
  • fildes β€” the original fildes, exactly as it was passed to the fchdir(2) system call. No substitutions, no edits, the real one πŸ‘‘

Returns:

The message explaining the error. ⚠️ heads up bestie: this message buffer is shared by all the libexplain functions that don't supply a buffer in their argument list. So it gets overwritten by the very next call to any libexplain function that shares that buffer β€” including calls from other threads. 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. Not her fault, it's a buffer situation.

🌈 explain_errno_fchdir

const char *explain_errno_fchdir(int errnum, int fildes);

The explain_errno_fchdir function also gives you an explanation of an error returned by the fchdir(2) system call. The least the message will contain is the value of strerror(errnum) β€” but again, usually it goes way harder and tells you the underlying cause in more detail. πŸ’–

She's intended to be used in a fashion similar to this:

if (fchdir(fildes) < 0)
{
    int err = errno;
    fprintf(stderr, '%s0, explain_errno_fchdir(err, fildes));
    exit(EXIT_FAILURE);
}
  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right before this function is called. This is necessary if you need to run any code between the system call being explained and this function, because so many libc functions will mess with the value of errno. Sneaky. πŸ™ˆ
  • fildes β€” the original fildes, exactly as passed to the fchdir(2) system call.

Returns:

The message explaining the error. Same tea as before: this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list, and it will be overwritten by the next call to any libexplain function sharing that buffer β€” other threads included. πŸ’€

Note: not thread safe, because the return buffer is shared across all threads, and so are many other functions in this library.

πŸŽ€ explain_message_fchdir

void explain_message_fchdir(char *message, int message_size, int
fildes);

The explain_message_fchdir function is your girl for obtaining an explanation of an error returned by the fchdir(2) system call. Minimum content = the value of strerror(errno), but usually it does way better and indicates the underlying cause with more detail. Obsessed. ✨

The errno global variable is what's used to obtain the error value to be decoded.

Use her like this:

if (fchdir(fildes) < 0)
{
    char message[3000];
    explain_message_fchdir(message, sizeof(message), fildes);
    fprintf(stderr, '%s0, message);
    exit(EXIT_FAILURE);
}
  • message β€” the location where the returned message gets stored. Because you supplied the message return buffer, this function is thread safe πŸŽ‰ slay!
  • message_size β€” the size in bytes of the location where the returned message gets stored.
  • fildes β€” the original fildes, exactly as passed to the fchdir(2) system call.

🧚 explain_message_errno_fchdir

void explain_message_errno_fchdir(char *message, int message_size, int
errnum, int fildes);

The explain_message_errno_fchdir function obtains an explanation of an error returned by the fchdir(2) system call. The least the message will contain is the value of strerror(errnum), but usually it does much better and shows the underlying cause in more detail. Queen behaviour πŸ‘‘

Here's the vibe:

if (fchdir(fildes) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_fchdir(message, sizeof(message), err,
        fildes);
    fprintf(stderr, '%s0, message);
    exit(EXIT_FAILURE);
}
  • message β€” where the returned message gets stored. Since a message return buffer was supplied, this function is thread safe 🫢
  • message_size β€” the size in bytes of the location where the returned message gets stored.
  • 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. They're chaotic like that 😭)
  • fildes β€” the original fildes, exactly as passed to the fchdir(2) system call.

libexplain version 1.4 Copyright (C) 2008 Peter Miller


πŸ’œ AUTHOR πŸ’œ

Written by Peter Miller <pmiller@opensource.org.au> β€” ty for the lore king 🫑


okay so that's the whole page bestie, we made it πŸ’…βœ¨ explain_fchdir(3) β€” from the Library Functions Manual, libexplain version 1.4, Copyright (C) 2008 Peter Miller. Go explain your errors and be the main character of your own stderr πŸŒΈπŸ¦‹πŸ’–

πŸ“¦ where this page comes from