diff options
| author | Michael Biebl <biebl@debian.org> | 2024-01-25 09:46:52 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2024-01-25 09:46:52 +0100 |
| commit | b6357ff41de179d0aa2e35a6d574e5749fe09002 (patch) | |
| tree | ff038e98f4569fa3ba217266e6d288410ed84cd4 /src/libnm-std-aux/nm-std-utils.c | |
| parent | 535ecf92edd8ad054ae8102a224c3dd8f3acf967 (diff) | |
| parent | 70e18d99b8e3e77bb37e218d7ac582130156f8ef (diff) | |
Update upstream source from tag 'upstream/1.45.90'
Update to upstream version '1.45.90' with Debian dir d723a85d75b9a8958dee17b97673a3fd9a80e18c
Diffstat (limited to 'src/libnm-std-aux/nm-std-utils.c')
| -rw-r--r-- | src/libnm-std-aux/nm-std-utils.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libnm-std-aux/nm-std-utils.c b/src/libnm-std-aux/nm-std-utils.c index 8901378c..8bc109f2 100644 --- a/src/libnm-std-aux/nm-std-utils.c +++ b/src/libnm-std-aux/nm-std-utils.c @@ -92,3 +92,43 @@ out_huge: } return SIZE_MAX; } + +/*****************************************************************************/ + +/** + * _nm_strerror_r: + * @errsv: the errno passed to strerror_r() + * @buf: the string buffer, must be non-null + * @buf_size: the size of the buffer, must be positive. + * + * A wrapper around strerror_r(). Does little else, aside clearing up the + * confusion about the different versions of the function. + * + * errno is preserved. + * + * Returns: the error string. This is either a static strong or @buf. It + * is not guaranteed to be @buf. + */ +const char * +_nm_strerror_r(int errsv, char *buf, size_t buf_size) +{ + NM_AUTO_PROTECT_ERRNO(errsv2); + char *buf2; + + nm_assert(buf); + nm_assert(buf_size > 0); + +#if (!defined(__GLIBC__) && !defined(__UCLIBC__)) || ((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE) + /* XSI-compliant */ + if (strerror_r(errsv, buf, buf_size) != 0) { + snprintf(buf, buf_size, "Unspecified errno %d", errsv); + } + buf2 = buf; +#else + /* GNU-specific */ + buf2 = strerror_r(errsv, buf, buf_size); +#endif + + nm_assert(buf2); + return buf2; +} |