explain_getrusage(3)

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

πŸ’– explain_getrusage β€” the libexplain page, bestie edition πŸ’–

okay so this is explain_getrusage(3), a manual page from the Library Functions Manual (yes the libexplain girlies know). it's literally the page that explains getrusage(2) errors to you in human words instead of just yelling a number at your face. no cap. πŸ¦‹


✨ NAME ✨

explain_getrusage β€” explain getrusage(2) errors πŸ’…


🌸 SYNOPSIS 🌸

#include <libexplain/getrusage.h>
const char *explain_getrusage(int who, struct rusage *usage);
const char *explain_errno_getrusage(int errnum, int who, struct rusage *usage);
void explain_message_getrusage(char *message, int message_size, int who, struct rusage *usage);
void explain_message_errno_getrusage(char *message, int message_size, int errnum, int who, struct rusage *usage);

πŸŽ€ DESCRIPTION πŸŽ€

These functions may be used to obtain explanations for errors returned by the getrusage(2) system call. like, that's the whole gig. the vibe is: system call goes wrong β†’ these girls tell you why. πŸ‘‘


πŸ’œ explain_getrusage

const char *explain_getrusage(int who, struct rusage *usage);

The explain_getrusage function is used to obtain an explanation of an error returned by the getrusage(2) 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. it's giving overachiever and we love that for it. ✨

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

  • who β€” The original who, exactly as passed to the getrusage(2) system call. no touchy, no renaming, just the same value you handed over. πŸ™ˆ
  • usage β€” The original usage, exactly as passed to the getrusage(2) 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. 😭 shared buffer, shared struggles.

Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. fr fr, do not come for me if your threads start fighting over it. πŸ’€

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

if (getrusage(who, usage) < 0)
{
    fprintf(stderr, "%s\n", explain_getrusage(who, usage));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_getrusage_or_die(3) function. bestie behaviour honestly, it already did the work for you. 🫢


πŸ’œ explain_errno_getrusage

const char *explain_errno_getrusage(int errnum, int who, struct rusage *usage);

The explain_errno_getrusage function is used to obtain an explanation of an error returned by the getrusage(2) 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. iconic, honestly. 🌈

  • 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. so like, grab errno early, it does NOT stay put. ⚠️
  • who β€” The original who, exactly as passed to the getrusage(2) system call.
  • usage β€” The original usage, exactly as passed to the getrusage(2) 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. same shared-buffer drama, different function. πŸ“

Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. periodt. πŸ’…

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

if (getrusage(who, usage) < 0)
{
    int err = errno;
    fprintf(stderr, "%s\n", explain_errno_getrusage(err, who, usage));
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_getrusage_or_die(3) function.


πŸ’œ explain_message_getrusage

void explain_message_getrusage(char *message, int message_size, int who, struct rusage *usage);

The explain_message_getrusage function is used to obtain an explanation of an error returned by the getrusage(2) 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. it's the you supply the buffer edition, main character energy. πŸ‘‘

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. ✨ you bring the buffer, you get the thread safety. that's the deal.
  • message_size β€” The size in bytes of the location in which to store the returned message.
  • who β€” The original who, exactly as passed to the getrusage(2) system call.
  • usage β€” The original usage, exactly as passed to the getrusage(2) system call.

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

if (getrusage(who, usage) < 0)
{
    char message[3000];
    explain_message_getrusage(message, sizeof(message), who, usage);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_getrusage_or_die(3) function.


πŸ’œ explain_message_errno_getrusage

void explain_message_errno_getrusage(char *message, int message_size, int errnum, int who, struct rusage *usage);

The explain_message_errno_getrusage function is used to obtain an explanation of an error returned by the getrusage(2) 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 final boss of this page, and yes she ate. πŸ”₯

  • 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. again: save that errno first, it is not loyal. 😭
  • who β€” The original who, exactly as passed to the getrusage(2) system call.
  • usage β€” The original usage, exactly as passed to the getrusage(2) system call.

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

if (getrusage(who, usage) < 0)
{
    int err = errno;
    char message[3000];
    explain_message_errno_getrusage(message, sizeof(message), err, who, usage);
    fprintf(stderr, "%s\n", message);
    exit(EXIT_FAILURE);
}

The above code example is available pre-packaged as the explain_getrusage_or_die(3) function.


πŸ¦‹ SEE ALSO πŸ¦‹


libexplain version 1.4 Copyright (C) 2013 Peter Miller


and that's the whole page bestie, tysm for reading πŸ’– this was explain_getrusage(3) from libexplain version 1.4, copyright (C) 2013 Peter Miller β€” go forth, decode your errors, and remember: the buffer is shared, the errno is fleeting, but you? you're slaying. πŸ’…βœ¨πŸŒΈπŸ¦‹πŸŽ€

πŸ“¦ where this page comes from