basic: add STRERROR() wrapper for strerror_r()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-10-11 16:10:21 +02:00
parent 0cbefc7d4f
commit 2c5d05b3cd
3 changed files with 56 additions and 0 deletions
+10
View File
@@ -6,6 +6,16 @@
#include "macro.h"
/* strerror(3) says that glibc uses a maximum length of 1024 bytes. */
#define ERRNO_BUF_LEN 1024
/* Note: the lifetime of the compound literal is the immediately surrounding block,
* see C11 §6.5.2.5, and
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks
*
* Note that we use the GNU variant of strerror_r() here. */
#define STRERROR(errnum) strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
static inline void _reset_errno_(int *saved_errno) {
if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
return;