explain_poll(3)
π explain_poll(3) β the group chat guide π
okay bestie, sit DOWN, because we're about to make friends with explain_poll(3), a little library function from the Library Functions Manual that turns your cursed poll(2) errors into actual sentences. it's giving "therapist but for errno" and honestly? we're obsessed. π«Ά
β¨ NAME β¨
explain_poll β explain poll(2) errors π
β¨ SYNOPSIS β¨
#include <libexplain/poll.h>
const char *explain_poll(struct pollfd *fds, int nfds, int timeout);
const char *explain_errno_poll(int errnum, struct pollfd *fds, int nfds,
int timeout);
void explain_message_poll(char *message, int message_size, struct pollfd
*fds, int nfds, int timeout);
void explain_message_errno_poll(char *message, int message_size, int
errnum, struct pollfd *fds, int nfds, int timeout);
πΈ DESCRIPTION πΈ
so basically, these functions are your lil translators β¨ they hand you explanations for errors that come back from the poll(2) system call. no more staring at a cryptic number like it personally wronged you. π
π explain_poll
const char *explain_poll(struct pollfd *fds, int nfds, int timeout);
the explain_poll function is how you get an explanation of an error that poll(2) threw back at you. the bare minimum the message will contain is the value of strerror(errno), but usually it does so much better than that and tells you the actual underlying cause in more detail. it's giving detective energy. π
the errno global variable is what gets used to obtain the error value that's gonna be decoded. she reads your mind (well, your errno).
fdsβ the originalfds, exactly as passed to thepoll(2)system call. we do not touch it, we do not improve it, we just report on it. periodt.nfdsβ the originalnfds, exactly as passed to thepoll(2)system call.timeoutβ the originaltimeout, exactly as passed to thepoll(2)system call.
Returns: the message explaining the error. β οΈ heads up bestie, this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. that means it will get 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 so do many other functions in this library. no cap.
Example: this function is intended to be used in a fashion similar to the following example:
int result = poll(fds, nfds, timeout);
if (result < 0)
{
fprintf(stderr, "%s\n", explain_poll(fds, nfds, timeout));
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_poll_or_die(3) function. so if you're feeling lazy (valid), that's your girl. π
π¦ explain_errno_poll
const char *explain_errno_poll(int errnum, struct pollfd *fds, int nfds,
int timeout);
the explain_errno_poll function is used to obtain an explanation of an error returned by the poll(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. β¨
errnumβ the error value to be decoded, usually obtained from theerrnoglobal variable just before this function is called. π¨ this one matters: it's 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. like, they'll just change it on you. rude.fdsβ the originalfds, exactly as passed to thepoll(2)system call.nfdsβ the originalnfds, exactly as passed to thepoll(2)system call.timeoutβ the originaltimeout, exactly as passed to thepoll(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.
Example: this function is intended to be used in a fashion similar to the following example:
int result = poll(fds, nfds, timeout);
if (result < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_poll(err, fds, nfds,
timeout));
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_poll_or_die(3) function. π
π§ explain_message_poll
void explain_message_poll(char *message, int message_size, struct pollfd
*fds, int nfds, int timeout);
the explain_message_poll function is used to obtain an explanation of an error returned by the poll(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. π
the errno global variable will be used to obtain the error value to be decoded.
messageβ the location in which to store the returned message. π and here's the glow-up: if a suitable message return buffer is supplied, this function is thread safe. she did that.message_sizeβ the size in bytes of the location in which to store the returned message.fdsβ the originalfds, exactly as passed to thepoll(2)system call.nfdsβ the originalnfds, exactly as passed to thepoll(2)system call.timeoutβ the originaltimeout, exactly as passed to thepoll(2)system call.
Example: this function is intended to be used in a fashion similar to the following example:
int result = poll(fds, nfds, timeout);
if (result < 0)
{
char message[3000];
explain_message_poll(message, sizeof(message), fds, nfds,
timeout);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_poll_or_die(3) function. π
π explain_message_errno_poll
void explain_message_errno_poll(char *message, int message_size, int
errnum, struct pollfd *fds, int nfds, int timeout);
the explain_message_errno_poll function is used to obtain an explanation of an error returned by the poll(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. π₯
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 keep doing it. πfdsβ the originalfds, exactly as passed to thepoll(2)system call.nfdsβ the originalnfds, exactly as passed to thepoll(2)system call.timeoutβ the originaltimeout, exactly as passed to thepoll(2)system call.
Example: this function is intended to be used in a fashion similar to the following example:
int result = poll(fds, nfds, timeout);
if (result < 0)
{
int err = errno;
char message[3000];
explain_message_errno_poll(message, sizeof(message), err,
fds, nfds, timeout);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
the above code example is available pre-packaged as the explain_poll_or_die(3) function. π
π SEE ALSO π
poll(2)β wait for some event on a file descriptorexplain_poll_or_die(3)β wait for some event on a file descriptor and report errors
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2010 Peter Miller
okay that's the whole page bestie, you ate that π
β¨ thanks for reading, mwah, go forth and decode your errnos like the main character you are π¦πΈπ β explain_poll(3), signing off, Library Functions Manual energy only, iykyk π
π¦ 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) 2010, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms