explain_ungetc(3)
β¨ NAME β¨
okay so bestie, meet explain_ungetc β it explains ungetc(3) errors π
Like, ungetc(3) fails and you're standing there like π what does that even mean β this whole library is here to translate the vibe for you. It lives in the Library Functions Manual, and it's giving "your emotional support manpage". π«Ά
πΈ SYNOPSIS πΈ
#include <libexplain/ungetc.h>
const char *explain_ungetc(int c, FILE *fp);
const char *explain_errno_ungetc(int errnum, int c, FILE *fp);
void explain_message_ungetc(char *message, int message_size, int c, FILE *fp);
void explain_message_errno_ungetc(char *message, int message_size, int errnum, int c, FILE *fp);
π¦ DESCRIPTION π¦
So here's the tea: these functions are your go-to for getting actual explanations for errors that come back from the ungetc(3) system call. Not just "it broke", but why. Obsessed. π
π explain_ungetc π
const char *explain_ungetc(int c, FILE *fp);
The explain_ungetc function is how you get an explanation of an error returned by the ungetc(3) 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 more detail. Main character energy, fr fr. β¨
The errno global variable will be used to obtain the error value to be decoded. (It just reads it off errno, no cap.)
cβ the originalc, exactly as passed to theungetc(3)system call.fpβ the originalfp, exactly as passed to theungetc(3)system call.
Returns:
The message explaining the error. Heads up though β 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 which shares this buffer, including other threads. So don't go holding onto it like it's yours, bestie. π
Note: this function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Not me being chaotic in multithreaded code π
Example: this function is intended to be used in a fashion similar to the following example:
if (ungetc(c, fp) < 0)
{
fprintf(stderr, "%s\n", explain_ungetc(c, fp));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_ungetc_or_die(3) function. π (Already done for you, slay.)
π explain_errno_ungetc π
const char *explain_errno_ungetc(int errnum, int c, FILE *fp);
The explain_errno_ungetc function is used to obtain an explanation of an error returned by the ungetc(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. π
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. (Sneaky little things. π€)cβ the originalc, exactly as passed to theungetc(3)system call.fpβ the originalfp, exactly as passed to theungetc(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:
if (ungetc(c, fp) < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_ungetc(err, c, fp));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_ungetc_or_die(3) function. π
π explain_message_ungetc π
void explain_message_ungetc(char *message, int message_size, int c, FILE *fp);
The explain_message_ungetc function is used to obtain an explanation of an error returned by the ungetc(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. β¨
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. π (Yes queen, you bring your own buffer, you get thread safety.)message_sizeβ the size in bytes of the location in which to store the returned message.cβ the originalc, exactly as passed to theungetc(3)system call.fpβ the originalfp, exactly as passed to theungetc(3)system call.
Example: this function is intended to be used in a fashion similar to the following example:
if (ungetc(c, fp) < 0)
{
char message[3000];
explain_message_ungetc(message, sizeof(message), c, fp);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_ungetc_or_die(3) function. π
π§ explain_message_errno_ungetc π§
void explain_message_errno_ungetc(char *message, int message_size, int errnum, int c, FILE *fp);
The explain_message_errno_ungetc function is used to obtain an explanation of an error returned by the ungetc(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. πΈ
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. π¨cβ the originalc, exactly as passed to theungetc(3)system call.fpβ the originalfp, exactly as passed to theungetc(3)system call.
Example: this function is intended to be used in a fashion similar to the following example:
if (ungetc(c, fp) < 0)
{
int err = errno;
char message[3000];
explain_message_errno_ungetc(message, sizeof(message), err, c, fp);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_ungetc_or_die(3) function. π«Ά
β SEE ALSO β
ungetc(3)β push a character back to a streamexplain_ungetc_or_die(3)β push a character back to a stream and report errors
π COPYRIGHT π
libexplain version 1.4
Copyright (C) 2010 Peter Miller
and that's the whole page, bestie π
this was explain_ungetc(3) from the Library Functions Manual, brought to you by libexplain version 1.4, Copyright (C) 2010 Peter Miller β mwah, go push a character back to a stream, you got this π¦β¨
π¦ 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) 2010, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms