sg_get_error(3)
πΈ NAME πΈ
okay bestie, welcome to the sg_get_error(3) page from the statgrab manual π
β this one is all about the little squad of functions that tell you what the last error was: sg_get_error, sg_get_error_arg, sg_get_error_errno, sg_str_error, sg_get_error_details, and sg_strperror.
β¨ SYNOPSIS β¨
#include <statgrab.h>
sg_error sg_get_error (void);
const char *sg_get_error_arg (void);
int sg_get_error_errno (void);
sg_error sg_get_error_details (sg_error_details *err_details);
const char *sg_str_error (sg_error code);
char *sg_strperror (char **buf, const sg_error_details * const
err_details);
π DESCRIPTION π
so there are four functions that get you info about the last error that happened: sg_get_error, sg_get_error_arg, sg_get_error_errno, and sg_get_error_details. The other two are here to make the machine-human-interface nicer β like your error log or a message box, bestie. sg_str_error gives you a human-readable error name, and sg_strperror prepares a full-blown error message ready for printing β¨
the error argument from sg_get_error_arg is stored thread local and gets reused every time an error occurs. if you're gonna use it later, duplicating it is a suitable strategy π same goes for the error_arg of sg_error_details delivered by sg_get_error_details.
β οΈ careful, bestie: if someone callssg_get_error_detailswith aNULLpointer, the last error gets overridden with a new one describing thatsg_get_error_detailswas called with invalid arguments. please be careful π
sg_strperror is allowed to be called with or without collected error details (err_details is NULL). in the latter case, the last occurred error of this thread is used to prepare the error message. be aware that the buffer pointer must be non-NULL β it points to an existing char * lvalue β but the char * lvalue it points to must be NULL. when invoked correctly, there are only two possible error conditions that let sg_strperror fail: ENOMEM (out of memory) and EINVAL (invalid error code) π
π Example π
if( NULL == sg_get_cpu_stats() ) {
char *buf = NULL;
if( NULL != sg_strperror( &buf, NULL ) ) {
fprintf( stderr, "error getting CPU stats: %s\n", buf );
free(buf);
exit(255);
}
else {
fprintf( stderr, "error getting CPU stats and error information\n" );
exit(255);
}
}
π¦ RETURN VALUES π¦
the error details contains following information:
typedef struct sg_error_details {
sg_error error;
int errno_value;
const char *error_arg;
} sg_error_details;
errorβ the statgrab library error code πerrno_valueβ the operating system error code π₯error_argβ additional information set when the error was reported π«Ά
π SEE ALSO π
statgrab(3)β go peek at the main character, no cap π
π WEBSITE π
β¨https://libstatgrab.org/β© β the website, literally right there π¦
source/version: libstatgrab Β· date: 2019-03-08 Β· this was the sg_get_error(3) manual page, bye bestie, slay responsibly πβ¨
π¦ where this page comes from
- alpine 3.24: libstatgrab-doc 0.92.1-r1 Β· LGPL-2.0-or-later
- arch rolling: libstatgrab 0.92.1-2 Β· LGPL AND GPL
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- nixos 26.05: libstatgrab 0.92.1
- nixpkgs unstable: libstatgrab 0.92.1
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms