tree-wide: introduce strerror_safe()

This commit is contained in:
Yu Watanabe
2019-07-05 02:43:56 +09:00
parent 7fa6223f67
commit 4bbccb02ea
20 changed files with 55 additions and 38 deletions
+8
View File
@@ -1,6 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdlib.h>
#include <string.h>
#include "macro.h"
static inline void _reset_errno_(int *saved_errno) {
@@ -28,6 +31,11 @@ static inline int negative_errno(void) {
return -errno;
}
static inline char *strerror_safe(int error) {
/* 'safe' here does NOT mean thread safety. */
return strerror(abs(error));
}
/* Hint #1: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5.
*
* Hint #2: The kernel sends e.g., EHOSTUNREACH or ENONET to userspace in some ICMP error cases. See the