mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	It's often inconvenient to switch sign of error when passing it into libbpf_strerror_r. It's better for it to handle that automatically. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Reviewed-by: Stanislav Fomichev <sdf@google.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
		
			
				
	
	
		
			18 lines
		
	
	
	
		
			522 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
	
		
			522 B
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 | 
						|
#undef _GNU_SOURCE
 | 
						|
#include <string.h>
 | 
						|
#include <stdio.h>
 | 
						|
#include "str_error.h"
 | 
						|
 | 
						|
/*
 | 
						|
 * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
 | 
						|
 * libc, while checking strerror_r() return to avoid having to check this in
 | 
						|
 * all places calling it.
 | 
						|
 */
 | 
						|
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);
 | 
						|
	return dst;
 | 
						|
}
 |