Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / package / libs / elfutils / patches / 100-musl-compat.patch
1 https://sourceware.org/bugzilla/show_bug.cgi?id=21002
2
3 --- a/lib/system.h
4 +++ b/lib/system.h
5 @@ -30,7 +30,18 @@
6  #define LIB_SYSTEM_H   1
7  
8  #include <errno.h>
9 -#include <error.h>
10 +#ifdef HAVE_ERROR_H
11 +#include "error.h"
12 +#else
13 +#include "err.h"
14 +#include <stdio.h>
15 +#define error(status, errno, ...)              \
16 +       do {                                    \
17 +               fflush(stdout);                 \
18 +               warn(__VA_ARGS__);              \
19 +               if (status) exit(status);       \
20 +        } while(0)
21 +#endif
22  #include <stddef.h>
23  #include <stdint.h>
24  #include <sys/param.h>
25 @@ -38,6 +49,10 @@
26  #include <byteswap.h>
27  #include <unistd.h>
28  
29 +#ifndef __GLIBC__
30 +#define canonicalize_file_name(name) realpath(name,NULL)
31 +#endif
32 +
33  #if __BYTE_ORDER == __LITTLE_ENDIAN
34  # define LE32(n)       (n)
35  # define LE64(n)       (n)
36 --- a/libdw/libdw_alloc.c
37 +++ b/libdw/libdw_alloc.c
38 @@ -73,5 +73,5 @@ __attribute ((noreturn)) attribute_hidde
39  __libdw_oom (void)
40  {
41    while (1)
42 -    error (EXIT_FAILURE, ENOMEM, "libdw");
43 +    error (EXIT_FAILURE, errno, gettext ("cannot allocate memory"));
44  }
45 --- a/libdwfl/dwfl_error.c
46 +++ b/libdwfl/dwfl_error.c
47 @@ -140,6 +140,7 @@ __libdwfl_seterrno (Dwfl_Error error)
48  const char *
49  dwfl_errmsg (int error)
50  {
51 +  static __thread char s[64] = "";
52    if (error == 0 || error == -1)
53      {
54        int last_error = global_error;
55 @@ -154,7 +155,8 @@ dwfl_errmsg (int error)
56    switch (error &~ 0xffff)
57      {
58      case OTHER_ERROR (ERRNO):
59 -      return strerror_r (error & 0xffff, "bad", 0);
60 +      strerror_r (error & 0xffff, s, sizeof(s));
61 +      return s;
62      case OTHER_ERROR (LIBELF):
63        return elf_errmsg (error & 0xffff);
64      case OTHER_ERROR (LIBDW):