explain_putc(3)

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

πŸ’– explain_putc(3) β€” Library Functions Manual πŸ’–

okay bestie, so this is explain_putc from the Library Functions Manual, and it's literally just here to translate putc(3) errors from cryptic nonsense into actual sentences. you're gonna love her. 🫢


✨ NAME ✨

explain_putc β€” explain putc(3) errors


🌸 SYNOPSIS 🌸

#include <libexplain/putc.h>
const char *explain_putc(int c, FILE *fp);
const char *explain_errno_putc(int errnum, int c, FILE *fp);
void explain_message_putc(char *message, int message_size, int c, FILE *fp);
void explain_message_errno_putc(char *message, int message_size, int errnum, int c, FILE *fp);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the whole point of these functions: you use them to get actual explanations for errors that the putc(3) system call hands back to you. no more squinting at errno like πŸ‘οΈπŸ‘„πŸ‘οΈ. they tell you what's up.

πŸ’… explain_putc

const char *explain_putc(int c, FILE *fp);

the explain_putc function is what you call to get an explanation of an error that came back from the putc(3) system call. worst case scenario, the message contains the value of strerror(errno) β€” but usually it does way better than that and tells you the underlying cause in more detail. it ate, honestly. πŸ”₯

the errno global variable is the one that gets used to obtain the error value to be decoded.

this function is meant to be used in a fashion similar to this example, no cap:

if (putc(c, fp) == EOF)
{
    fprintf(stderr, "%s\n", explain_putc(c, fp));
    exit(EXIT_FAILURE);
}
  • c β€” the original c, exactly as passed to the putc(3) system call.
  • fp β€” the original fp, exactly as passed to the putc(3) system call.

Returns:

the message explaining the error. heads up bestie: this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. so it gets overwritten by the next call to any libexplain function that shares this buffer β€” including calls from 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 do the same thing. periodt.

πŸŽ€ explain_errno_putc

const char *explain_errno_putc(int errnum, int c, FILE *fp);

the explain_errno_putc function is what you call to get an explanation of an error that came back from the putc(3) system call. least it'll give you is the value of strerror(errnum), but usually it does soooo much better and shows you the underlying cause in more detail. iconic. ✨

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

if (putc(c, fp) == EOF)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_putc(err, c, fp));
    exit(EXIT_FAILURE);
}
  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right before this function gets called. you need this if you have to run any code between the system call you're explaining and this function, because so many libc functions will go and mess with the value of errno. like, rude.
  • c β€” the original c, exactly as passed to the putc(3) system call.
  • fp β€” the original fp, exactly as passed to the putc(3) system call.

Returns:

the message explaining the error. and 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, other threads included. πŸ™ˆ

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_putc

void explain_message_putc(char *message, int message_size, int c, FILE *fp);

the explain_message_putc function may be used to obtain an explanation of an error returned by the putc(3) 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. she's thorough πŸ’…

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 (putc(c, fp) == EOF)
{
    char message[3000];
    explain_message_putc(message, sizeof(message), c, fp);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}
  • message β€” the location in which to store the returned message. if you supply a suitable message return buffer, this function is thread safe. slay 🫢
  • message_size β€” the size in bytes of the location in which to store the returned message.
  • c β€” the original c, exactly as passed to the putc(3) system call.
  • fp β€” the original fp, exactly as passed to the putc(3) system call.

🧚 explain_message_errno_putc

void explain_message_errno_putc(char *message, int message_size, int errnum, int c, FILE *fp);

the explain_message_errno_putc function may be used to obtain an explanation of an error returned by the putc(3) system call. 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. she understood the assignment. ⭐

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

if (putc(c, fp) == EOF)
{
    int err = errno;
    char message[3000];
    explain_message_errno_putc(message, sizeof(message), err, c, fp);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}
  • 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. (they keep doing it. every time. πŸ’€)
  • c β€” the original c, exactly as passed to the putc(3) system call.
  • fp β€” the original fp, exactly as passed to the putc(3) system call.

πŸ‘‘ SEE ALSO πŸ‘‘


libexplain version 1.4 Copyright (C) 2008 Peter Miller


and that's the whole page bestie, go forth and explain your putc(3) errors with main character energy πŸ’œ β€” this was explain_putc(3), Library Functions Manual, libexplain version 1.4, Copyright (C) 2008 Peter Miller. mwah πŸ“

πŸ“¦ where this page comes from