explain_strtol(3)
explain_strtol(3) π
okay bestie, gather round, because we're about to talk about the Library Functions Manual page for explain_strtol from libexplain β the glow-up your error messages have been begging for. β¨
πΈ NAME πΈ
explain_strtol β the girl who explains your strtol(3) errors to you, gently, in full sentences π
π SYNOPSIS π
#include <libexplain/strtol.h>
const char *explain_strtol(const char *nptr, char **endptr, int base);
const char *explain_errno_strtol(int errnum, const char *nptr, char
**endptr, int base);
void explain_message_strtol(char *message, int message_size, const char
*nptr, char **endptr, int base);
void explain_message_errno_strtol(char *message, int message_size, int
errnum, const char *nptr, char **endptr, int base);
π¦ DESCRIPTION π¦
So like, these functions are your little translators: they take an error that came back from the strtol(3) system call and turn it into an actual explanation. No more squinting at a bare errno like it's a cryptic text from a guy who types in one word only. π
explain_strtol π
const char *explain_strtol(const char *nptr, char **endptr, int base);
explain_strtol gets you an explanation of an error returned by the strtol(3) system call. The bare minimum the message will contain is the value of strerror(errno), but honestly? Usually it does so much better than that and tells you the underlying cause in way more detail. It's giving investigative journalist energy. π
The errno global variable is the one it uses to grab the error value that needs decoding.
nptrβ the originalnptr, exactly as passed to thestrtol(3)system call. no edits, no remixes, the original.endptrβ the originalendptr, exactly as passed to thestrtol(3)system call.baseβ the originalbase, exactly as passed to thestrtol(3)system call.
Returns: The message explaining the error. This message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. Which means it gets overwritten by the next call to any libexplain function sharing that buffer β including calls from other threads. π
Note: This function is not thread safe, because it shares a return buffer across all threads, plus many other functions in this library do the same thing. So yeah. Be careful bestie. π«Ά
Example: This function is meant to be used in a fashion similar to the following example:
long result = strtol(nptr, endptr, base);
if (result < 0)
{
fprintf(stderr, "%s\n", explain_strtol(nptr, endptr, base));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_strtol_or_die(3) function. Convenience? Iconic. π
explain_errno_strtol β¨
const char *explain_errno_strtol(int errnum, const char *nptr, char
**endptr, int base);
explain_errno_strtol gets you an explanation of an error returned by the strtol(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 overachiever behavior, different signature. π
errnumβ the error value to be decoded, usually grabbed from theerrnoglobal variable right before this function is called. You need to do this if you have to call any code between the system call being explained and this function, because many libc functions will alter the value oferrno. yes, they will betray you. yes, this is why we pass it explicitly. πnptrβ the originalnptr, exactly as passed to thestrtol(3)system call.endptrβ the originalendptr, exactly as passed to thestrtol(3)system call.baseβ the originalbase, exactly as passed to thestrtol(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:
long result = strtol(nptr, endptr, base);
if (result < 0)
{
int err = errno;
fprintf(stderr, "%s\n", explain_errno_strtol(err, nptr,
endptr, base));
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_strtol_or_die(3) function.
explain_message_strtol π
void explain_message_strtol(char *message, int message_size, const char
*nptr, char **endptr, int base);
explain_message_strtol gets you an explanation of an error returned by the strtol(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. look at her go!! π₯³message_sizeβ the size in bytes of the location in which to store the returned message.nptrβ the originalnptr, exactly as passed to thestrtol(3)system call.endptrβ the originalendptr, exactly as passed to thestrtol(3)system call.baseβ the originalbase, exactly as passed to thestrtol(3)system call.
Example: This function is intended to be used in a fashion similar to the following example:
long result = strtol(nptr, endptr, base);
if (result < 0)
{
char message[3000];
explain_message_strtol(message, sizeof(message), nptr,
endptr, base);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_strtol_or_die(3) function.
explain_message_errno_strtol π
void explain_message_errno_strtol(char *message, int message_size, int
errnum, const char *nptr, char **endptr, int base);
explain_message_errno_strtol gets you an explanation of an error returned by the strtol(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, if you will. π
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. (they're messy like that, no cap.)nptrβ the originalnptr, exactly as passed to thestrtol(3)system call.endptrβ the originalendptr, exactly as passed to thestrtol(3)system call.baseβ the originalbase, exactly as passed to thestrtol(3)system call.
Example: This function is intended to be used in a fashion similar to the following example:
long result = strtol(nptr, endptr, base);
if (result < 0)
{
int err = errno;
char message[3000];
explain_message_errno_strtol(message, sizeof(message), err,
nptr, endptr, base);
fprintf(stderr, "%s\n", message);
exit(EXIT_FAILURE);
}
The above code example is available pre-packaged as the explain_strtol_or_die(3) function.
π SEE ALSO π
strtol(3)β convert a string to a long integerexplain_strtol_or_die(3)β convert a string to a long integer and report errors
π COPYRIGHT π
- libexplain version 1.4
- Copyright (C) 2009 Peter Miller
and that's the whole page bestie, you ate that π
β¨ explain_strtol(3), libexplain version 1.4, copyright 2009 Peter Miller β mwah, go forth and read your error messages like the main character you are π«Άπ
π¦ 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) 2009-2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms