17d62b00eSchristos /* Declarations for missing functions. 2*6881a400Schristos Copyright (C) 2019-2022 Free Software Foundation, Inc. 37d62b00eSchristos 47d62b00eSchristos This file is part of libctf. 57d62b00eSchristos 67d62b00eSchristos libctf is free software; you can redistribute it and/or modify it under 77d62b00eSchristos the terms of the GNU General Public License as published by the Free 87d62b00eSchristos Software Foundation; either version 3, or (at your option) any later 97d62b00eSchristos version. 107d62b00eSchristos 117d62b00eSchristos This program is distributed in the hope that it will be useful, but 127d62b00eSchristos WITHOUT ANY WARRANTY; without even the implied warranty of 137d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 147d62b00eSchristos See the GNU General Public License for more details. 157d62b00eSchristos 167d62b00eSchristos You should have received a copy of the GNU General Public License 177d62b00eSchristos along with this program; see the file COPYING. If not see 187d62b00eSchristos <http://www.gnu.org/licenses/>. */ 197d62b00eSchristos 207d62b00eSchristos #ifndef _CTF_DECLS_H 217d62b00eSchristos #define _CTF_DECLS_H 227d62b00eSchristos 237d62b00eSchristos #include "config.h" 247d62b00eSchristos 257d62b00eSchristos #include <stddef.h> 267d62b00eSchristos #include <stdlib.h> 277d62b00eSchristos #include "libiberty.h" 287d62b00eSchristos 297d62b00eSchristos #if HAVE_QSORT_R_ARG_LAST 307d62b00eSchristos static inline void 317d62b00eSchristos ctf_qsort_r (void *base, size_t nmemb, size_t size, 327d62b00eSchristos int (*compar)(const void *, const void *, void *), 337d62b00eSchristos void *arg) 347d62b00eSchristos { 357d62b00eSchristos qsort_r (base, nmemb, size, compar, arg); 367d62b00eSchristos } 377d62b00eSchristos #elif HAVE_QSORT_R_COMPAR_LAST 387d62b00eSchristos struct ctf_qsort_arg 397d62b00eSchristos { 407d62b00eSchristos int (*compar) (const void *, const void *, void *); 417d62b00eSchristos void *arg; 427d62b00eSchristos }; 437d62b00eSchristos 447d62b00eSchristos static int 457d62b00eSchristos ctf_qsort_compar_thunk (void *arg, const void *a, const void *b) 467d62b00eSchristos { 477d62b00eSchristos struct ctf_qsort_arg *qsort_arg = (struct ctf_qsort_arg *) arg; 487d62b00eSchristos 497d62b00eSchristos return qsort_arg->compar (a, b, qsort_arg->arg); 507d62b00eSchristos } 517d62b00eSchristos 527d62b00eSchristos static inline void 537d62b00eSchristos ctf_qsort_r (void *base, size_t nmemb, size_t size, 547d62b00eSchristos int (*compar)(const void *, const void *, void *), 557d62b00eSchristos void *arg) 567d62b00eSchristos { 577d62b00eSchristos struct ctf_qsort_arg thunk = { compar, arg }; 587d62b00eSchristos qsort_r (base, nmemb, size, &thunk, ctf_qsort_compar_thunk); 597d62b00eSchristos } 607d62b00eSchristos #else 617d62b00eSchristos void ctf_qsort_r (void *base, size_t nmemb, size_t size, 627d62b00eSchristos int (*compar)(const void *, const void *, void *), 637d62b00eSchristos void *arg); 647d62b00eSchristos #endif 657d62b00eSchristos 667d62b00eSchristos #ifndef HAVE_O_CLOEXEC 677d62b00eSchristos # define O_CLOEXEC 0 687d62b00eSchristos #endif 697d62b00eSchristos 707d62b00eSchristos #undef MAX 717d62b00eSchristos #undef MIN 727d62b00eSchristos #define MAX(a, b) ((a) > (b) ? (a) : (b)) 737d62b00eSchristos #define MIN(a, b) ((a) < (b) ? (a) : (b)) 747d62b00eSchristos 757d62b00eSchristos #if !HAVE_DECL_STPCPY 767d62b00eSchristos extern char *stpcpy (char *, const char *); 777d62b00eSchristos #endif 787d62b00eSchristos 797d62b00eSchristos #endif /* _CTF_DECLS_H */ 80