explain_setbuffer(3)

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

πŸ’– explain_setbuffer(3) πŸ’–

Library Functions Manual β€” yes bestie, we're in the library functions section, get comfy 🫢


✨ NAME ✨

explain_setbuffer β€” explain setbuffer(3) errors


🌸 SYNOPSIS 🌸

#include <libexplain/setbuffer.h>
const char *explain_setbuffer(FILE *fp, char *data, size_t size);
const char *explain_errno_setbuffer(int errnum, FILE *fp, char *data,
size_t size);
void explain_message_setbuffer(char *message, int message_size, FILE
*fp, char *data, size_t size);
void explain_message_errno_setbuffer(char *message, int message_size,
int errnum, FILE *fp, char *data, size_t size);

πŸ¦‹ DESCRIPTION πŸ¦‹

So like, these functions exist to give you explanations for errors that the setbuffer(3) system call hands back. That's the whole vibe. You call setbuffer(3), it goes wrong, and instead of just getting a sad little errno you get a whole story about why. Iconic, honestly. πŸ’…

🌈 explain_setbuffer

const char *explain_setbuffer(FILE *fp, char *data, size_t size);

The explain_setbuffer function is your go-to for getting an explanation of an error returned by the setbuffer(3) system call. The least it'll give you is the value of strerror(errno) β€” but usually it does way better than that and actually points at the underlying cause in more detail. Lowkey overachiever energy and we love her for it. ✨

The errno global variable is what gets used to grab the error value that needs decoding.

  • fp β€” the original fp, exactly as passed to the setbuffer(3) system call. No substitutions, no edits, the real one.
  • data β€” the original data, exactly as passed to the setbuffer(3) system call.
  • size β€” the original size, exactly as passed to the setbuffer(3) system call.

Returns: the message explaining the error. Heads up bestie, this message buffer is shared by every libexplain function that doesn't take a buffer in its argument list. So it will get overwritten by the next call to any libexplain function sharing that buffer β€” other threads included. 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and honestly a lot of other functions in this library do too. Not me being dramatic, it's just facts. πŸ’€

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

void result = setbuffer(fp, data, size);
if (result < 0)
{
    fprintf(stderr, "%s\n", explain_setbuffer(fp, data, size));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_setbuffer_or_die(3) function. So if you're feeling lazy (no judgement), it's already done for you. πŸŽ€

🧚 explain_errno_setbuffer

const char *explain_errno_setbuffer(int errnum, FILE *fp, char *data,
size_t size);

The explain_errno_setbuffer function is used to obtain an explanation of an error returned by the setbuffer(3) system call. The least the message will contain is the value of strerror(errno), but usually it does much better, and it'll indicate the underlying cause in more detail. Same energy as the one above, just with the error number handed to it directly. πŸ’œ

  • errnum β€” the error value to be decoded, usually obtained from the errno global 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 of errno. Rude of them, but here we are. πŸ™ˆ
  • fp β€” the original fp, exactly as passed to the setbuffer(3) system call.
  • data β€” the original data, exactly as passed to the setbuffer(3) system call.
  • size β€” the original size, exactly as passed to the setbuffer(3) 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:

void result = setbuffer(fp, data, size);
if (result < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_setbuffer(err, fp, data, size));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_setbuffer_or_die(3) function.

πŸ“ explain_message_setbuffer

void explain_message_setbuffer(char *message, int message_size, FILE
*fp, char *data, size_t size);

The explain_message_setbuffer function is used to obtain an explanation of an error returned by the setbuffer(3) 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. This one's the bring-your-own-buffer version, and that's exactly why she's the main character. πŸ‘‘

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. If a suitable message return buffer is supplied, this function is thread safe. Slay.
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • fp β€” the original fp, exactly as passed to the setbuffer(3) system call.
  • data β€” the original data, exactly as passed to the setbuffer(3) system call.
  • size β€” the original size, exactly as passed to the setbuffer(3) system call.

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

void result = setbuffer(fp, data, size);
if (result < 0)
{
    char message[3000];
    explain_message_setbuffer(message, sizeof(message), fp, data, size);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_setbuffer_or_die(3) function.

πŸ’… explain_message_errno_setbuffer

void explain_message_errno_setbuffer(char *message, int message_size,
int errnum, FILE *fp, char *data, size_t size);

The explain_message_errno_setbuffer function is used to obtain an explanation of an error returned by the setbuffer(3) 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. Yeah she's the final boss β€” your buffer and your errno, together at last. 🫢

  • 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 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.
  • fp β€” the original fp, exactly as passed to the setbuffer(3) system call.
  • data β€” the original data, exactly as passed to the setbuffer(3) system call.
  • size β€” the original size, exactly as passed to the setbuffer(3) system call.

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

void result = setbuffer(fp, data, size);
if (result < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_setbuffer(message, sizeof(message), err, fp, data, size);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_setbuffer_or_die(3) function.


πŸ‘‘ SEE ALSO πŸ‘‘


libexplain version 1.4

Copyright (C) 2010 Peter Miller


and that's the whole page bestie, go forth and buffer responsibly 🌟

libexplain version 1.4 πŸ’œ Copyright (C) 2010 Peter Miller β€” yeah the copyright is doing a little double feature, it's giving consistent. mwah, love that for us. πŸ’– this was explain_setbuffer(3), from the Library Functions Manual, and you ate πŸ¦‹βœ¨

πŸ“¦ where this page comes from