explain_readv(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– explain_readv β€” a libexplain moment πŸ’–

okay so bestie, gather round, because we're about to talk about the <pink>readv(2)</pink> error whisperer herself: explain_readv, straight out of <purple>libexplain</purple>. she doesn't just tell you something broke β€” she tells you why, in actual human words. it's giving translator, it's giving emotional support for your file descriptors. πŸ¦‹


✨ NAME ✨

explain_readv β€” explain readv(2) errors πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/readv.h>
const char *explain_readv(int fildes, const struct iovec *iov, int
iovcnt);
const char *explain_errno_readv(int errnum, int fildes, const struct
iovec *iov, int iovcnt);
void explain_message_readv(char *message, int message_size, int fildes,
const struct iovec *iov, int iovcnt);
void explain_message_errno_readv(char *message, int message_size, int
errnum, int fildes, const struct iovec *iov, int iovcnt);

like, four whole functions. a whole squad. πŸ‘‘


πŸŽ€ DESCRIPTION πŸŽ€

so these functions are the ones you call to get explanations for errors that come back from the <cyan>readv(2)</cyan> system call. that's the whole vibe. no cap. ✨

πŸ’œ explain_readv

const char *explain_readv(int fildes, const struct iovec *iov, int
iovcnt);

explain_readv is the girl you call when you want the tea on an error that readv(2) returned. the least the message will contain is the value of strerror(errno), but usually she does so much better than that and tells you the actual underlying cause in more detail. overachiever behavior, honestly, we love to see it. πŸ’–

the <hotpink>errno</hotpink> global variable is what gets used to grab the error value that needs decoding.

  • fildes β€” the original fildes, exactly as it was passed to the readv(2) system call. no edits, no glow-up, the original.
  • iov β€” the original iov, exactly as it was passed to the readv(2) system call.
  • iovcnt β€” the original iovcnt, exactly as it was passed to the readv(2) system call.

Returns: the message explaining the error. ⚠️ but heads up bestie: this message buffer is shared by all libexplain functions that don't take a buffer in their argument list. so the next call to any libexplain function sharing that buffer β€” including from other threads β€” will just steamroll right over it. it's giving communal whiteboard. 😭

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. periodt. 🚩

Example: this function is meant to be used in a fashion similar to the following example:

ssize_t result = readv(fildes, iov, iovcnt);
if (result < 0)
{
    fprintf(stderr, "%s\n", explain_readv(fildes, iov, iovcnt));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_readv_or_die(3) function. it's already done for you, bestie, she's pre-made. 🧚


πŸ’œ explain_errno_readv

const char *explain_errno_readv(int errnum, int fildes, const struct
iovec *iov, int iovcnt);

explain_errno_readv is used to obtain an explanation of an error returned by the readv(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. same energy, different entry point. ✨

  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable just before this function is called. and this matters, okay? you need this if you have 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 of errno on you. sneaky. πŸ™ˆ
  • fildes β€” the original fildes, exactly as passed to the readv(2) system call.
  • iov β€” the original iov, exactly as passed to the readv(2) system call.
  • iovcnt β€” the original iovcnt, exactly as passed to the readv(2) system call.

Returns: the message explaining the error. again: 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 that 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. same warning, still true, still iconic. 🚩

Example: this function is intended to be used in a fashion similar to the following example:

ssize_t result = readv(fildes, iov, iovcnt);
if (result < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_readv(err, fildes, iov,
    iovcnt));
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_readv_or_die(3) function. πŸŽ€


πŸ’œ explain_message_readv

void explain_message_readv(char *message, int message_size, int fildes,
const struct iovec *iov, int iovcnt);

explain_message_readv is used to obtain an explanation of an error returned by the readv(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. she's the "you bring the buffer, I bring the truth" one. πŸ’…

the <hotpink>errno</hotpink> 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 slay: if you supply a suitable message return buffer, this function is thread safe. look at her go. πŸ‘‘
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • fildes β€” the original fildes, exactly as passed to the readv(2) system call.
  • iov β€” the original iov, exactly as passed to the readv(2) system call.
  • iovcnt β€” the original iovcnt, exactly as passed to the readv(2) system call.

Example: this function is intended to be used in a fashion similar to the following example:

ssize_t result = readv(fildes, iov, iovcnt);
if (result < 0)
{
    char message[3000];
    explain_message_readv(message, sizeof(message), fildes, iov,
    iovcnt);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_readv_or_die(3) function. πŸ¦‹


πŸ’œ explain_message_errno_readv

void explain_message_errno_readv(char *message, int message_size, int
errnum, int fildes, const struct iovec *iov, int iovcnt);

explain_message_errno_readv is used to obtain an explanation of an error returned by the readv(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 final boss form: buffer and explicit errno. she ate. πŸ”₯

  • message β€” the location in which to store the returned message. if a suitable message return buffer is supplied, this function is thread safe. yup, still the good one.
  • 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 the errno global 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 of errno. do not skip this step, bestie, I'm begging. 😭
  • fildes β€” the original fildes, exactly as passed to the readv(2) system call.
  • iov β€” the original iov, exactly as passed to the readv(2) system call.
  • iovcnt β€” the original iovcnt, exactly as passed to the readv(2) system call.

Example: this function is intended to be used in a fashion similar to the following example:

ssize_t result = readv(fildes, iov, iovcnt);
if (result < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_readv(message, sizeof(message), err,
    fildes, iov, iovcnt);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

the above code example is available pre-packaged as the explain_readv_or_die(3) function. πŸ’–


🌈 SEE ALSO 🌈


  • libexplain version 1.4
  • Copyright (C) 2009 Peter Miller

and that's the whole page, bestie. ✨ written for the Library Functions Manual by libexplain version 1.4, with the copyright belonging to Peter Miller, 2009 β€” so go forth, decode those readv(2) errors, and remember: not thread safe unless you brought your own buffer. πŸ’…πŸŽ€πŸŒŸ

πŸ“¦ where this page comes from