ctf-decls.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Declarations for missing functions.
  2. Copyright (C) 2019-2022 Free Software Foundation, Inc.
  3. This file is part of libctf.
  4. libctf is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _CTF_DECLS_H
  16. #define _CTF_DECLS_H
  17. #include "config.h"
  18. #include <stddef.h>
  19. #include <stdlib.h>
  20. #include "libiberty.h"
  21. #if HAVE_QSORT_R_ARG_LAST
  22. static inline void
  23. ctf_qsort_r (void *base, size_t nmemb, size_t size,
  24. int (*compar)(const void *, const void *, void *),
  25. void *arg)
  26. {
  27. qsort_r (base, nmemb, size, compar, arg);
  28. }
  29. #elif HAVE_QSORT_R_COMPAR_LAST
  30. struct ctf_qsort_arg
  31. {
  32. int (*compar) (const void *, const void *, void *);
  33. void *arg;
  34. };
  35. static int
  36. ctf_qsort_compar_thunk (void *arg, const void *a, const void *b)
  37. {
  38. struct ctf_qsort_arg *qsort_arg = (struct ctf_qsort_arg *) arg;
  39. return qsort_arg->compar (a, b, qsort_arg->arg);
  40. }
  41. static inline void
  42. ctf_qsort_r (void *base, size_t nmemb, size_t size,
  43. int (*compar)(const void *, const void *, void *),
  44. void *arg)
  45. {
  46. struct ctf_qsort_arg thunk = { compar, arg };
  47. qsort_r (base, nmemb, size, &thunk, ctf_qsort_compar_thunk);
  48. }
  49. #else
  50. void ctf_qsort_r (void *base, size_t nmemb, size_t size,
  51. int (*compar)(const void *, const void *, void *),
  52. void *arg);
  53. #endif
  54. #ifndef HAVE_O_CLOEXEC
  55. # define O_CLOEXEC 0
  56. #endif
  57. #undef MAX
  58. #undef MIN
  59. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  60. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  61. #if !HAVE_DECL_STPCPY
  62. extern char *stpcpy (char *, const char *);
  63. #endif
  64. #endif /* _CTF_DECLS_H */