str_error.c 479 B

123456789101112131415161718
  1. // SPDX-License-Identifier: LGPL-2.1
  2. #undef _GNU_SOURCE
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "str_error.h"
  6. /*
  7. * Wrapper to allow for building in non-GNU systems such as Alpine Linux's musl
  8. * libc, while checking strerror_r() return to avoid having to check this in
  9. * all places calling it.
  10. */
  11. char *str_error(int err, char *dst, int len)
  12. {
  13. int ret = strerror_r(err, dst, len);
  14. if (ret)
  15. snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, ret);
  16. return dst;
  17. }