explain_access(3)
πΈ NAME πΈ
explain_access β bestie, this whole page is about explaining the errors that come back from the access(2) system call. That's the entire vibe. π
And hi, yes, this is the explain_access(3) page from the Library Functions Manual, and we are reading it together, all of it, no skipping. π«Ά
β¨ SYNOPSIS β¨
#include <libexplain/access.h>
const char *explain_access(const char *pathname, int mode);
const char *explain_errno_access(int errnum, const char *pathname, int mode);
void explain_message_access(char *message, int message_size, const char *pathname, int mode);
void explain_message_errno_access(char *message, int message_size, int errnum, const char *pathname, int mode);
π DESCRIPTION π
So these four functions? They're how you get explanations for access(2) errors. Four of them. Each one is slightly different and the differences genuinely matter, so we're doing them one at a time. π§
π explain_access π
const char *explain_access(const char *pathname, int mode);
The explain_access function is how you get an explanation of an error returned by the access(2) system call. The least your message is gonna contain is the value of strerror(errno) β but usually it does way better than that and points at the actual underlying cause in way more detail. Obsessed with that, honestly.
It reads the errno global variable to get the error value it's decoding.
It's meant to be used in a fashion similar to this example, fr fr:
int fd = access(pathname, mode);
if (fd < 0)
{
fprintf(stderr, "%s0, explain_access(pathname, mode));
exit(EXIT_FAILURE);
}
pathnameβ the originalpathname, exactly as passed to theaccess(2)system call. No edits, no glow-up.modeβ the originalmode, exactly as passed to theaccess(2)system call. Same energy.
Returns: the message explaining the error. β οΈ But heads up β this message buffer is shared by all the libexplain functions that don't supply a buffer in their own argument list. So the very next call to any libexplain function that shares this buffer will overwrite it, other threads included. π
Note: this function is not thread safe, because it shares a return buffer across all threads β and honestly, a lot of other functions in this library do the exact same thing.
π explain_errno_access π
const char *explain_errno_access(int errnum, const char *pathname, int mode);
The explain_errno_access function is how you get an explanation of an error returned by the access(2) system call. The least your message is gonna contain is the value of strerror(errnum) β but usually it does much better and shows you the underlying cause in more detail. π
It's meant to be used in a fashion similar to this example:
int fd = access(pathname, mode);
if (fd < 0)
{
int err = errno;
fprintf(stderr, "%s0, explain_errno_access(err, pathname, mode));
exit(EXIT_FAILURE);
}
errnumβ the error value to be decoded, usually grabbed from theerrnoglobal variable right before you call this function. And you do need to do that if you're gonna run any code between the system call you're explaining and this function, because so many libc functions will mess with the value oferrno. Not a vibe. πpathnameβ the originalpathname, exactly as passed to theaccess(2)system call.modeβ the originalmode, exactly as passed to theaccess(2)system call.
Returns: the message explaining the error. Again β this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. The next call to any libexplain function sharing this buffer overwrites it, other threads included. π
Note: this function is not thread safe, because it shares a return buffer across all threads β plus many other functions in this library.
π explain_message_access π
void explain_message_access(char *message, int message_size, const char *pathname, int mode);
The explain_message_access function is how you get an explanation of an error returned by the access(2) system call. The least your message is gonna contain is the value of strerror(errno) β but usually it does much better and tells you the underlying cause in more detail. β¨
The errno global variable is used to obtain the error value being decoded.
It's meant to be used in a fashion similar to this example:
int fd = access(pathname, mode);
if (fd < 0)
{
char message[3000];
explain_message_access(message, sizeof(message), pathname, mode);
fprintf(stderr, "%s0, message);
exit(EXIT_FAILURE);
}
messageβ where you want the returned message stored. And 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 goes.pathnameβ the originalpathname, exactly as passed to theaccess(2)system call.modeβ the originalmode, exactly as passed to theaccess(2)system call.
π explain_message_errno_access π
void explain_message_errno_access(char *message, int message_size, int errnum, const char *pathname, int mode);
The explain_message_errno_access function is how you get an explanation of an error returned by the access(2) system call. The least your message is gonna contain is the value of strerror(errnum) β but usually it does much better and shows the underlying cause in more detail. π₯
It's meant to be used in a fashion similar to this example:
int fd = access(pathname, mode);
if (fd < 0)
{
int err = errno;
char message[3000];
explain_message_errno_access(message, sizeof(message), err, pathname, mode);
fprintf(stderr, "%s0, message);
exit(EXIT_FAILURE);
}
messageβ where you want the returned message stored. Because a message return buffer has been supplied, this function is thread safe. Periodt. πmessage_sizeβ the size in bytes of the location where the returned message goes.errnumβ the error value to be decoded, usually grabbed from theerrnoglobal variable right before this function is called. Necessary if you need to call any code between the system call being explained and this function, because lots of libc functions will alter the value oferrno. π€pathnameβ the originalpathname, exactly as passed to theaccess(2)system call.modeβ the originalmode, exactly as passed to theaccess(2)system call.
π COPYRIGHT π
libexplainversion1.4- Copyright (C) 2008 Peter Miller
π AUTHOR π
Written by Peter Miller <pmiller@opensource.org.au>
And that's the whole explain_access(3) page from the Library Functions Manual, top to bottom, every last crumb. π Go explain your errors, bestie, you've got this π
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2008, 2009, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms