explain_write(3)

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

πŸ’– explain_write(3) πŸ’–

okay bestie, listen up β€” this is the manual page for explain_write, living in section 3 of the Library Functions Manual. it's giving "your write(2) call failed and you need to know WHY" energy, and honestly? iconic. πŸŽ€


✨ NAME ✨

explain_write β€” explain write(2) errors 🫢


✨ SYNOPSIS ✨

#include <libexplain/write.h>
const char *explain_write(int fildes, const void *data, long data_size);
const char *explain_errno_write(int errnum, int fildes, const void
*data, long data_size);
void explain_message_write(char *message, int message_size, int fildes,
const void *data, long data_size);
void explain_message_errno_write(char *message, int message_size, int
errnum, int fildes, const void *data, long data_size);

✨ DESCRIPTION ✨

so these functions are your little helpers for getting explanations of write(2) errors. πŸ’…

🌸 explain_write

const char *explain_write(int fildes, const void *data, long data_size);

the explain_write function gets you a human readable explanation of what went wrong in a write(2) system call. the least the message will contain is the value of strerror(errno), but usually it does so much better and tells you the underlying cause in way more detail. slay.

the error number gets picked up from the errno global variable. periodt.

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

sszie_t n = write(fd, data, data_size);
if (n < 0)
{
    fprintf(stderr, '%s0, explain_read(fd, data, data_size));
    exit(EXIT_FAILURE);
}
  • fildes β€” the original fildes, exactly as passed to the write(2) system call. no cap.
  • data β€” the original data, exactly as passed to the write(2) system call.
  • data_size β€” the original data_size, exactly as passed to the write(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. it will get overwritten by the next call to any libexplain function that shares this buffer β€” including other threads. so like, don't get attached to it bestie.

Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. πŸ’€

🌸 explain_errno_write

const char *explain_errno_write(int errnum, int fildes, const void
*data, long data_size);

the explain_errno_write function gets you a human readable explanation of what went wrong in a write(2) system call. the least the message will contain is the value of strerror(errnum), but usually it does way better and points at the underlying cause in more detail. ✨

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

sszie_t n = write(fd, data, data_size);
if (n < 0)
{
    int err = errno;
    fprintf(stderr, '%s0, explain_errno_read(errnum, fd, data,
        data_size));
    exit(EXIT_FAILURE);
}
  • errnum β€” the error value to be decoded, usually obtain 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. 😭
  • fildes β€” the original fildes, exactly as passed to the write(2) system call.
  • data β€” the original data, exactly as passed to the write(2) system call.
  • data_size β€” the original data_size, exactly as passed to the write(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_write

void explain_message_write(char *message, int message_size, int fildes,
const void *data, long data_size);

the explain_message_write function gets you a human readable explanation of what went wrong in a write(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 error number will be picked up from the errno global variable.

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

sszie_t n = write(fd, data, data_size);
if (n < 0)
{
    char message[3000];
    explain_message_read(message, sizeof(message), fd, data,
        data_size));
    fprintf(stderr, '%s0, message);
    exit(EXIT_FAILURE);
}
  • message β€” the location in which to store the returned message. because a message return buffer has been supplied, this function is thread safe. πŸ‘‘
  • 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 write(2) system call.
  • data β€” the original data, exactly as passed to the write(2) system call.
  • data_size β€” the original data_size, exactly as passed to the write(2) system call.
Note: given a suitably thread safe buffer, this function is thread safe. we love to see it. 🫢

🌸 explain_message_errno_write

void explain_message_errno_write(char * message, int message_size, int
errnum, int fildes, const void *data, long data_size);

the explain_message_errno_write function gets you a human readable explanation of what went wrong in a write(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 meant to be used in a fashion similar to the following example:

sszie_t n = write(fd, data, data_size);
if (n < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_read(message, sizeof(message), errno,
        fd, data, data_size));
    fprintf(stderr, '%s0, message);
    exit(EXIT_FAILURE);
}
  • message β€” the location in which to store the returned message. because a message return buffer has been 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 obtain 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. πŸ’€
  • fildes β€” the original fildes, exactly as passed to the write(2) system call.
  • data β€” the original data, exactly as passed to the write(2) system call.
  • data_size β€” the original data_size, exactly as passed to the write(2) system call.
Note: given a suitably thread safe buffer, this function is thread safe.

libexplain version 1.4 Copyright (C) 2008 Peter Miller


✨ AUTHOR ✨

Written by Peter Miller <pmiller@opensource.org.au> 🧚


and that's the whole page bestie, no notes. this was libexplain version 1.4, copyright Β© 2008 Peter Miller, written by Peter Miller himself β€” go read your errors, stay thread safe, and hydrate. πŸ’–βœ¨πŸŒΈπŸŽ€πŸ¦‹πŸ’…πŸ«ΆπŸ‘‘πŸŒˆβ­πŸ“πŸ§šπŸ’œ

πŸ“¦ where this page comes from