explain_fchown(3)

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

πŸ’– explain_fchown(3) β€” the glow-up edition πŸ’–

okay bestie, so this is a page from the Library Functions Manual, and it's all about explain_fchown β€” the function that tells you why your fchown(2) call said no. she's giving very much "let me translate the errno for you, girlie" energy. πŸ¦‹


✨ NAME ✨

explain_fchown β€” explain fchown(2) errors πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/fchown.h>
const char *explain_fchown(int fildes, int owner, int group);
const char *explain_errno_fchown(int errnum, int fildes, int owner, int
group);
void explain_message_fchown(char *message, int message_size, int fildes,
int owner, int group);
void explain_message_errno_fchown(char *message, int message_size, int
errnum, int fildes, int owner, int group);

πŸ‘‘ DESCRIPTION πŸ‘‘

so these four functions are your little translators πŸ’– you use them to get explanations for errors that the fchown(2) system call handed back to you. no more staring at a cryptic errno like it's a cryptic text from your ex. 😭

πŸ’… explain_fchown

const char *explain_fchown(int fildes, int owner, int group);

explain_fchown gets you an explanation of an error returned by the fchown(2) system call. the bare minimum you'll get in that message is the value of strerror(errno) β€” but bestie, usually it does so much better than that and points at the actual underlying cause in way more detail. slay. ✨

the errno global variable is the one being used to grab the error value that gets decoded.

this function is meant to be used in a fashion similar to this iconic little example:

if (fchown(fildes, owner, group) < 0)
{
    fprintf(stderr, "%s\n", explain_fchown(fildes, owner, group));
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_fchown_or_die(3) function.

  • fildes β€” the original fildes, exactly as passed to the fchown(2) system call.
  • owner β€” the original owner, exactly as passed to the fchown(2) system call.
  • group β€” the original group, exactly as passed to the fchown(2) system call.

Returns:

the message explaining the error. 🫢 this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. it will be 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 lots of other functions in this library do too. 😭

πŸŽ€ explain_errno_fchown

const char *explain_errno_fchown(int errnum, int fildes, int owner, int
group);

explain_errno_fchown gets you an explanation of an error returned by the fchown(2) system call. the least the message will contain is the value of strerror(errnum) β€” but usually it does much better and clues you in on the underlying cause with more detail. πŸ’–

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

if (fchown(fildes, owner, group) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n",
        explain_errno_fchown(err, fildes, owner, group));
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_fchown_or_die(3) function.

  • 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 alter the value of errno. πŸ’€
  • fildes β€” the original fildes, exactly as passed to the fchown(2) system call.
  • owner β€” the original owner, exactly as passed to the fchown(2) system call.
  • group β€” the original group, exactly as passed to the fchown(2) system call.

Returns:

the message explaining the error. this message buffer is shared by all libexplain functions which don't supply a buffer in their argument list. it will be overwritten by the next call to any libexplain function that 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 do too. no cap.

πŸ¦‹ explain_message_fchown

void explain_message_fchown(char *message, int message_size, int fildes,
int owner, int group);

explain_message_fchown may be used to obtain an explanation of an error returned by the fchown(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 is used to obtain the error value to be decoded.

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

if (fchown(fildes, owner, group) < 0)
{
    char message[3000];
    explain_message_fchown(message, sizeof(message), fildes, owner, group);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_fchown_or_die(3) function.

  • 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.
  • fildes β€” the original fildes, exactly as passed to the fchown(2) system call.
  • owner β€” the original owner, exactly as passed to the fchown(2) system call.
  • group β€” the original group, exactly as passed to the fchown(2) system call.

🌈 explain_message_errno_fchown

void explain_message_errno_fchown(char *message, int message_size, int
errnum, int fildes, int owner, int group);

explain_message_errno_fchown may be used to obtain an explanation of an error returned by the fchown(2) system call. the least the message will contain is the value of strerror(errnum), but usually it does much better, and indicates the underlying cause in more detail. πŸ’œ

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

if (fchown(fildes, owner, group) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_fchown(message, sizeof(message),
        err, fildes, owner, group);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre‐packaged as the explain_fchown_or_die(3) function.

  • 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. 😭
  • fildes β€” the original fildes, exactly as passed to the fchown(2) system call.
  • owner β€” the original owner, exactly as passed to the fchown(2) system call.
  • group β€” the original group, exactly as passed to the fchown(2) system call.

⭐ SEE ALSO ⭐


libexplain version 1.4 Copyright (C) 2008 Peter Miller


and that's the whole page, bestie β€” no notes, she ate πŸ’…βœ¨ this was explain_fchown(3) from libexplain version 1.4, copyright (C) 2008 Peter Miller, and honestly? iconic. go forth and decode your errnos. πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from