mirror of
https://github.com/systemd/systemd.git
synced 2025-03-22 06:50:18 +03:00
errno-util: add new errno_or_else() helper
This commit is contained in:
parent
4747b645c6
commit
fed813778f
@ -36,6 +36,17 @@ static inline char *strerror_safe(int error) {
|
||||
return strerror(abs(error));
|
||||
}
|
||||
|
||||
static inline int errno_or_else(int fallback) {
|
||||
/* To be used when invoking library calls where errno handling is not defined clearly: we return
|
||||
* errno if it is set, and the specified error otherwise. The idea is that the caller initializes
|
||||
* errno to zero before doing an API call, and then uses this helper to retrieve a somewhat useful
|
||||
* error code */
|
||||
if (errno > 0)
|
||||
return -errno;
|
||||
|
||||
return -abs(fallback);
|
||||
}
|
||||
|
||||
/* 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user