explain_strtoll(3)

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

🌸 explain_strtoll β€” ok bestie, let's decode ur strtoll(3) L's 🌸

Library Functions Manual Β· the libexplain era Β· explain_strtoll(3)


✨ NAME ✨

explain_strtoll β€” no cap, this is the one that explains ur strtoll(3) errors πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <libexplain/strtoll.h>
const char *explain_strtoll(const char *nptr, char **endptr, int base);
const char *explain_errno_strtoll(int errnum, const char *nptr, char
**endptr, int base);
void explain_message_strtoll(char *message, int message_size, const char
*nptr, char **endptr, int base);
void explain_message_errno_strtoll(char *message, int message_size, int
errnum, const char *nptr, char **endptr, int base);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so, these functions? They're ur little group chat that explains errors handed back by the strtoll(3) system call. Four of them. All icons, all doing slightly different things. Let's get into it 🫢


πŸ’– explain_strtoll

const char *explain_strtoll(const char *nptr, char **endptr, int base);

The explain_strtoll function is how u get an explanation of an error that came back from strtoll(3). Like, the least the message will contain is the value of strerror(errno), but honestly? Usually it does so much better and tells u the underlying cause in way more detail. It's giving detective energy fr fr πŸ”

The errno global variable is what gets used to obtain the error value that needs decoding.

  • nptr β€” the original nptr, exactly as passed to the strtoll(3) system call. no edits, no glow-up, just as-is ✨
  • endptr β€” the original endptr, exactly as passed to the strtoll(3) system call.
  • base β€” the original base, exactly as passed to the strtoll(3) system call.

Returns:

The message explaining the error. Heads up tho: this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. So it will get overwritten by the next call to any libexplain function that shares this buffer β€” including calls from other threads 😭

Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. it's giving communal, and not in a cute way πŸ’€

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

long long result = strtoll(nptr, endptr, base);
if (result < 0)
{
    fprintf(stderr, "%s\n", explain_strtoll(nptr, endptr, base));
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_strtoll_or_die(3) function. convenient much? πŸ‘‘


🌈 explain_errno_strtoll

const char *explain_errno_strtoll(int errnum, const char *nptr, char
**endptr, int base);

The explain_errno_strtoll function is how u get an explanation of an error returned by the strtoll(3) system call. Again, the least the message will contain is the value of strerror(errno), but usually it goes way harder and shows u 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. This one matters if u need to run any code between the system call u wanna explain and this function, because many libc functions will alter the value of errno and then ur explanation is explaining the wrong thing πŸ™ˆ
  • nptr β€” the original nptr, exactly as passed to the strtoll(3) system call.
  • endptr β€” the original endptr, exactly as passed to the strtoll(3) system call.
  • base β€” the original base, exactly as passed to the strtoll(3) system call.

Returns:

The message explaining the error. Same tea as before: this message buffer is shared by all libexplain functions which don't supply a buffer in their argument list, and it will be overwritten by the next call to any libexplain function that shares this buffer, including other threads.

Note: not thread safe, because it shares a return buffer across all threads, and many other functions in this library do too. periodt πŸ’€

Example: intended to be used in a fashion similar to:

long long result = strtoll(nptr, endptr, base);
if (result < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_strtoll(err, nptr,
    endptr, base));
    exit(EXIT_FAILURE);
}

The above code example is available pre‐packaged as the explain_strtoll_or_die(3) function. slay ✨


🧚 explain_message_strtoll

void explain_message_strtoll(char *message, int message_size, const char
*nptr, char **endptr, int base);

The explain_message_strtoll function gets u an explanation of an error returned by the strtoll(3) system call. Least the message will contain is the value of strerror(errno), but usually it does much better and points at the underlying cause in more detail.

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

  • message β€” the location where the returned message gets stored. If a suitable message return buffer is supplied, this function is thread safe. πŸ‘‘ that's the upgrade bestie
  • 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 strtoll(3) system call.
  • endptr β€” the original endptr, exactly as passed to the strtoll(3) system call.
  • base β€” the original base, exactly as passed to the strtoll(3) system call.

Example: intended to be used in a fashion similar to:

long long result = strtoll(nptr, endptr, base);
if (result < 0)
{
    char message[3000];
    explain_message_strtoll(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_strtoll_or_die(3) function. we love a pre-packaged moment 🎁


πŸ’œ explain_message_errno_strtoll

void explain_message_errno_strtoll(char *message, int message_size, int
errnum, const char *nptr, char **endptr, int base);

The explain_message_errno_strtoll function is used to obtain an explanation of an error returned by the strtoll(3) system call. 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.

  • 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 u 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. stay vigilant bestie 😭
  • nptr β€” the original nptr, exactly as passed to the strtoll(3) system call.
  • endptr β€” the original endptr, exactly as passed to the strtoll(3) system call.
  • base β€” the original base, exactly as passed to the strtoll(3) system call.

Example: intended to be used in a fashion similar to:

long long result = strtoll(nptr, endptr, base);
if (result < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_strtoll(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_strtoll_or_die(3) function. iconic behavior, truly πŸ”₯


⭐ SEE ALSO ⭐

iykyk, these two are the whole squad πŸ‘―


libexplain version 1.4 Copyright (C) 2009 Peter Miller


and that's the whole page bestie!! 🌸 this was explain_strtoll(3) from the Library Functions Manual, brought to u by libexplain version 1.4, copyright (C) 2009 Peter Miller β€” mwah, take care of ur errno, drink water, and go convert some strings responsibly πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from