str_error.c 636 B

123456789101112131415161718192021
  1. // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
  2. #undef _GNU_SOURCE
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "str_error.h"
  6. /* make sure libbpf doesn't use kernel-only integer typedefs */
  7. #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
  8. /*
  9. * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
  10. * libc, while checking strerror_r() return to avoid having to check this in
  11. * all places calling it.
  12. */
  13. char *libbpf_strerror_r(int err, char *dst, int len)
  14. {
  15. int ret = strerror_r(err < 0 ? -err : err, dst, len);
  16. if (ret)
  17. snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
  18. return dst;
  19. }