explain_fseek(3)

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

πŸ’– explain_fseek(3) β€” the manual page, but make it make sense πŸ’–

library functions manual ✨ libexplain ✨ bestie edition


🌸 NAME 🌸

explain_fseek β€” ok so this one explains fseek(3) errors for you, no cap 🫢


✨ SYNOPSIS ✨

#include <libexplain/fseek.h>
const char *explain_fseek(FILE *fp, long offset, int whence);
const char *explain_errno_fseek(int errnum, FILE *fp, long offset, int
whence);
void explain_message_fseek(char *message, int message_size, FILE *fp,
long offset, int whence);
void explain_message_errno_fseek(char *message, int message_size, int
errnum, FILE *fp, long offset, int whence);

πŸ‘‘ DESCRIPTION πŸ‘‘

So basically these functions are your little translators πŸ’… β€” you hit an error from the fseek(3) system call, and these hand you back an explanation of what actually went wrong. Iconic behaviour, honestly.

πŸ¦‹ explain_fseek

const char *explain_fseek(FILE *fp, long offset, int whence);

explain_fseek is the one you call to get an explanation of an error that came back from the fseek(3) system call. The bare minimum it will give you is the value of strerror(errno) β€” but usually it does so much better than that, and points at the actual underlying cause in way more detail. She ate. πŸ”₯

The errno global variable is the one it reads to figure out which error value it's decoding.

  • fp β€” the original fp, exactly as it was passed to the fseek(3) system call. Same one, untouched, fr fr.
  • offset β€” the original offset, exactly as passed to the fseek(3) system call.
  • whence β€” the original whence, exactly as passed to the fseek(3) system call.

Returns: The message explaining the error. Heads up though β€” this message buffer is shared by every libexplain function that doesn't take a buffer in its argument list. So it gets overwritten the next time any libexplain function that shares this buffer gets called, including from other threads. 😭

Note: this function is not thread safe, because it shares one return buffer across all threads, and so do lots of other functions in this library. Not her fault, it's the buffer's fault.

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

if (fseek(fp, offset, whence) < 0)
{
    fprintf(stderr, "%s\n", explain_fseek(fp, offset, whence));
    exit(EXIT_FAILURE);
}

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

πŸ’œ explain_errno_fseek

const char *explain_errno_fseek(int errnum, FILE *fp, long offset, int
whence);

explain_errno_fseek gets you an explanation of an error returned by the fseek(3) system call. The least the message will contain is the value of strerror(errno), but usually it goes way harder and shows you the underlying cause in more detail. ✨

  • errnum β€” the error value to be decoded, usually grabbed from the errno global variable right before this function is called. You need to do that if there's any code running between the system call you're explaining and this function, because lots of libc functions will alter the value of errno. Sneaky of them ngl.
  • fp β€” the original fp, exactly as passed to the fseek(3) system call.
  • offset β€” the original offset, exactly as passed to the fseek(3) system call.
  • whence β€” the original whence, exactly as passed to the fseek(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 (fseek(fp, offset, whence) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_fseek(err, fp, offset,
    whence));
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_fseek_or_die(3) function. πŸ’–

🌈 explain_message_fseek

void explain_message_fseek(char *message, int message_size, FILE *fp,
long offset, int whence);

explain_message_fseek gets you an explanation of an error returned by the fseek(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 like that. πŸ’…

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 fseek(3) system call.
  • offset β€” the original offset, exactly as passed to the fseek(3) system call.
  • whence β€” the original whence, exactly as passed to the fseek(3) system call.

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

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

The above code example is available pre‐packaged as the explain_fseek_or_die(3) function. πŸ¦‹

🧚 explain_message_errno_fseek

void explain_message_errno_fseek(char *message, int message_size, int
errnum, FILE *fp, long offset, int whence);

explain_message_errno_fseek gets you an explanation of an error returned by the fseek(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. Periodt. ⭐

  • 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. They're like that. 😀)
  • fp β€” the original fp, exactly as passed to the fseek(3) system call.
  • offset β€” the original offset, exactly as passed to the fseek(3) system call.
  • whence β€” the original whence, exactly as passed to the fseek(3) system call.

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

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

The above code example is available pre‐packaged as the explain_fseek_or_die(3) function. πŸ“


🫢 SEE ALSO 🫢


libexplain version 1.4 Copyright (C) 2010 Peter Miller


ok that's the whole page bestie, you're officially a fseek(3) error-decoding legend 🌟 this was explain_fseek(3) from the Library Functions Manual, brought to you by libexplain version 1.4, copyright (C) 2010 Peter Miller β€” mwah, go forth and debug πŸ’…βœ¨

πŸ“¦ where this page comes from