explain_lchown(3)

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

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

okay bestie, gather round, because we're about to talk about explain_lchown from the Library Functions Manual section, and honestly? it's giving error-decoding royalty. πŸ‘‘


✨ NAME ✨

explain_lchown β€” explain lchown(2) errors 🫢


✨ SYNOPSIS ✨

#include <libexplain/lchown.h>
const char *explain_lchown(const char *pathname, int owner, int group);
const char *explain_errno_lchown(int errnum, const char *pathname, int owner, int group);
void explain_message_lchown(char *message, int message_size, const char *pathname, int owner, int group);
void explain_message_errno_lchown(char *message, int message_size, int errnum, const char *pathname, int owner, int group);

✨ DESCRIPTION ✨

so like, these functions? they're your little besties for getting explanations when the lchown(2) system call throws hands and returns an error. πŸ’… they don't just tell you that something broke β€” they tell you why, and they do it with main character energy.


🌸 explain_lchown 🌸

const char *explain_lchown(const char *pathname, int owner, int group);

the explain_lchown function is literally the way to get an explanation of an error that came back from the lchown(2) system call. the absolute bare minimum the message will contain is the value of strerror(errno) β€” but lowkey, usually it does so much better and points at the underlying cause in way more detail. no cap. ✨

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

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

if (lchown(pathname, owner, group) < 0)
{
    fprintf(stderr, "%s\n", explain_lchown(pathname, owner, group));
    exit(EXIT_FAILURE);
}
  • pathname β€” the original pathname, exactly as passed to the lchown(2) system call. like, exactly. don't be editing it, bestie. πŸŽ€
  • owner β€” the original owner, exactly as passed to the lchown(2) system call.
  • group β€” the original group, exactly as passed to the lchown(2) system call.

Returns:

the message explaining the error. πŸ’Œ but listen β€” this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. it will get overwritten by the next call to any libexplain function that shares this buffer, including other threads. so don't be clinging to it like it's yours, because it is NOT. 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. it's giving "communal apartment" energy and not in a cute way. πŸ’€

πŸ¦‹ explain_errno_lchown πŸ¦‹

const char *explain_errno_lchown(int errnum, const char *pathname, int owner, int group);

the explain_errno_lchown function is used to obtain an explanation of an error returned by the lchown(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. iconic behaviour, honestly. 🌈

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

if (lchown(pathname, owner, group) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_lchown(err,
        pathname, owner, group));
    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. so like, grab it early or it's gone, fr fr. πŸ™ˆ
  • pathname β€” the original pathname, exactly as passed to the lchown(2) system call.
  • owner β€” the original owner, exactly as passed to the lchown(2) system call.
  • group β€” the original group, exactly as passed to the lchown(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 communal-buffer situation, bestie, we don't make the rules. πŸ’€

πŸŽ€ explain_message_lchown πŸŽ€

void explain_message_lchown(char *message, int message_size, const char *pathname, int owner, int group);

the explain_message_lchown function may be used to obtain an explanation of an error returned by the lchown(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. she's thorough. she's that girl. πŸ‘‘

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 (lchown(pathname, owner, group) < 0)
{
    char message[3000];
    explain_message_lchown(message, sizeof(message),
        pathname, owner, group);
    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. 🫢 the glow-up we've been waiting for!!
  • 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 lchown(2) system call.
  • owner β€” the original owner, exactly as passed to the lchown(2) system call.
  • group β€” the original group, exactly as passed to the lchown(2) system call.

🧚 explain_message_errno_lchown 🧚

void explain_message_errno_lchown(char *message, int message_size, int errnum, const char *pathname, int owner, int group);

the explain_message_errno_lchown function may be used to obtain an explanation of an error returned by the lchown(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. the whole package. the moment. ⭐

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

if (lchown(pathname, owner, group) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_lchown(message, sizeof(message), err,
        pathname, owner, group);
    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. 😭 grab it fast!!
  • pathname β€” the original pathname, exactly as passed to the lchown(2) system call.
  • owner β€” the original owner, exactly as passed to the lchown(2) system call.
  • group β€” the original group, exactly as passed to the lchown(2) system call.

✨ SEE ALSO ✨


libexplain version 1.4 Copyright (C) 2008 Peter Miller


and that's the whole page, bestie!! πŸŽ€ you just read explain_lchown(3) from libexplain version 1.4, with Copyright (C) 2008 Peter Miller riding shotgun. go forth and decode those errors like the main character you are. πŸ’…βœ¨πŸ‘‘

πŸ“¦ where this page comes from