File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,17 @@ static inline char *strerror_safe(int error) {
3636 return strerror (abs (error ));
3737}
3838
39+ static inline int errno_or_else (int fallback ) {
40+ /* To be used when invoking library calls where errno handling is not defined clearly: we return
41+ * errno if it is set, and the specified error otherwise. The idea is that the caller initializes
42+ * errno to zero before doing an API call, and then uses this helper to retrieve a somewhat useful
43+ * error code */
44+ if (errno > 0 )
45+ return - errno ;
46+
47+ return - abs (fallback );
48+ }
49+
3950/* Hint #1: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5.
4051 *
4152 * Hint #2: The kernel sends e.g., EHOSTUNREACH or ENONET to userspace in some ICMP error cases. See the
You can’t perform that action at this time.
0 commit comments