explain_fseek(3)
π 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 originalfp, exactly as it was passed to thefseek(3)system call. Same one, untouched, fr fr.offsetβ the originaloffset, exactly as passed to thefseek(3)system call.whenceβ the originalwhence, exactly as passed to thefseek(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 theerrnoglobal 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 oferrno. Sneaky of them ngl.fpβ the originalfp, exactly as passed to thefseek(3)system call.offsetβ the originaloffset, exactly as passed to thefseek(3)system call.whenceβ the originalwhence, exactly as passed to thefseek(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 originalfp, exactly as passed to thefseek(3)system call.offsetβ the originaloffset, exactly as passed to thefseek(3)system call.whenceβ the originalwhence, exactly as passed to thefseek(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 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. (Yes, again. They're like that. π€)fpβ the originalfp, exactly as passed to thefseek(3)system call.offsetβ the originaloffset, exactly as passed to thefseek(3)system call.whenceβ the originalwhence, exactly as passed to thefseek(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 π«Ά
fseek(3)β reposition a streamexplain_fseek_or_die(3)β reposition a stream and report errors
π COPYRIGHT π
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
- 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