diff options
Diffstat (limited to 'tools/lib/bpf/str_error.c')
| -rw-r--r-- | tools/lib/bpf/str_error.c | 16 | 
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c index 146da01979c7..5e6a1e27ddf9 100644 --- a/tools/lib/bpf/str_error.c +++ b/tools/lib/bpf/str_error.c @@ -2,6 +2,7 @@  #undef _GNU_SOURCE  #include <string.h>  #include <stdio.h> +#include <errno.h>  #include "str_error.h"  /* make sure libbpf doesn't use kernel-only integer typedefs */ @@ -15,7 +16,18 @@  char *libbpf_strerror_r(int err, char *dst, int len)  {  	int ret = strerror_r(err < 0 ? -err : err, dst, len); -	if (ret) -		snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret); +	/* on glibc <2.13, ret == -1 and errno is set, if strerror_r() can't +	 * handle the error, on glibc >=2.13 *positive* (errno-like) error +	 * code is returned directly +	 */ +	if (ret == -1) +		ret = errno; +	if (ret) { +		if (ret == EINVAL) +			/* strerror_r() doesn't recognize this specific error */ +			snprintf(dst, len, "unknown error (%d)", err < 0 ? err : -err); +		else +			snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret); +	}  	return dst;  }  | 
