explain_ioctl(3)
β¨ explain_ioctl β¨
okay bestie, welcome to explain_ioctl from the libexplain manual, section 3 (library functions, we're fancy like that π
). short version: this lil family of functions takes your busted ioctl(2) call and turns the error into a whole explanation, not just a sad little number. it's giving "translator for your syscall trauma". let's get into it π«Ά
πΈ NAME πΈ
explain_ioctl β explain ioctl(2) errors. that's the whole vibe. you called ioctl, it said no, and now you want to know why. this is the why. π
β¨ SYNOPSIS β¨
#include <libexplain/ioctl.h>
const char *explain_ioctl(int fildes, int request, void *data);
const char *explain_errno_ioctl(int errnum, int fildes, int request,
void *data);
void explain_message_ioctl(char *message, int message_size, int fildes,
int request, void *data);
void explain_message_errno_ioctl(char *message, int message_size, int
errnum, int fildes, int request, void *data);
four functions, four flavors of "let me explain". pick your fighter π
π DESCRIPTION π
so basically, these functions are how you get explanations for errors handed back to you by the ioctl(2) system call. no cap. that's the entire job description.
π¦ explain_ioctl
const char *explain_ioctl(int fildes, int request, void *data);
the explain_ioctl function is your go-to for getting an explanation of an error returned by the ioctl(2) system call. the least the message is ever gonna contain is the value of strerror(errno) β but usually it does so much better than that and tells you the actual underlying cause in way more detail. it's the difference between "something broke" and "bestie here's exactly what broke and why" π
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 this example:
int result = ioctl(fildes, request, data);
if (result < 0)
{
fprintf(stderr, "%s\n", explain_ioctl(fildes, request, data));
exit(EXIT_FAILURE);
}
that code example above? it's available preβpackaged as the explain_ioctl_or_die(3) function. yes, the name is iconic, no, i did not choose it.
fildesβ the originalfildes, exactly as passed to theioctl(2)system call. don't get cute with it, pass it as-is.requestβ the originalrequest, exactly as passed to theioctl(2)system call. same energy.dataβ the originaldata, exactly as passed to theioctl(2)system call. keep it verbatim, bestie.
Returns: the message explaining the error. 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 that shares this buffer, including calls from other threads. so likeβ¦ don't hold onto it, it's not yours, it's everybody's π
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. if you're threading, you've been warned π
π explain_errno_ioctl
const char *explain_errno_ioctl(int errnum, int fildes, int request,
void *data);
the explain_errno_ioctl function gets you an explanation of an error returned by the ioctl(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 much more detail. slay.
this function is intended to be used in a fashion similar to this example:
if (ioctl(fildes, request, data) < 0)
{
int err = errno;
fprintf(stderr, "%s\n",
explain_errno_ioctl(err, fildes, request, data));
exit(EXIT_FAILURE);
}
and yep, this code example is available preβpackaged as the explain_ioctl_or_die(3) function too. β¨
errnumβ the error value to be decoded, usually grabbed from theerrnoglobal variable right before this function is called. this is necessary if you need to call any code between the system call you're explaining and this function, because a lot of libc functions will alter the value oferrno. so save it first, fr fr.fildesβ the originalfildes, exactly as passed to theioctl(2)system call.requestβ the originalrequest, exactly as passed to theioctl(2)system call.dataβ the originaldata, exactly as passed to theioctl(2)system call.
Returns: the message explaining the error. this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list, and it'll get overwritten by the next call to any libexplain function sharing this buffer β other threads included. the way it does not belong to you π
Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library do the same.
π explain_message_ioctl
void explain_message_ioctl(char *message, int message_size, int fildes,
int request, void *data);
the explain_message_ioctl function may be used to obtain an explanation of an error returned by the ioctl(2) system call. the least the message will contain is the value of strerror(errno), but usually it does much better and indicates the underlying cause in more detail. obsessed.
the errno global variable is used to obtain the error value that needs decoding.
this function is intended to be used in a fashion similar to this example:
if (ioctl(fildes, request, data) < 0)
{
char message[3000];
explain_message_ioctl(message, sizeof(message), fildes, request, data);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
and yes, this code example is available preβpackaged as the explain_ioctl_or_die(3) function. π
messageβ the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. look at that, growth.message_sizeβ the size in bytes of the location in which to store the returned message.fildesβ the originalfildes, exactly as passed to theioctl(2)system call.requestβ the originalrequest, exactly as passed to theioctl(2)system call.dataβ the originaldata, exactly as passed to theioctl(2)system call.
β explain_message_errno_ioctl
void explain_message_errno_ioctl(char *message, int message_size, int
errnum, int fildes, int request, void *data);
the explain_message_errno_ioctl function may be used to obtain an explanation of an error returned by the ioctl(2) system call. the least the message will contain is the value of strerror(errnum), but usually it does much better and gives you the underlying cause in more detail. it ate, honestly.
this function is intended to be used in a fashion similar to this example:
if (ioctl(fildes, request, data) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_ioctl(message, sizeof(message), err,
fildes, request, data);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
and guess what β this code example is available preβpackaged as the explain_ioctl_or_die(3) function. β¨
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. so like, grab it early, babe.fildesβ the originalfildes, exactly as passed to theioctl(2)system call.requestβ the originalrequest, exactly as passed to theioctl(2)system call.dataβ the originaldata, exactly as passed to theioctl(2)system call.
π SEE ALSO π
ioctl(2)β control deviceexplain_ioctl_or_die(3)β control device and report errors
iykyk. these two are the besties you go read next. π«Ά
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2008 Peter Miller
and that's the whole page, bestie π libexplain version 1.4, Copyright (C) 2008 Peter Miller, and this little manual page goes by explain_ioctl(3) β main character energy, no notes, periodt πβ¨
π¦ 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-2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms