explain_strtol(3)

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

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 original nptr, exactly as passed to the strtol(3) system call. no edits, no remixes, the original.
  • endptr β€” the original endptr, exactly as passed to the strtol(3) system call.
  • base β€” the original base, exactly as passed to the strtol(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 the errno global 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 of errno. yes, they will betray you. yes, this is why we pass it explicitly. πŸ’€
  • nptr β€” the original nptr, exactly as passed to the strtol(3) system call.
  • endptr β€” the original endptr, exactly as passed to the strtol(3) system call.
  • base β€” the original base, exactly as passed to the strtol(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 original nptr, exactly as passed to the strtol(3) system call.
  • endptr β€” the original endptr, exactly as passed to the strtol(3) system call.
  • base β€” the original base, exactly as passed to the strtol(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 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. (they're messy like that, no cap.)
  • nptr β€” the original nptr, exactly as passed to the strtol(3) system call.
  • endptr β€” the original endptr, exactly as passed to the strtol(3) system call.
  • base β€” the original base, exactly as passed to the strtol(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 πŸ‘‘


  • 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