explain_fileno(3)

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

πŸ’– explain_fileno(3) πŸ’–

okay bestie, gather round, we're doing explain_fileno(3) from the Library Functions Manual and it's genuinely so useful. This is the glow-up page for all the fileno(3) error-explaining functions in libexplain, and I'm gonna walk you through every single one. no skips. periodt. ✨


🌸 NAME 🌸

explain_fileno β€” explain fileno(3) errors πŸ’…

like, it literally explains the errors. that's the whole job. iconic.


πŸŽ€ SYNOPSIS πŸŽ€

#include <libexplain/fileno.h>
const char *explain_fileno(FILE *fp);
const char *explain_errno_fileno(int errnum, FILE *fp);
void explain_message_fileno(char *message, int message_size, FILE *fp);
void explain_message_errno_fileno(char *message, int message_size, int errnum, FILE *fp);

four functions. four besties. each one handles the error-explaining vibe a lil differently, and honestly? slay. πŸ¦‹


✨ DESCRIPTION ✨

so, these functions may be used to obtain explanations for errors returned by the fileno(3) system call. that's the whole plot. no cap. πŸ’œ


πŸ’« explain_fileno

const char *explain_fileno(FILE *fp);

The explain_fileno function is used to obtain an explanation of an error returned by the fileno(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. like, it overdelivers. main character energy fr fr. πŸ‘‘

The errno global variable will be used to obtain the error value to be decoded.

  • fp β€” The original fp, exactly as passed to the fileno(3) system call. yes, the exact same one. don't be out here inventing new ones. πŸ™ˆ

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. so like, if you're threading, know that. it's giving "borrowed your hoodie and gave it back different". 😭

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

if (fileno(fp) < 0)
{
    fprintf(stderr, "%s\n", explain_fileno(fp));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_fileno_or_die(3) function. so if you're lazy (valid), there's a shortcut. πŸ’–


🌈 explain_errno_fileno

const char *explain_errno_fileno(int errnum, FILE *fp);

The explain_errno_fileno function is used to obtain an explanation of an error returned by the fileno(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. same energy, different signature. ✨

  • 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. yes bestie, errno is fragile. grab it fast or it's gone. 🫢
  • fp β€” The original fp, exactly as passed to the fileno(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 (fileno(fp) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_fileno(err, fp));
    exit(EXIT_FAILURE);
}

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


πŸ¦‹ explain_message_fileno

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

The explain_message_fileno function is used to obtain an explanation of an error returned by the fileno(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. ooh she's responsible. we love a buffer-owning queen. πŸ‘‘
  • 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 fileno(3) system call.

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

if (fileno(fp) < 0)
{
    char message[3000];
    explain_message_fileno(message, sizeof(message), fp);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_fileno_or_die(3) function. πŸ’œ


🧚 explain_message_errno_fileno

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

The explain_message_errno_fileno function is used to obtain an explanation of an error returned by the fileno(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 full combo meal, no substitutions. πŸ“

  • 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. yes, again, errno will get sniped if you sleep on it. 😭
  • fp β€” The original fp, exactly as passed to the fileno(3) system call.

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

if (fileno(fp) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_fileno(message, sizeof(message), err, fp);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

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


πŸ‘€ SEE ALSO πŸ‘€

go read those too bestie, they're part of the lore. πŸ“š


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

and that's the whole page!! 🫢 thanks for reading all the way to the end, you're literally the best. this was explain_fileno(3), part of the Library Functions Manual, libexplain version 1.4, Copyright (C) 2009 Peter Miller, and yes the footer says explain_fileno(3) one more time because she loves a grand entrance and an even grander exit. bye bestie, go explain some errors!! πŸ’–βœ¨πŸŒˆπŸ’…

πŸ“¦ where this page comes from