18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 28c2ecf20Sopenharmony_ci#undef _GNU_SOURCE 38c2ecf20Sopenharmony_ci#include <string.h> 48c2ecf20Sopenharmony_ci#include <stdio.h> 58c2ecf20Sopenharmony_ci#include "str_error.h" 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* make sure libbpf doesn't use kernel-only integer typedefs */ 88c2ecf20Sopenharmony_ci#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* 118c2ecf20Sopenharmony_ci * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl 128c2ecf20Sopenharmony_ci * libc, while checking strerror_r() return to avoid having to check this in 138c2ecf20Sopenharmony_ci * all places calling it. 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_cichar *libbpf_strerror_r(int err, char *dst, int len) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci int ret = strerror_r(err < 0 ? -err : err, dst, len); 188c2ecf20Sopenharmony_ci if (ret) 198c2ecf20Sopenharmony_ci snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret); 208c2ecf20Sopenharmony_ci return dst; 218c2ecf20Sopenharmony_ci} 22