explain_select(3)
π explain_select(3) β Library Functions Manual π
okay bestie, so you know how select(2) can just randomly fail on you and leave you staring at errno like ποΈπποΈ? yeah. this page is from the Library Functions Manual and it's all about the libexplain glow-up that turns that cryptic error into an actual explanation. sit down, hydrate, let's go π
β¨ NAME β¨
explain_select β explain select(2) errors π
πΈ SYNOPSIS πΈ
#include <sys/select.h>
#include <libexplain/select.h>
const char *explain_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
const char *explain_errno_select(int errnum, int nfds, fd_set *readfds,
fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
void explain_message_select(char *message, int message_size, int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval
*timeout);
void explain_message_errno_select(char *message, int message_size, int
errnum, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);
π¦ DESCRIPTION π¦
so these functions? they're your little translators π. you use them to get explanations for errors that the select(2) system call hands back to you. no more raw errno staring contests, no cap.
π explain_select
const char *explain_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
the explain_select function is the moment β¨ it gets you an explanation of an error returned by the select(2) system call. the absolute bare minimum the message will contain is the value of strerror(errno), but usually it does so much better and points at the underlying cause in more detail. it's giving detective energy π
the errno global variable is what gets 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 (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
fprintf(stderr, "%s\n", explain_select(nfds,
readfds, writefds, exceptfds, timeout));
exit(EXIT_FAILURE);
}
nfdsβ the originalnfds, exactly as passed to theselect(2)system call.readfdsβ the originalreadfds, exactly as passed to theselect(2)system call.writefdsβ the originalwritefds, exactly as passed to theselect(2)system call.exceptfdsβ the originalexceptfds, exactly as passed to theselect(2)system call.timeoutβ the originaltimeout, exactly as passed to theselect(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. it will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. so like. screenshot it or copy it, don't just vibe with the pointer π
Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. fr fr, be careful.
π« explain_errno_select
const char *explain_errno_select(int errnum, int nfds, fd_set *readfds,
fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
the explain_errno_select function gets you an explanation of an error returned by the select(2) system call. minimum content = the value of strerror(errnum), but usually it goes way harder and indicates the underlying cause in more detail π«Ά
this function is intended to be used in a fashion similar to the following example:
if (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_select(err,
nfds, readfds, writefds, exceptfds, timeout));
exit(EXIT_FAILURE);
}
errnumβ the error value to be decoded, usually obtained from theerrnoglobal 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 oferrno. yes literally, they will snatch it from you πnfdsβ the originalnfds, exactly as passed to theselect(2)system call.readfdsβ the originalreadfds, exactly as passed to theselect(2)system call.writefdsβ the originalwritefds, exactly as passed to theselect(2)system call.exceptfdsβ the originalexceptfds, exactly as passed to theselect(2)system call.timeoutβ the originaltimeout, exactly as passed to theselect(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.
π explain_message_select
void explain_message_select(char *message, int message_size, int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval
*timeout);
the explain_message_select function may be used to obtain an explanation of an error returned by the select(2) system call. least it'll 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 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 (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
char message[3000];
explain_message_select(message, sizeof(message),
nfds, readfds, writefds, exceptfds, timeout);
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 π that's the whole point, bestie.message_sizeβ the size in bytes of the location in which to store the returned message.nfdsβ the originalnfds, exactly as passed to theselect(2)system call.readfdsβ the originalreadfds, exactly as passed to theselect(2)system call.writefdsβ the originalwritefds, exactly as passed to theselect(2)system call.exceptfdsβ the originalexceptfds, exactly as passed to theselect(2)system call.timeoutβ the originaltimeout, exactly as passed to theselect(2)system call.
π§ explain_message_errno_select
void explain_message_errno_select(char *message, int message_size, int
errnum, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout);
the explain_message_errno_select function may be used to obtain an explanation of an error returned by the select(2) system call. least it'll contain is the value of strerror(errnum), but usually it does much better and indicates the underlying cause in more detail π
this function is intended to be used in a fashion similar to the following example:
if (select(nfds, readfds, writefds, exceptfds, timeout) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_select(message, sizeof(message), err,
nfds, readfds, writefds, exceptfds, timeout);
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 theerrnoglobal 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 oferrno. again. they WILL do it πnfdsβ the originalnfds, exactly as passed to theselect(2)system call.readfdsβ the originalreadfds, exactly as passed to theselect(2)system call.writefdsβ the originalwritefds, exactly as passed to theselect(2)system call.exceptfdsβ the originalexceptfds, exactly as passed to theselect(2)system call.timeoutβ the originaltimeout, exactly as passed to theselect(2)system call.
π SEE ALSO π
select(2)β blah blahexplain_select_or_die(3)β blah blah and report errors
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2008 Peter Miller
and that's the whole page bestie π«Ά go forth and decode your errnos, you absolute icon β this was explain_select(3) from the Library Functions Manual, brought to you by libexplain version 1.4, Copyright (C) 2008 Peter Miller β mwah, no notes ππ
π¦ 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