explain_dup(3)
π¦ explain_dup(3) β the manual page, but make it make sense π¦
okay so bestie, this is explain_dup from the Library Functions Manual (that's the section 3 part, iykyk) β and no cap, this one is a lifesaver when dup(2) is acting up and you're just sitting there like "why π". Let's get into it. π
β¨ NAME β¨
explain_dup β literally here to explain your dup(2) errors, bestie π
πΈ SYNOPSIS πΈ
#include <libexplain/dup.h>
const char *explain_dup(int fildes);
const char *explain_errno_dup(int errnum, int fildes);
void explain_message_dup(char *message, int message_size, int fildes);
void explain_message_errno_dup(char *message, int message_size, int errnum, int fildes);
π DESCRIPTION π
So these functions? They're the ones you call when you want an actual explanation for the errors that dup(2) throws back at you. Not just a vibe, an explanation. π«Ά
π explain_dup
const char *explain_dup(int fildes);
The explain_dup function is your go-to for getting an explanation of an error that came back from the dup(2) system call. Like, the bare minimum it'll give you is the value of strerror(errno) β but honestly? Usually it does so much better than that and tells you the actual underlying cause in way more detail. obsessed. β¨
The errno global variable is what it reads to get the error value it's gonna decode.
This function is meant to be used in a way that looks like this:
if (dup(fildes) < 0)
{
fprintf(stderr, "%s\n", explain_dup(fildes));
exit(EXIT_FAILURE);
}
fildesβ the originalfildes, exactly as you passed it to thedup(2)system call. no edits, no remixing, keep it verbatim bestie.
Returns: The message explaining the error. Heads up though β this message buffer is shared by all the libexplain functions that don't take a buffer in their argument list. So it's gonna get overwritten by the next call to any libexplain function that shares that buffer, including calls happening in other threads. π
Note: this function is not thread safe, because it shares one return buffer across all threads, and honestly a whole bunch of other functions in this library do the same thing. π
π§ explain_errno_dup
const char *explain_errno_dup(int errnum, int fildes);
The explain_errno_dup function is the one you reach for when you want an explanation of an error returned by the dup(2) system call. The least the message will contain is the value of strerror(errnum), but usually it goes way harder and points at the underlying cause in more detail. π₯
This function is intended to be used in a fashion similar to the following example:
if (dup(fildes) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_dup(err, fildes));
exit(EXIT_FAILURE);
}
errnumβ the error value that's gonna get decoded, usually grabbed from theerrnoglobal variable right before you call this function. This matters if you need to run any code between the system call you're explaining and this function, because a lot of libc functions will straight up change the value oferrnoon you. πfildesβ the originalfildes, exactly as passed to thedup(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. It will be overwritten by the next call to any libexplain function sharing this buffer, including from other threads. π
Note: not thread safe either, for the exact same shared-return-buffer reason, and many other functions in this library share that trait. π
π explain_message_dup
void explain_message_dup(char *message, int message_size, int fildes);
The explain_message_dup function may be used to obtain an explanation of an error returned by the dup(2) system call. The least the message will contain is the value of strerror(errno), but usually it does much better and shows you 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 (dup(fildes) < 0)
{
char message[3000];
explain_message_dup(message, sizeof(message), fildes);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
messageβ the location where the returned message gets stored. And here's the slay part: if you supply a suitable message return buffer, this function is thread safe. πmessage_sizeβ the size in bytes of the location where the returned message gets stored.fildesβ the originalfildes, exactly as passed to thedup(2)system call.
π explain_message_errno_dup
void explain_message_errno_dup(char *message, int message_size, int errnum, int fildes);
The explain_message_errno_dup function may be used to obtain an explanation of an error returned by the dup(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. β¨
This function is intended to be used in a fashion similar to the following example:
if (dup(fildes) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_dup(message, sizeof(message), err, fildes);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
messageβ the location where the returned message gets stored. If a suitable message return buffer is supplied, this function is thread safe. π«Άmessage_sizeβ the size in bytes of the location where the returned message gets stored.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. πfildesβ the originalfildes, exactly as passed to thedup(2)system call.
π₯ SEE ALSO π₯
dup(2)β duplicate a file descriptorexplain_dup_or_die(3)β duplicate a file descriptor and report errors
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2008 Peter Miller
okay that's the whole page bestie, go forth and debug with main character energy π β¨
this was explain_dup(3) from the Library Functions Manual, brought to you by libexplain version 1.4, copyright Copyright (C) 2008 Peter Miller β mwah, take care of her ππ
π¦ 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