---
name: "sg_get_error_errno"
section: "3"
platform: "linux"
package: "libstatgrab"
version: "0.92.1-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/sg_get_error_errno"
---

# sg\_get\_error\_errno(3)

get last error status

## NAME

sg\_get\_error, sg\_get\_error\_arg, sg\_get\_error\_errno, sg\_str\_error, sg\_get\_error\_details, sg\_strperror - get last error status

## SYNOPSIS

```
FC#include <statgrab.h>F[0]
```

FCsg\_error **sg\_get\_error**F\[0\]  FC(void);F\[0\]

FCconst char \***sg\_get\_error\_arg**F\[0\]  FC(void);F\[0\]

FCint **sg\_get\_error\_errno**F\[0\]  FC(void);F\[0\]

FCsg\_error **sg\_get\_error\_details**F\[0\]  FC(sg\_error\_details \**err\_details*);F\[0\]

FCconst char \***sg\_str\_error**F\[0\]  FC(sg\_error *code*);F\[0\]

FCchar \***sg\_strperror**F\[0\]  FC(char \*\**buf*, const sg\_error\_details \* const *err\_details*);F\[0\]

## DESCRIPTION

There are four functions to get information about the last occurred error: FC**sg\_get\_error**F\[0\], FC**sg\_get\_error\_arg**F\[0\], FC**sg\_get\_error\_errno**F\[0\] and FC**sg\_get\_error\_details**F\[0\]. The remaining functions are intended to improve the machine-human-interface (e.g. the error log or a message box): FC**sg\_str\_error**F\[0\] delivers a human readable error name and FC**sg\_strperror**F\[0\] prepares a full blown error message for printing.

The error argument (FC**sg\_get\_error\_arg**F\[0\]) is stored thread local and is reused every time an error occures. If a later usage is intended, duplicating it is a suitable strategy. Same for the FCerror\_argF\[0\] of FCsg\_error\_detailsF\[0\] delivered by FC**sg\_get\_error\_details**F\[0\].

When someone calls the function FC**sg\_get\_error\_details**F\[0\] with a NULL pointer, the last error is overridden with a new one describing that FC**sg\_get\_error\_details**F\[0\] is called with invalid arguments. Please be careful.

The function FC**sg\_strperror**F\[0\] is allowed to be called with or without (FCerr\_detailsF\[0\] is NULL) collected error details. In the latter case, the last occurred error of this thread is used to prepare the error message. Be aware, the the buffer pointer must be non-NULL (points to an existing FCchar \*F\[0\] lvalue), but the FCchar \*F\[0\] lvalue it points to, must be NULL. When invoked correctly, there are only two possible error conditions let FC**sg\_strperror**F\[0\] fail: ENOMEM (out of memory) and EINVAL (invalid error code).

**Example**

```
FC
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);
    }
}
        F[0]
```

## RETURN VALUES

The error details contains following information:

```
FC
typedef struct sg_error_details {
        sg_error error;
        int errno_value;
        const char *error_arg;
} sg_error_details;
    F[0]
```

- FCerrorF\[0\]

  The statgrab library error code.

- FCerrno\_valueF\[0\]

  The operating system error code.

- FCerror\_argF\[0\]

  Additional information set when the error was reported.

## SEE ALSO

[**statgrab**(3)](/statgrab/3.md)

## WEBSITE

⟨https://libstatgrab.org/⟩
